nginx反向代理tomcat集群

nginx反向代理tomcat集群
1、安装包准备
jdk1.8.0_151.tar.gz
apache-tomcat-8.5.35.tar.gz
jpress-v3.2.5.war
2、配置数据库

yum install mariadb mariadb-server -y
mysql -e "create database jpress character set utf8 collate utf8_bin;"
mysql -e "grant all privileges on jpress.* to jpress@"192.168.2.%" identified by 'jpress';"


3、安装JDK,tomcat

tar xzf jdk1.8.0_151.tar.gz -C /usr/local/
ln -vs /usr/local/jdk1.8.0_151 /usr/local/jdk1.8

tee /etc/profile.d/jdk8.sh < 
EOF

cd /usr/local/tomcat1/bin;./startup.sh

4、安装jpress

mkdir -p /var/www/html/jpress
cp /root/jpress-v3.2.5.war /var/www/html/jpress
cd /var/www/html/jpress
jar xvf jpress-v3.2.5.war

http://192.168.2.117:8080/jpress 界面上根据向导安装jpress
5、配置tomcat多实例

cd /usr/local
cp -ra tomcat1 tomcat2


修改 tomcat2/conf/server.xml里面的8005/8080/8009端口不能和tomcat1的一样
启动第二个实例tomcat
 

cd /usr/local/tomcat2/bin;./startup.sh

6、修改tomcat配置获取nginx代理后的客户端真实IP,日志增加%{X-Real-IP}i

vi conf/server.xml 

        


7、安装配置nginx

vi /etc/nginx/conf.d/lb-tomcat.conf
upstream jpress.com {
        ip_hash;
        server 192.168.2.117:8080 weight=1;
        server 192.168.2.117:8081 weight=1;
}
server {
        listen 80;
        server_name 192.168.2.118;
        location / {
                proxy_pass      http://jpress.com;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

 

你可能感兴趣的:(tomcat)