Nginx+tomcat负载均衡群集
准备工作:源码安装的nginx服务器一个,tomcat服务器两个、mysql数据库一个,分别在不同虚拟机上或不同计算机上,服务器都是静态IP地址且可以互通,并都关闭防火墙和selinux
一、Nginx配置
1.主配置文件配置:vim nginx.conf
Upstream字段中配置tomcat所在服务器IP地址,后缀要加上“:8080”,weight代表权重,默认为1,决定访问流量走向
把localhost更改为自己域名
在网站根location字段中添加proxy_pass行,其中javademon是upstream后自定义的变量
其它干扰选项还原为默认配置
2.启动niginx:systemctl start nginx
添加nginx为系统服务的方法
cat >/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/loca