濮阳杆衣贸易有限公司

主頁 > 知識庫 > centos7下systemd實(shí)現(xiàn)tomcat多實(shí)例配置方法

centos7下systemd實(shí)現(xiàn)tomcat多實(shí)例配置方法

熱門標(biāo)簽:常州云呼叫外呼系統(tǒng) 小藍(lán)鴿電話機(jī)器人 阿克蘇市地圖標(biāo)注app 上海營銷外呼系統(tǒng)定制 京東外呼系統(tǒng)怎么操作 bs外呼系統(tǒng) 河北機(jī)器人電銷 ai人工電話機(jī)器人 長沙人工外呼系統(tǒng)公司

本文我們分享在Centos安裝tomcat,然后用systemd實(shí)現(xiàn)tomcat多實(shí)例的方法,有需求的朋友可以認(rèn)真參考一下。
系統(tǒng)環(huán)境: CentOS 7 x86_64

1、安裝jdk

rpm -ivh jdk-8u60-linux-x64.rpm

2、創(chuàng)建普通用戶

getent group tomcat || groupadd -r tomcat
getent passwd tomcat || useradd -r -d /opt -s /bin/nologin tomcat

3、下載tomcat 7
cd /opt
wget http://mirrors.ustc.edu.cn/apache/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0.64.tar.gz
tar zxvf apache-tomcat-7.0.64.tar.gz
mv apache-tomcat-7.0.64 tomcat01
chown -R tomcat:tomcat tomcat01
 
tar zxvf apache-tomcat-7.0.64.tar.gz
mv apache-tomcat-7.0.64 tomcat02
chown -R tomcat:tomcat tomcat02

兩個(gè)實(shí)例同時(shí)監(jiān)聽8080端口必然會產(chǎn)生沖突,所以必須修改.

sed -i 's/8080/8081/g' /opt/tomcat01/conf/server.xml
sed -i 's/8005/8001/g' /opt/tomcat01/conf/server.xml
sed -i 's/8080/8082/g' /opt/tomcat02/conf/server.xml
sed -i 's/8005/8002/g' /opt/tomcat02/conf/server.xml

AJP通常用不上,這里統(tǒng)一關(guān)閉

sed -i '/8009/d' /opt/tomcat01/conf/server.xml
sed -i '/8009/d' /opt/tomcat01/conf/server.xml

tomcat在Linux 下默認(rèn)工作模式是bio,性能非常低,建議使用apr或者nio,
這里改為nio,即非阻塞IO,性能比較好。

sed -i.bak 's#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#' /opt/tomcat01/conf/server.xml
sed -i.bak 's#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#' /opt/tomcat02/conf/server.xml

4、創(chuàng)建啟動文件

cd /usr/lib/systemd/system
cat >tomcat01.service EOF
[Unit]
Description=Apache Tomcat 7
After=network.target
[Service]
Type=oneshot
ExecStart=/opt/tomcat01/bin/startup.sh
ExecStop=/opt/tomcat01/bin/shutdown.sh
RemainAfterExit=yes
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
EOF
tomcat02同理
sed 's/tomcat01/tomcat02/g' tomcat01.service > tomcat02.service

5、啟動服務(wù)

systemctl enable tomcat01
systemctl enable tomcat02
systemctl start tomcat01
systemctl start tomcat02

6、查看進(jìn)程

ps aux |grep tomcat
附上一份nginx反向代理tomcat的配置文件
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=static:10m inactive=1h max_size=1g;
 
upstream tomcat {
        ip_hash ;
        #hash           $remote_addr consistent;
        server          127.0.0.1:8081 max_fails=1 fail_timeout=2s ;
        server          127.0.0.1:8082 max_fails=1 fail_timeout=2s ; ;
        keepalive       16;
}
 
server {
        listen          80;
        server_name     tomcat.example.com;
 
        charset         utf-8;
        access_log      /var/log/nginx/tomcat.access.log  main;
        root            /usr/share/nginx/html;
        index           index.html index.htm index.jsp;
 
        location / {
                proxy_pass              http://tomcat;
                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_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;
 
                proxy_connect_timeout   300;
                proxy_send_timeout      300;
                proxy_read_timeout      300;
                proxy_http_version      1.1;
                proxy_set_header        Connection "";
 
                add_header              X-Backend "$upstream_addr";
        }
 
        location ~* ^.+.(js|css|ico|gif|jpg|jpeg|png)$ {
                proxy_pass              http://tomcat ;
                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_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;
 
                proxy_connect_timeout   300;
                proxy_send_timeout      300;
                proxy_read_timeout      300;
                proxy_http_version      1.1;
                proxy_set_header        Connection "";
 
                proxy_cache             static;
                proxy_cache_key         $host$uri$is_args$args;
                proxy_cache_valid       200 302 5m;
                proxy_cache_valid       404 1m;
                proxy_cache_valid       any 1h;
                add_header              X-Cache $upstream_cache_status;
 
                #log_not_found off;
                #access_log off;
                expires max;
        }
 
        location ~ /.ht {
                deny  all;
        } 
}

標(biāo)簽:泉州 邢臺 銅仁 甘孜 周口 忻州 來賓 甘南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《centos7下systemd實(shí)現(xiàn)tomcat多實(shí)例配置方法》,本文關(guān)鍵詞  centos7,下,systemd,實(shí)現(xiàn),tomcat,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《centos7下systemd實(shí)現(xiàn)tomcat多實(shí)例配置方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于centos7下systemd實(shí)現(xiàn)tomcat多實(shí)例配置方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    息烽县| 灌南县| 巍山| 桐城市| 郸城县| 吉首市| 潼关县| 黄梅县| 长汀县| 繁昌县| 探索| 南木林县| 蒲江县| 赣榆县| 日喀则市| 霍邱县| 新源县| 新昌县| 西充县| 千阳县| 山丹县| 平乡县| 华安县| 应用必备| 鞍山市| 西乌珠穆沁旗| 台山市| 瑞金市| 盱眙县| 洪泽县| 奎屯市| 梓潼县| 临海市| 柘荣县| 霍城县| 三穗县| 海城市| 蓝田县| 乌拉特前旗| 娱乐| 新疆|