1. 下载
通过wget 下载jdk以及tomcat
# cd /home
下载jdk:
# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
下载tomcat
# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.16/bin/apache-tomcat-8.5.16.tar.gz
2. 解压
解压下载的jdk,tomcat到/usr/local 目录下
# tar -zxvf apache-tomcat-8.5.16.tar.gz -C /usr/local
# tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/local
# cd /usr/local
重命名为jdk8, tomcat8
# mv jdk1.8.0_131 jdk8
# mv apache-tomcat-8.5.16 tomcat8
3. Java环境配置
注:进入profile 之后按 i 键进行编辑,Esc 键进入命令模式输出 :wq! 保存并退出
# vi /etc/profile
export JAVA_HOME=/usr/local/jdk8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
执行profile让新配置生效
# source /etc/profile
检查是否安装成功
# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11,mixed mode)
4. Tomcat环境配置
配置防火墙
查看防火墙是否开启
# systemctl status firewalld
通过systemctl status firewalld查看firewalld状态,发现当前是dead状态,即防火墙未开启。
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
通过systemctl start firewalld开启防火墙,没有任何提示即开启成功。
# systemctl start firewalld
再次查看开启状态提示以及开启
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2017-06-13 17:03:25 CST; 16s ago
Main PID: 12686 (firewalld)
CGroup: /system.slice/firewalld.service
└─12686 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
关闭防火墙的命令如下:
# systemctl stop firewalld
开启Tomcat默认的8080端口
# firewall-cmd --permanent --zone=public --add-port=8080/tcp
# firewall-cmd --reload
如果还是不能访问,在阿里云的安全组中配置
创建Tomcat 用户
基于安全管理的前提条件下,安装Tomcat前,单独建立系统帐号和组用于运行Tomcat。
首先,创建一个新的tomcat组:
# groupadd tomcat
然后,创建一个新的tomcat用户,指定home目录 /usr/local/tomcat8 ,并将tomcat用户加入tomcat组:
# useradd -M -s /bin/nologin -g tomcat -d /usr/local/tomcat8 tomcat
配置目录的归属
# chown -R tomcat:tomcat /usr/local/tomcat8
建立自启动服务
# vi /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 8
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/local/jdk8
Environment=CATALINA_PID=/usr/local/tomcat8/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/local/tomcat8
Environment=CATALINA_BASE=/usr/local/tomcat8
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
[Install]
WantedBy=multi-user.target
配置自启动服务
# systemctl daemon-reload
# systemctl start tomcat
# systemctl enable tomcat
原文链接:https://www.f2er.com/centos/377203.html