Close security
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
This experiment will need to install a two Tomcat Nginx
A: Tomcat installation configuration
Java -version # to view details of their own version of the JDK
Uninstall JDK
method one
[root@localhost ~]# which java
/usr/bin/java
[Root @ localhost ~] # rm -rf / usr / bin / java # delete the corresponding directory
Method Two
[Root @ localhost ~] # rpm -qa | grep -i openjdk # view the version information they install the JDK
java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
# Uninstalling the JDK software
[root@localhost ~]# rpm -e java-1.7.0-openjdk
[root@localhost ~]# rpm -e java-1.7.0-openjdk-headless
[root@localhost ~]# rpm -e java-1.8.0-openjdk --nodeps
[root@localhost ~]# rpm -e java-1.8.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep -i openjdk
Install the JDK
Own JDK download to your virtual machine
[Root @ localhost ~] #tar xf JDK # unpacking
[Root @ localhost ~] #mv JDK / usr / local / java # into the extracted directory / usr / local / java named the
[Root @ localhost ~] #vim / etc / profile # define your own environment variables
export JAVA_HOME = / usr / local / java # Set with java directory
export PATH = $ PATH: $ JAVA_HOME / bin # add the bin subdirectory with java directory in the PATH environment variable
[Root @ localhost ~] #source / etc / profile # source with the implementation of the entry into force
[Root @ localhost ~] Details of JDK version #java -version # View installed
Unzip Tomcat package
[Root @ localhost ~] #tar xf tomcat # unpack your Tomcat package
[Root @ localhost ~] #mv tomcat / usr / local / tomcat # unpacked into the directory / usr / local / set tomcat
[Root @ localhost ~] # / usr / local / tomcat / bin / startup.sh # open Tomcat service
[root@localhost ~]#/usr/local/tomcat/bin/shutdown.sh #关闭Tomcat服务
[root@localhost ~]# netstat -lnpt | grep :8080 #Tomcat默认运行在8080端口查看是否打开
二:安装配置Nginx
[root@localhost ~]#yum -y install pcre-devel zlib-devel make gcc gcc-c++ openssl-devel #安装Nginx依赖包
[root@localhost ~]#useradd -M -s /sbin/nologin nginx #创建一个Nginx测试用户
[root@localhost ~]#tar xf nginx -C /usr/src #将Nginx解包到/usr/src下
[root@localhost ~]#cd /usr/src/nginx
[root@localhost ~]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-pcre && make && make install #对Nginx进行编译安装
--prefix 设定Nginx的安装目录
--user和--group 指定Nginx运行用户和组
--with-http_stub_status_module 启用http_stub_status_module模块以支持状态统计
--with-http_ssl_module 启用SSL模块
--with-http_flv_module 启用FLV模块,提供寻求内存使用基于时间的偏移量文件
[root@localhost ~]#ln -s /usr/local/nginx/sbin/nginx /usr/local/bin #给Nginx一个软连接
[root@localhost ~]#nginx -t #检查语法
[root@localhost ~]# nginx #开启Nginx服务
[root@localhost ~]#netstat -lnpt | grep 80 #查看端口
三:Nginx负载均衡
修改nginx的nginx.conf文件
在http底下写入一个地址池里面写入你的IP地址:端口:权重
upstream tomcat_server { #你的地址池
server 192.168.200.12:8080 weight=1;
server 192.168.200.13:8080 weight=1;
}
在server里面实现你访问jsp的负载均衡
location ~ \.jsp$ {
proxy_pass http://tomcat_server; #你的地址池名称
}