主机名称 | IP | 角色 |
---|---|---|
nginx | 192.168.110.10 | 反向代理、负载均衡服务器 |
tomcat1 | 192.168.110.11 | tomcat集群服务器 |
tomcat2 | 192.168.110.12 | tomcat集群服务器 |
//创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
//安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
安装过程略....
[root@localhost ~]# yum -y groups mark install 'Development Tools'
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools
//创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
--2018-08-20 11:19:09-- http://nginx.org/download/nginx-1.12.0.tar.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63, 2606:7100:1:69::3f, ...
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 980831 (958K) [application/octet-stream]
Saving to: ‘nginx-1.12.0.tar.gz’
100%[======================================================>] 980,831 15.9KB/s in 43s
2018-08-20 11:19:52 (22.3 KB/s) - ‘nginx-1.12.0.tar.gz’ saved [980831/980831]
//编译安装
[root@localhost src]# ls
debug kernels nginx-1.12.0.tar.gz
[root@localhost src]# tar xf nginx-1.12.0.tar.gz
[root@localhost src]# cd nginx-1.12.0
[root@localhost nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.12.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
安装过程略....
//配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
//启动nginx
[root@localhost ~]# nginx
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
tomcat1的配置:
//关闭防火墙和selinux
[root@tomcat1 ~]# systemctl stop firewalld
[root@tomcat1 ~]# systemctl disable firewalld
[root@tomcat1 ~]# setenforce 0
//安装jdk环境
[root@tomcat1 ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
//查看安装的版本
[root@tomcat2 ~]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
//下载tomcat
[root@tomcat1 ~]# cd /usr/src/
[root@tomcat1 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.38/bin/apache-tomcat-9.0.38.tar.gz
//解压部署
[root@tomcat1 src]# ls
apache-tomcat-9.0.38.tar.gz debug kernels
[root@tomcat1 src]# tar xf apache-tomcat-9.0.38.tar.gz -C /usr/local/
[root@tomcat1 src]# cd /usr/local/
[root@tomcat1 local]# ln -s apache-tomcat-9.0.38/ tomcat
[root@tomcat1 local]# ll
总用量 0
drwxr-xr-x. 9 root root 220 8月 30 09:45 apache-tomcat-9.0.38
drwxr-xr-x. 2 root root 6 3月 10 2016 bin
drwxr-xr-x. 2 root root 6 3月 10 2016 etc
drwxr-xr-x. 2 root root 6 3月 10 2016 games
drwxr-xr-x. 2 root root 6 3月 10 2016 include
drwxr-xr-x. 2 root root 6 3月 10 2016 lib
drwxr-xr-x. 2 root root 6 3月 10 2016 lib64
drwxr-xr-x. 2 root root 6 3月 10 2016 libexec
drwxr-xr-x. 2 root root 6 3月 10 2016 sbin
drwxr-xr-x. 5 root root 49 3月 25 02:56 share
drwxr-xr-x. 2 root root 6 3月 10 2016 src
lrwxrwxrwx. 1 root root 21 8月 30 09:45 tomcat -> apache-tomcat-9.0.38/
//写一个hello world的java页面
[root@tomcat1 ~]# vim index.html
[root@tomcat1 ~]# cat index.jsp
index.jsp
[root@tomcat1 test]# cat index.jsp
test page
<%
out.println("I am tomcat!");
%>
[root@tomcat1 ~]# mkdir /usr/local/tomcat/webapps/test
[root@tomcat1 ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@tomcat1 ~]# ll /usr/local/tomcat/webapps/test/
总用量 4
-rw-r--r--. 1 root root 137 8月 30 09:50 index.jsp
//启动tomcat
[root@tomcat1 ~]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat1 ~]# ps -ef | grep tomcat
root 25206 1 0 09:24 pts/2 00:00:08 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 25269 9735 0 10:00 pts/2 00:00:00 grep --color=auto tomcat
[root@tomcat1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 1 ::ffff:127.0.0.1:8015 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
tomcat2的配置:
//关闭防火墙和selinux
[root@tomcat2 ~]# systemctl stop firewalld
[root@tomcat2 ~]# systemctl disable firewalld
[root@tomcat2 ~]# setenforce 0
//安装jdk环境
[root@tomcat2 ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
//查看安装的版本
[root@tomcat2 ~]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
//下载tomcat
[root@tomcat2 ~]# cd /usr/src/
[root@tomcat2 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.38/bin/apache-tomcat-9.0.38.tar.gz
//解压部署
[root@tomcat2 src]# ls
apache-tomcat-9.0.38.tar.gz debug kernels
[root@tomcat2 src]# tar xf apache-tomcat-9.0.38.tar.gz -C /usr/local/
[root@tomcat2 src]# cd /usr/local/
[root@tomcat2 local]# ln -s apache-tomcat-9.0.38/ tomcat
[root@tomcat2 local]# ll
总用量 0
drwxr-xr-x. 9 root root 220 8月 30 09:45 apache-tomcat-9.0.38
drwxr-xr-x. 2 root root 6 3月 10 2016 bin
drwxr-xr-x. 2 root root 6 3月 10 2016 etc
drwxr-xr-x. 2 root root 6 3月 10 2016 games
drwxr-xr-x. 2 root root 6 3月 10 2016 include
drwxr-xr-x. 2 root root 6 3月 10 2016 lib
drwxr-xr-x. 2 root root 6 3月 10 2016 lib64
drwxr-xr-x. 2 root root 6 3月 10 2016 libexec
drwxr-xr-x. 2 root root 6 3月 10 2016 sbin
drwxr-xr-x. 5 root root 49 3月 25 02:56 share
drwxr-xr-x. 2 root root 6 3月 10 2016 src
lrwxrwxrwx. 1 root root 21 8月 30 09:45 tomcat -> apache-tomcat-9.0.38/
//写一个hello world的java页面
[root@tomcat2 ~]# vim index.html
[root@tomcat2 ~]# cat index.jsp
test page
<%
out.println("Hello World");
%>
[root@tomcat2 ~]# mkdir /usr/local/tomcat/webapps/test
[root@tomcat2 ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@tomcat2 ~]# ll /usr/local/tomcat/webapps/test/
总用量 4
-rw-r--r--. 1 root root 137 8月 30 09:50 index.jsp
//启动tomcat
[root@tomcat2 ~]# /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat2 ~]# ps -ef | grep tomcat
root 8433 1 0 16:34 pts/0 00:00:27 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 24240 24160 0 19:04 pts/1 00:00:00 grep --color=auto tomcat
[root@tomcat2 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
[root@tomcat1 ~]# vim /usr/local/tomcat/conf/server.xml
//修改下面两条port
//在/usr/local/nginx/conf/nginx.conf文件中添加如下
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
#gzip on;
upstream tomcat-web {
server 192.168.110.11:8081 weight=1;
server 192.168.110.12:8080 weight=1;
}
server {
listen 80;
server_name 192.168.110.10;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcat-web;
root html;
index index.html index.htm index.jsp;
}
//重启nginx服务
[root@nginx ~]# nginx -s stop
[root@nginx ~]# nginx
[root@nginx ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*