上述配置完成之后进行对tomcat配置不同端口
tomcat设置端口
# 移动tomcat设置两个主目录
[root@lyx local]# mv apache-tomcat-8.5.79 tomcat-home
[root@lyx local]# cp -R tomcat-home tomcat-8080
[root@lyx local]# cp -R tomcat-home tomcat-8090
进行修改对应端口8080默认不变修改8090:
[root@lyx local]# vi /usr/local/tomcat-8090/conf/server.xml
...
<Server port="8015" shutdown="SHUTDOWN">
...
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
...
进入到tomcat-8080目录下创建一个启动的shell脚本和一个停止的shell脚本:
[root@lyx tomcat-8080]# cat start.sh
#!/bin/sh
CUR_DIR=`dirname $BASH_SOURCE`
export CATALINA_BASE=`readlink -f $CUR_DIR`
export CATALINA_HOME="/usr/local/tomcat-home"
if [ -f $CATALINA_HOME/bin/startup.sh ]; then
$CATALINA_HOME/bin/startup.sh
else
echo "$CATALINA_HOME/bin/startup.sh not exist"
fi
[root@lyx tomcat-8080]#
# 然后添加权限
[root@lyx tomcat-8080]# chmod +x start.sh
[root@lyx tomcat-8080]# cat stop.sh
#!/bin/sh
CUR_DIR=`dirname $BASH_SOURCE`
export CATALINA_BASE=`readlink -f $CUR_DIR`
export CATALINA_HOME="/usr/local/tomcat-home"
if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then
$CATALINA_HOME/bin/shutdown.sh
else
echo "$CATALINA_HOME/bin/shutdown.sh not exist"
fi
[root@lyx tomcat-8080]#
# 然后添加权限
[root@lyx tomcat-8080]# chmod +x stop.sh
同样进入到tomcat-8090目录下创建一个启动的shell脚本和一个停止的shell脚本:
[root@lyx tomcat-8090]# cat start.sh
#!/bin/sh
CUR_DIR=`dirname $BASH_SOURCE`
export CATALINA_BASE=`readlink -f $CUR_DIR`
export CATALINA_HOME="/usr/local/tomcat-home"
if [ -f $CATALINA_HOME/bin/startup.sh ]; then
$CATALINA_HOME/bin/startup.sh
else
echo "$CATALINA_HOME/bin/startup.sh not exist"
fi
[root@lyx tomcat-8090]#
# 然后添加权限
[root@lyx tomcat-8090]# chmod +x start.sh
[root@lyx tomcat-8090]# cat stop.sh
#!/bin/sh
CUR_DIR=`dirname $BASH_SOURCE`
export CATALINA_BASE=`readlink -f $CUR_DIR`
export CATALINA_HOME="/usr/local/tomcat-home"
if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then
$CATALINA_HOME/bin/shutdown.sh
else
echo "$CATALINA_HOME/bin/shutdown.sh not exist"
fi
[root@lyx tomcat-8090]#
# 然后添加权限
[root@lyx tomcat-8090]# chmod +x stop.sh
对tomcat-8080进行启动:
[root@lyx tomcat-8080]# ./start.sh
Using CATALINA_BASE: /usr/local/tomcat-8080
Using CATALINA_HOME: /usr/local/tomcat-home
Using CATALINA_TMPDIR: /usr/local/tomcat-8080/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-home/bin/bootstrap.jar:/usr/local/tomcat-8080/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
对tomcat-8090进行启动:
[root@lyx tomcat-8090]# ./start.sh
Using CATALINA_BASE: /usr/local/tomcat-8090
Using CATALINA_HOME: /usr/local/tomcat-home
Using CATALINA_TMPDIR: /usr/local/tomcat-8090/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-home/bin/bootstrap.jar:/usr/local/tomcat-9090/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
对应访问:
修改8090端口网页内容为tomcat-8090而8080端口为hello依然为猫作为对比测试:
[root@lyx local]# cd tomcat-8090/
[root@lyx tomcat-8090]# cd webapps/ROOT/
[root@lyx ROOT]# cp -a index.jsp index1.jsp
[root@lyx ROOT]# rm -rf index.jsp
[root@lyx ROOT]# cat index.jsp
tomcat-9090
[root@lyx ROOT]#
[root@lyx ~]# cd /usr/local/tomcat-8080/
[root@lyx tomcat-8080]# cat webapps/ROOT/index.jsp
hello
[root@lyx tomcat-8080]#
进行刷新网页查看:
注意:如果操作完之后会出现显示一个端口那么就是端口进行冲突需要进行修改环境变量,正常访问则无需修改:
# 编辑
vim /etc/profile
# 添加到最后
TOMCAT_HOME=/usr/local/tomcat-8080/
CATALINA_HOME=/usr/local/tomcat-8080/
CATLINA_BASE=/usr/local/tomcat-8080
export TOMCAT_HOME CATALINA_HOME CATALINA_BASH
TOMCAT_HOME_1=/usr/local/tomcat-8090
CATALINA_HOME_1=/usr/local/tomcat-8090
CATLINA_BASE_1=/usr/local/tomcat-8090
export TOMCAT_HOME_1 CATALINA_HOME_1 CATALINA_BASH_1
# 进行加载环境变量
source /etc/profile #这个是一定要做的
# 然后进行修改tomcat的bin目录下catalina.sh
[root@lyx tomcat-8090]# vi bin/catalina.sh
# 添加
export CATALINA_HOME=$CATALINA_HOME_1
export CATALINA_HOME=$CATALINA_HOME_1
进行配置nginx:
[root@lyx nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf
# 添加:
upstream tomcatserver{
server 192.168.88.88:8080 weight=20;
server 192.168.88.88:8090 weight=10;
}
# 停止nginx
[root@lyx ~]# /usr/local/nginx/sbin/nginx -s stop
# 启动nginx
[root@lyx ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
访问查看:
再次刷新:
[root@lyx ~]# vi /usr/local/nginx/conf/nginx.conf
# 停止nginx
[root@lyx ~]# /usr/local/nginx/sbin/nginx -s stop
# 启动nginx
[root@lyx ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
进行访问:一直不变
[root@lyx ~]# vi /usr/local/nginx/conf/nginx.conf
编译环境:
# 上传并且解压1.8.1 并且sticky也在此执行
[root@lyx ~]# cd /server/tools/
[root@lyx tools]# ll
总用量 940
drwxr-xr-x 9 1001 1001 230 4月 12 09:27 nginx-1.8.1
-rw-r--r-- 1 root root 833473 4月 12 09:20 nginx-1.8.1.tar.gz
-rw-r--r-- 1 root root 124138 4月 12 09:14 nginx-sticky-module-ng
# 下载Sticky
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
# 进行解压
tar -xvf master.tar.gz
#重命名为nginx-goodies-nginx-sticky-module-ng
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 /opt/nginx-goodies-nginx-sticky-module-ng
#进入nginx目录进行安装编译
[root@localhost nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/server/tools/nginx-goodies-nginx-sticky-module-ng/
# 源码编译
make && make install ,一定要编译安装,否则不生效
# 查看模块
/usr/local/nginx/sbin/nginx -V
useradd -M -s /sbin/nologin nginx
#启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf