一、安裝nginx
1.1 下載下傳nginx,儲存路徑為:/usr/local/software
cd /usr/local/software
wget http://nginx.org/download/nginx-1.19.6.tar.gz
1.2 解壓安裝包,得到解壓目錄
tar -xzvf nginx-1.19.6.tar.gz
1.3 進入解壓目錄
cd nginx-1.19.6
1.4 執行指令指定安裝目錄
./configure --prefix=/usr/local/nginx-1.19.6
如果出現錯誤:
-
錯誤為:./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
-
錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module --with-openssl=
options.
解決辦法:
yum -y install openssl openssl-devel
1.5 接下來通過指令 make && make install 指令
1.6 進入安裝位置修改配置
cd /usr/local/nginx1.19.6
進入該目錄下的配置目錄conf
1.7 修改ng的conf檔案
# ng配置nacos叢集負載均衡 start
upstream nacosCluster {
server 146.56.192.87:8848;
server 146.56.192.87:8849;
server 146.56.192.87:8850;
}
server {
listen 8847;
server_name 146.56.192.87;
location /nacos/ {
proxy_pass http://nacosCluster/nacos/;
index index.html index.htm index.jsp;
}
}
# ng配置nacos叢集負載均衡 end
以上,nginx已安裝完成并配置好負載均衡。
1.8 啟動nginx
測試通路:
二、初始化nacos資料庫
建立一個資料庫(需要自己建立一個資料庫) 腳本的在 nacos/conf/nacos-mysql.sql
三、搭建Nacos叢集
三個Nacos端口分别為8849 ,8850,8851
3.1 修改nacos8850/conf檔案 application.properties
主要修改端口、打開mysql配置注解、配置mysql資料庫連接配接的配置資訊
3.2 修改nacos8850/conf檔案 把原來的cluster.conf.example改為cluster.conf檔案
檔案内容為如下:
3.3 按照上面方法分表修改8848 8849兩個nacos
3.4 分别啟動這三個nacos
執行啟動指令:
./bin/start.sh
啟動成功的依據 檢視日志,指令為:
tail -f logs/start.out
測試:
分别登陸位址:
- http://${IP}:8849/nacos
- http://${IP}:8850/nacos
- http://${IP}:8851/nacos
NG測試
- http://${IP}:8847/nacos/
用戶端位址: 直接填寫 nginx 的8847 端口的位址就可以了,nginx代理效果: