CentOS7安装javaJdk1.8、部署多台tomcat

一:安装JDK

1. 去oracle官网下载liunx版jdk1.8


2.进入java目录
[root@iZwz91nfqrmmcjz3ax4vqvZ ~]# cd /usr/java
上传文件,解压文件 创建软链接 
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# tar -zxvf jdk-8u111-linux-x64.tar.gz
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# ls -n /usr/java/jdk1.8.0_111 /usr/java/latestjdk

3. 配置环境 打开etc/profile文件
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# vi /etc/profile
安i进入编辑
JAVA_HOME=/usr/java/jdk/latestjdk
JAVA_BIN=$JAVA_HOME/bin
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/dt.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH
 按 Esc 键、输入 :wq 回车,保持并退出。

启用新的配置
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# source /etc/profile

查看JDK版本
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# java -version
 java version "1.8.0_91"
 Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
 Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)


二:安装多台tomcat

本次这里配置3台Tomcat,请求通过nginx处理进入
2.1   上传tomcat包,解压 ,本次是tomcat7
[root@iZwz91nfqrmmcjz3ax4vqvZ ~]# cd /usr/java
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# tar -zxvf apache-tomcat-7.0.73.tar.gz
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# mv /usr/java/apache-tomcat-7.0.73   /usr/java/tomcat-job-server
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# tar -zxvf apache-tomcat-7.0.73.tar.gz
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# mv /usr/java/apache-tomcat-7.0.73   /usr/java/tomcat-job-c
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# tar -zxvf apache-tomcat-7.0.73.tar.gz
 mv /usr/java/apache-tomcat-7.0.73   /usr/java/tomcat-job-b
2.2 修改3个tomcat的配置文件
8080那个tomcat配置文件不用修改
[root@iZwz91nfqrmmcjz3ax4vqvZ java]# cd tomcat-job-c/conf/
[root@iZwz91nfqrmmcjz3ax4vqvZ conf]# vi server.xml

 端口:8005->9005

8081

maxThreads="150"minSpareThreads="25"maxSpareThreads="75"

enableLookups="false"redirectPort="8443"acceptCount="100"

connectionTimeout="20000"disableUploadTimeout="true"/>

9009

enableLookups="false"redirectPort="8443"protocol="AJP/1.3"/>

[root@iZwz91nfqrmmcjz3ax4vqvZ conf]# cd /usr/java/tomcat-job-b/conf/
[root@iZwz91nfqrmmcjz3ax4vqvZ conf]# vi server.xml

 端口:8005->9006

8082

maxThreads="150"minSpareThreads="25"maxSpareThreads="75"

enableLookups="false"redirectPort="8443"acceptCount="100"

connectionTimeout="20000"disableUploadTimeout="true"/>

9010

enableLookups="false"redirectPort="8443"protocol="AJP/1.3"/>

关闭防火墙
[root@iZwz91nfqrmmcjz3ax4vqvZ ~]# chkconfig  iptables off

 
   
 
   
 
   
 
   
 
   
 
  
 
   
 
  
2.3 启动每个tomcat
[root@iZwz91nfqrmmcjz3ax4vqvZ ~]# cd /usr/java/tomcat-job-server/bin
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# ./startup.sh 
Using CATALINA_BASE:   /usr/java/tomcat-job-server
Using CATALINA_HOME:   /usr/java/tomcat-job-server
Using CATALINA_TMPDIR: /usr/java/tomcat-job-server/temp
Using JRE_HOME:        /usr/java/latestjdk
Using CLASSPATH:       /usr/java/tomcat-job-server/bin/bootstrap.jar:/usr/java/tomcat-job-server/bin/tomcat-juli.jar
Tomcat started.
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# cd /usr/java/tomcat-job-c/bin
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# ./startup.sh 
Using CATALINA_BASE:   /usr/java/tomcat-job-c
Using CATALINA_HOME:   /usr/java/tomcat-job-c
Using CATALINA_TMPDIR: /usr/java/tomcat-job-c/temp
Using JRE_HOME:        /usr/java/latestjdk
Using CLASSPATH:       /usr/java/tomcat-job-c/bin/bootstrap.jar:/usr/java/tomcat-job-c/bin/tomcat-juli.jar
Tomcat started.
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# cd /usr/java/tomcat-job-c/bin
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# ./startup.sh 
Using CATALINA_BASE:   /usr/java/tomcat-job-c
Using CATALINA_HOME:   /usr/java/tomcat-job-c
Using CATALINA_TMPDIR: /usr/java/tomcat-job-c/temp
Using JRE_HOME:        /usr/java/latestjdk
Using CLASSPATH:       /usr/java/tomcat-job-c/bin/bootstrap.jar:/usr/java/tomcat-job-c/bin/tomcat-juli.jar
Tomcat started.
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# 

访问http://xxx.xxx.xxx.xxx:端口号   出现下面界面就成功了

http://120.77.213.193:8081/





3.通过nginx方向代理
	[root@iZwz91nfqrmmcjz3ax4vqvZ bin]# cd /usr/java/nginx/conf/
	[root@iZwz91nfqrmmcjz3ax4vqvZ conf]# vi nginx.conf

http{
加入:
    server_tokens	 off;

	proxy_connect_timeout 10;
	proxy_read_timeout 180;
	proxy_send_timeout 5;
	proxy_buffer_size 16k;
	proxy_buffers 4 64k;
	proxy_busy_buffers_size 128k;
	proxy_temp_file_write_size 128k;
	
	client_header_buffer_size 256k;
	large_client_header_buffers 4 256k;
	
	#启动GZIP压缩CSS和JS
    gzip on;
    # 压缩级别 1-9,默认是1,级别越高压缩率越大,当然压缩时间也就越长
    gzip_comp_level 5;
    gzip_min_length  1100;
	# 压缩类型
    gzip_types text/plain application/x-javascript application/json text/javascript text/css;
	
	upstream job_server_http {
		server 127.0.0.1:8080;
	}
	
	upstream job_c_http {
		server 127.0.0.1:8081;
	}
	
	upstream job_b_http {
		server 127.0.0.1:8082;
	}



server:{
//加入:
location ^~ /joinf-job-c  {
            proxy_redirect         off;
            proxy_set_header       Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass      http://job_c_http;
            root   html;
            index  index.html index.htm;
        }

location ^~ /joinf-job-b  {
            proxy_redirect         off;
            proxy_set_header       Host $host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass      http://job_b_http;
            root   html;
            index  index.html index.htm;
        }
}
}

重启nginx
[root@iZwz91nfqrmmcjz3ax4vqvZ bin]#  /usr/java/nginx/sbin/nginx -s reload 


测试
原来:http://120.77.213.193:8081/joinf-job-c
现在:http://120.77.213.193/joinf-job-c       效果一样





你可能感兴趣的:(CentOS7安装javaJdk1.8、部署多台tomcat)