码迷,mamicode.com
首页 > 编程语言 > 详细

CentOS安装java和tomcat

时间:2018-12-30 23:18:42      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:目录   restart   自启   connector   class   火墙   conf   lookup   .gz   

检查java版本
rpm -qa | grep java

清除系统自带java
rpm -e --nodeps rpm -qa | grep java

复制文件
cp jdk-8u191-linux-x64.tar.gz /usr/java

文件错了。。删除
rm -rf /usr/java

mkdir /usr/local/java/
tar -zxvf jdk-8u191-linux-x64.tar.gz -C /usr/local/java
mkdir /usr/local/tomcat/
tar -zxvf apache-tomcat-8.5.35.tar.gz -C /usr/local/tomcat

设置环境变量:
gedit /etc/profile

JAVA_HOME=/usr/local/java/jdk1.8.0_191
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

设置生效
source /etc/profile

配置tomcat server.xml

server.xml可以配置端口,编码以及配置项目等等,我们这里就配置一个端口,把默认的8080,修改成80

gedit /usr/local/tomcat/apache-tomcat-8.5.35/conf/server.xml

将<Connector port="8080" protocol="HTTP/1.1"
改成<Connector port="80" protocol="HTTP/1.1"

防火墙添加80/8080端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
#刷新防火墙 使其生效
sudo firewall-cmd --reload

firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表

启动tomcat
/usr/local/tomcat/apache-tomcat-8.5.35/bin/startup.sh

设置开机自启动

如果要开机自启动tomcat,配置如下:
chmod +x /etc/rc.d/rc.local
gedit /etc/rc.d/rc.local

在文件中添加下面几行:

export JAVA_HOME=/usr/local/java/jdk1.8.0_191

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
/usr/local/tomcat/bin/startup.sh

配置tomcat的jdk环境变量
yum -y install vim
gedit /usr/local/tomcat/apache-tomcat-8.5.35/bin/catalina.sh

在 OS specific support. 前面加入如下代码:

JAVA_HOME=/usr/local/java/jdk1.8.0_191
JRE_HOME=$JAVA_HOME/jre

配置tomcat8开机启动

在/usr/lib/systemd/system目录下增加tomcat8.service文件,内容如下:

gedit /usr/lib/systemd/system/tomcat.service

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=oneshot
ExecStart=/usr/local/tomcat/apache-tomcat-8.5.35/bin/startup.sh
ExecStop=/usr/local/tomcat/apache-tomcat-8.5.35/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

允许tomcat开机启动
systemctl enable tomcat

tomcat8常见命令
systemctl start tomcat.service //启动tomcat
systemctl stop tomcat.service //关闭tomcat
systemctl restart tomcat.service //重启tomcat
systemctl status tomcat.service //查看状态tomcat


CentOS安装java和tomcat

标签:目录   restart   自启   connector   class   火墙   conf   lookup   .gz   

原文地址:http://blog.51cto.com/7701254/2337233

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!