centos7 jdk8 tomcat8 安装

Posted 北冥大帝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 jdk8 tomcat8 安装相关的知识,希望对你有一定的参考价值。

安装jdk

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F;oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"

# tar xzf jdk-8u131-linux-x64.tar.gz
# cd /opt/jdk1.8.0_131/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2
# alternatives --config java


There are 3 programs which provide ‘java‘.

Selection Command
-----------------------------------------------
* 1 /opt/jdk1.7.0_71/bin/java
+ 2 /opt/jdk1.8.0_45/bin/java
3 /opt/jdk1.8.0_91/bin/java
4 /opt/jdk1.8.0_131/bin/java

Enter to keep the current selection[+], or type selection number: 4
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_131/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_131/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_131/bin/jar
# alternatives --set javac /opt/jdk1.8.0_131/bin/javac

=================================================================

配置环境变量:
vim /etc/profile
增加:
# export JAVA_HOME=/opt/jdk1.8.0_131
# export JRE_HOME=/opt/jdk1.8.0_131/jre
# export PATH=$PATH:/opt/jdk1.8.0_131/bin:/opt/jdk1.8.0_131/jre/bin
然后:
source /etc/profile

java -version :查看版本信息

=================================================================

安装tomcat8
http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz

解压:
tar -zxvf apache-tomcat-8.0.45.tar.gz -C /opt/
=======================================================
centos7使用systemctl替换了service命令
1、查看服务
systemctl status name.service
启动服务
systemctl start name.service
停止服务
systemctl stop name.service
重启服务
systemctl restart name.service
增加开机启动
systemctl enable name.service
删除开机启动
systemctl disable name.service
2、tomcat增加启动参数
tomcat需要增加一个pid文件
在tomcat/bin 目录下面,增加setenv.sh配置,catalina.sh启动的时候会调用,同时配置java内存参数
[[email protected] bin]# vim setenv.sh
写入一下命令:
#tomcat启动pid

export CATALINA_HOME=/home/hwmon/apache-tomcat-8.0.20
export CATALINA_BASE=/home/hwmon/apache-tomcat-8.0.20
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add Java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

3、增加tomcat.service
在/usr/lib/systemd/system目录下增加tomcat.service,目录必须是绝对目录
[[email protected] bin]# vim /usr/lib/systemd/system/tomcat.service
写入一下命令:
[Unit]

Description=Tomcat

After=syslog.target network.target remote-fs.target nss-lookup.target


[Service]

Type=forking

PIDFile=/home/hwmon/tomcat/tomcat.pid

ExecStart=/home/hwmon/tomcat/bin/startup.sh

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true


[Install]

WantedBy=multi-user.target

##[unit]配置了服务的描述,规定了在network启动之后执行,

##[service]配置服务的pid,服务的启动,停止,重启

##[install]配置了使用用户

4、使用tomcat.service

systemctl enable tomcat.service

systemctl start tomcat.service

systemctl stop tomcat.service

systemctl restart tomcat.service

因为配置pid,在启动的时候会在tomcat的根目录下生产tomcat.pid文件,停止后删除

=====================================================================================

查看防火墙:
firewall-cmd --list-ports


1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)


firewall-cmd --zone=public --add-port=80/tcp --permanent





























































以上是关于centos7 jdk8 tomcat8 安装的主要内容,如果未能解决你的问题,请参考以下文章

centos7下 jdk8的安装及tomcat8的安装

Centos7 安装 Tomcat8

Centos7 安装 Tomcat8

centos7上安装配置tomcat8.5

开发人员学Linux:CentOS7中安装JDK8和Tomcat8

CentOs7.4安装jdk1.8-tomcat8-activemq