实验环境
主机名 | IP | 操作系统 | 所需配置 |
---|---|---|---|
A | 192.168.24.131 | centos7 | 2个Tomcat |
B | 192.168.24.146 | centos7 | mysql,nginx |
实验需求
主机B作为nginx服务器,主机A作为2个Tomcat服务器,客户端发来的请求首先经由nginx处理,由nignx反代至后端的Tomcat服务器实现负载均衡
实验部署如下
在主机A操作如下
部署2个Tomcat服务器
实验准备
关闭防火墙以及SELINX
[root@linfan ~]# systemctl stop firewalld
[root@linfan ~]# systemctl disable firewalld
[root@linfan ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@linfan ~]# setenforce 0
setenforce: SELinux is disabled
安装yum源
[root@linfan ~]# cd /etc/yum.repos.d/
[root@linfan yum.repos.d]# curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1572 100 1572 0 0 9484 0 --:--:-- --:--:-- --:--:-- 9527
[root@linfan yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/163.repo
[root@linfan yum.repos.d]# sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/163.repo
[root@linfan yum.repos.d]# yum clean all
yum.repos.d]# yum -y install epel-release
Loaded plugins: fastestmirror
Cleaning repos: base centosplus extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
java环境安装
安装jdk环境
[root@linfan ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
查看安装版本
[root@linfan ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
tomcat部署
下载tomcat
[root@linfan ~]cd /usr/src
[root@linfan src]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
[root@linfan src]# ls
apache-tomcat-9.0.8.tar.gz debug kernels
解压部署
因为要部署2个tomcal,所以这里要实现2次解压
//第一次解压
root@linfan src]# tar xf apache-tomcat-9.0.8.tar.gz -C /usr/local/
[root@linfan src]# cd /usr/local/
[root@linfan local]# mv apache-tomcat-9.0.8/ doudou //解压后重命名为doudou,防止第二次解压在同一目录下同名
[root@linfan local]# ls doudou
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
//第二次解压
[root@linfan local]# cd /usr/src
[root@linfan src]# ls
apache-tomcat-9.0.8.tar.gz debug kernels
[root@linfan src]# tar xf apache-tomcat-9.0.8.tar.gz -C /usr/local/
[root@linfan src]# cd /usr/local/
[root@linfan local]# ls
apache-tomcat-9.0.8 bin doudou etc games include lib lib64 libexec nginx sbin share src
[root@linfan local]# ln -s doudou/ tomcat1 //软连接为tomcat1
[root@linfan local]# ln -s apache-tomcat-9.0.8/ tomcat2 //软连接为tomcat2
[root@linfan local]# ll
total 0
drwxr-xr-x 9 root root 160 Sep 5 01:36 apache-tomcat-9.0.8
drwxr-xr-x. 2 root root 6 Nov 5 2016 bin
drwxr-xr-x 9 root root 160 Sep 5 01:34 doudou
drwxr-xr-x. 2 root root 6 Nov 5 2016 etc
drwxr-xr-x. 2 root root 6 Nov 5 2016 games
drwxr-xr-x. 2 root root 6 Nov 5 2016 include
drwxr-xr-x. 2 root root 6 Nov 5 2016 lib
drwxr-xr-x. 2 root root 6 Nov 5 2016 lib64
drwxr-xr-x. 2 root root 6 Nov 5 2016 libexec
drwxr-xr-x. 11 root root 151 Sep 3 03:16 nginx
drwxr-xr-x. 2 root root 6 Nov 5 2016 sbin
drwxr-xr-x. 5 root root 49 Aug 30 04:37 share
drwxr-xr-x. 2 root root 6 Nov 5 2016 src
lrwxrwxrwx 1 root root 7 Sep 5 01:37 tomcat1 -> doudou/
lrwxrwxrwx 1 root root 20 Sep 5 01:37 tomcat2 -> apache-tomcat-9.0.8/
为了避免端口冲突,修改tomcat配置文件的端口号(修改其中一个即可)在这里我修改tomcat1的配置文件
tomcat1的端口改为8081
[root@linfan ~]# vim /usr/local/tomcat1/conf/server.xml
...
...
-->
//修改为8006
...
...
-->
//修改为8444