一、APISIX相關介紹
1、安全網關
安全網關設置的目的是防止Internet或外網不安全因素蔓延到自己企業(yè)或組織的內部網 。
安全網關在應用層和網絡層上面都有防火墻的身影。
其范圍從協(xié)議級過濾到十分復雜的應用級過濾等。推薦了解傳智播客linux云計算+運維開發(fā)課程。
API網關:整個流量總入口,能夠進行集中管理和控制!
2、apisix介紹
APISIX 是一個云原生、高性能、可擴展的微服務 API 網關。
它是基于 OpenResty 和 etcd來實現(xiàn),和傳統(tǒng) API 網關相比,APISIX 具備動態(tài)路由和插件熱加載,特別適合微服務體系下的 API 管理。
APISIX 是基于云原生的微服務 API 網關,它是所有業(yè)務流量的入口,可以處理傳統(tǒng)的南北向流量(server-client),也可以處理服務間的東西向流量(server-server),也可以當做 k8s ingress controller 來使用。
Tip:流量流向方向
在圖表中,通常核心網絡組件繪制在頂部(NORTH),客戶端繪制在底部(SOUTH),而數(shù)據(jù)中心內的不同服務器水平(EAST-WEST)繪制。
APISIX 通過插件機制,提供動態(tài)負載平衡、身份驗證、限流限速等功能,并且支持你自己開發(fā)的插件。
二、安裝部署
1、安裝apisix服務
①提前解決依賴問題
# 安裝epel源, luarocks 需要使用到.
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
# 添加OpenResty 的鏡像源
yum install yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
# 安裝 OpenResty, etcd 和一些依賴工具
yum install -y etcd openresty curl git gcc luarocks lua-devel
# 啟動 etcd 服務端
systemctl start etcd
# 防火墻關閉
systemctl stop firewalld.service
systemctl disable firewalld.service
# 關閉selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
②安裝apisix
yum install -y https://github.com/apache/incubator-apisix/releases/download/1.1/apisix-1.1-0.el7.noarch.rpm
③啟動apisix
apisix start
④查看服務是否啟動
查看進程或者監(jiān)聽端口9080
ps aux|grep apisix
netstat -lntp|grep 9080
2、安裝控制臺Dashbord頁面
此控制臺頁面基于VUE開發(fā),需要通過yarn編譯生成。
需要基礎編譯環(huán)境:node npm yarn
①安裝node和npm
wget https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
#解壓部署
tar xvf node-v12.16.1-linux-x64.tar.xz
mv node-v12.16.1-linux-x64 /usr/local/node
#配置環(huán)境變量
echo 'PATH=/usr/local/node/bin/:$PATH' >> /etc/profile
source /etc/profile
#測試環(huán)境
node --version
npm --version
②安裝yarn
wget https://github.com/yarnpkg/yarn/releases/download/v1.22.4/yarn-v1.22.4.tar.gz
#解壓部署
tar xvf yarn-v1.22.4.tar.gz
mv yarn-v1.22.4 /usr/local/yarn
#配置環(huán)境變量
echo 'PATH=/usr/local/yarn/bin/:$PATH' >> /etc/profile
source /etc/profile
#測試環(huán)境
yarn --version
③編譯dashboard組件,生成靜態(tài)頁面
# git獲取源碼
git clone https://github.com/apache/incubator-apisix-dashboard.git
cd incubator-apisix-dashboard
#切換分支版本 和apisix版本一致即可
git checkout 1.0
#下載解決依賴包
yarn
#構建生成頁面
yarn build:prod
#復制到訪問路徑
mkdir -p /usr/local/apisix/dashboard
cp -r ./* /usr/local/apisix/dashboard
④通過瀏覽器進行訪問
http://ip:9080/apisix/dashboard/
三、案例測試使用
1、反向代理測試
①啟動一個正常的web服務器
也可以使用已經安裝的openresty
#啟動web服務器 默認80端口
/usr/local/openresty/bin/opennresty
#檢測服務是否開啟 80端口
netstat -lntp |grep 80
②配置指向后端服務
到這里還暫時不能使用。需要配置具體路由信息進行轉發(fā)測試



到這里還暫時不能使用。需要配置具體路由信息進行轉發(fā)測試。
③配置路由規(guī)則信息


④測試查看

通過上圖,可以查看到已經轉發(fā)成功。也就是說明反向代理設置成功。
2、負載均衡測試
這里簡單測試一下負載均衡輪詢的效果。故然另外安裝一個httpd監(jiān)聽不同端口進行測試。
①安裝一個httpd
yum install httpd
②修改httpd默認端口,添加測試頁面
默認httpd監(jiān)聽端口80,上面案例中已經啟動openresty在80端口,故這里將httpd修改為8080。
vim +42 /etc/httpd/conf/httpd.conf

添加測試頁面
echo this is httpd page >> /var/www/html/index.html
③啟動并查看httpd服務
systemctl start httpd
systemctl status httpd
④在upstream中添加后端節(jié)點


⑤測試查看負載均衡轉發(fā)效果

以上案例可以看到路由已經轉發(fā),并且負載均衡到這里實現(xiàn)的兩個節(jié)點。
猜你喜歡:
Linux運維的發(fā)展歷史和和行業(yè)前景介紹