centos7安裝tomcat7使用jsvc做守護進程

來源:互聯網
上載者:User

標籤:container   apache   des   自啟動   esc   sys   ali   pac   daemon   

1.首先添加不能登陸的使用者及組

groupadd tomcat
useradd -r -g tomcat -s /sbin/nologin tomcat

2.安裝openJDK並設定好JAVA_HOME環境變數

3.解壓tomcat檔案

tar -xzvf tomcat-version.tar.gz -C /usr/local
cd /user/local
mv tomcat-version tomcat
cd tomcat/bin
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-1.1.x-native-src/unix
./configure
make
cp jsvc ../..
cd ../..
4.添加systemd服務單元,添加tomcat為自啟動服務
vi /etc/systemd/system/tomcat.service
添加如下內容


[Unit]
Description=Apache Tomcat Web Application Container
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java
Environment=CATALINA_HOME=/usr/local/tomcat
Environment=CATALINA_BASE=/usr/local/tomcat

ExecStart=/usr/local/tomcat/bin/daemon.sh start
ExecStop=/usr/local/tomcat/bin/daemon.sh stop

[Install]
WantedBy=multi-user.target

再運行:
systemctl daemon-reload
systemctl enable tomcat
systemctl start tomcat
systemctl status tomcat
註:
可以不用在tomcat.service中聲明JAVA_HOME,CATALINA_BASE,CATALINA_HOME變數,也可以在tomcat安裝目錄的bin下的daemon.sh檔案的首行聲明(即:在# OS specific support (must be ‘true‘ or ‘false‘).前一行)
systemd的指令碼不會從/etc/profile中讀取環境變數
記得開啟防火牆及8080連接埠

centos7安裝tomcat7使用jsvc做守護進程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.