Nginx(负载均衡的配置)
1.上传nginx安装包
链接: https://pan.baidu.com/s/1p-bXES6vOhn--H-93ltUVA 提取码: 1s6m 复制这段内容后打开百度网盘手机App,操作更方便哦
2.解压nginx
tar -zxvf nginx-1.12.2.tar.gz -C /usr/local/src/
3.进入到nginx的源码目录
cd /usr/local/src/nginx-1.12.2/
4.预编译
./configure
5.安静gcc编译器
yum -y install gcc pcre-devel openssl openssl-devel
6.然后再执行
./configure
7.编译安装nginx
make && make install
8.启动nginx(进入到usr/local/nginx/目录)
sbin/nginx
9.查看nginx进程
ps -ef | grep nginx
netstat -anpt | grep nginx
--------------------------------------------------------------------------
将springboot程序部署在多台服务器上,然后启动springboot
java -jar niubike-0.0.1-SNAPSHOT.war >> ./logs 2>&1 &
--------------------------------------------------------------------------
修改nginx的配置文件,让nginx实现负载均衡功能
vi /usr/local/nginx/conf/nginx.conf
在HTTP后面添加
#响应数据的来源
upstream tomcats {
server node-1.xiaoniu.com:8888 weight=1;
server node-2.xiaoniu.com:8888 weight=1;
server node-3.xiaoniu.com:8888 weight=1;
}
在Server后面添加
location ~ .* {
proxy_pass http://tomcats;
}
nginx.conf文件