阿里云centos7.x安装jdk+tomcat
安装过程需要root权限登陆
1.安装java
在安装tomcat之前需要安装java se,这里使用yum工具安装jdk运行时环境
yum install java-1.8.0-openjdk.x86_64
查看java是否安装成功
java -version
此时应该输出
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
2.为tomcat创建一个专用用户
groupadd tomcat
useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
3.下载和安装Apcahe Tomcat
cd ~
wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.50/bin/apache-tomcat-8.0.50.tar.gz
tar -zxvf apache-tomcat-8.0.50.tar.gz -C /opt/tomcat --strip-components=1
4.设置权限
cd /opt/tomcat
chgrp -R tomcat conf
chmod g+rwx conf
chmod g+r conf/*
chown -R tomcat logs/ temp/ webapps/ work/
chgrp -R tomcat bin
chgrp -R tomcat lib
chmod g+rwx bin
chmod g+r bin/*
5.为tomcat创建一个System unit文件
vim /etc/systemd/system/tomcat.service
将下列代码复制进去
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
输入 :wq保存退出
6.安装haveged(出于安全的考虑)
yum install haveged
systemctl start haveged.service
systemctl enable haveged.service
7.开始测试apche tomcat
systemctl start tomcat.service
systemctl enable tomcat.service
为了在浏览器中测试tomcat,需要修改firewall规则
firewall-cmd --zone=public --permanent --add-port=8080/tcp
firewall-cmd --reload
在浏览器输入http://your-server-ip:8080测试
(如果是阿里云,需要打开安全组策略的8080端口)
如下图:
测试页面成功页面: