一、安装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代理效果: