虚拟机1 : nginx
1 systemctl stop firewalld
2 setenforce 0
3 yum -y install lrzsz
4 rz
5 ls
6 tar -zxvf nginx-1.10.1.tar.gz -C /usr/src/
7 cd /usr/src/nginx-1.10.1/
8 yum -y install gcc gcc-c++ pcre-devel zlib-devel
9 ./configure --prefix=/usr/local/nginx
10 make && make install
11 /usr/local/nginx/sbin/nginx
测试 ip:80
虚拟机2: tomcat 1
1 systemctl stopfirewalld
2 systemctl stop firewalld
3 setenforce 0
4 yum -y install java
5 yum -y install lrzsz
6 rz
7 tar -zxvf apache-tomcat-7.0.68.tar.gz
8 cp -r apache-tomcat-7.0.68 /opt/tomcat
9 cd /opt/tomcat/bin/
10 ./startup.sh
11 cd /opt/tomcat/webapps/ROOT/
12 ls
14 mv index.jsp index.pl
15 vim index.jsp 编写测试页面
测试 ip:8080
虚拟机3 : tomcat2 1 systemctl stopfirewalld
2 systemctl stop firewalld
3 setenforce 0
4 yum -y install java
5 java -version
6 yum -y install lrzsz
7 rz
8 tar -zxvf apache-tomcat-7.0.68.tar.gz
9 cp -r apache-tomcat-7.0.68 /opt/tomcat
10 cd /opt/tomcat/bin/
11 ./startup.sh
12 cd /opt/tomcat/webapps/ROOT/
14 mv index.jsp index.pl
15 vim index.jsp 编写测试页面
测试 ip:8080
负载均衡配置 虚拟机1:nginx
15 vim /usr/local/nginx/conf/nginx.conf
location / { 覆盖原有的 添加
proxy_pass http://daxian; 下对应
}
upstream daxian { 上对应
server 192.168.238.129:8080; 分别对应已建好的tomcat1 加端口号
server 192.168.238.130:8080; tomcat2 加端口号
}
} 备注:容易报错,如果在最后添加一定要加一个括号
19 pkill nginx
20 /usr/local/nginx/sbin/nginx 重启nginx
测试 ip 不断刷新,就实现了 负载均衡了
-------------------------------------------------------------------------------------------------