一、先安装 JDK 1.8
1、登录网页:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2、下载Linux x64 位版本:jdk-8u45-linux-x64.rpm
3、将文件移到安装目录,比如:/root/
4、使用以下命令进行安装:
[root@localhost ~]# rpm -ivh jdk-8u45-linux-x64.rpm
5、使用以下命令验证安装结果:
[root@localhost ~]# java -version
java version “1.8.0_45″
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
— 查看java命令路径
[root@localhost ~]# whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java
— 设置默认的 java, javac 版本
[root@localhost ~]# ln -s -f /usr/java/jdk1.8.0_45/jre/bin/java
[root@localhost ~]# ln -s -f /usr/java/jdk1.8.0_45/bin/javac
— 看到此信息,表示安装成功.
6、配置 java 运行环境变量:
[root@localhost local]# vi /etc/profile — 在末端添加
export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@localhost local]# source /etc/profile — 生效此配置
二、安装 Tomcat 8.0
1、下载Tomcat源码安装包:
[root@localhost ~]# wget http://apache.dataguru.cn/tomcat/tomcat-8/v8.0.21/bin/apache-tomcat-8.0.21.tar.gz
2、将下载的压缩包进行解压:
[root@localhost ~]# tar -xzf apache-tomcat-8.0.21.tar.gz
3、将解压后的目录移动更新至:
[root@localhost ~]# mv apache-tomcat-8.0.21 /usr/local/tomcat8
4、配置Tomcat,使其可以启动:
[root@localhost ~]# cd /usr/local/tomcat8/bin
[root@localhost bin]# vi catalina.sh — 在有效代码前添加如下代码.
CATALINA_HOME=/usr/local/tomcat8
[root@localhost bin]# chmod +x *.sh — 对所有 .sh 文件添加可执行权限.
5、启动 Tomcat
[root@localhost bin]# ./startup.sh — 在/usr/local/tomcat8/bin 目录下执行
Using CATALINA_BASE: /usr/local/tomcat8
Using CATALINA_HOME: /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME: /usr/java/default/jre
Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
6、测试浏览器访问:http://localhost:8080/ — localhost 可使用 tomcat 服务器的 ip 地址.
出现此页面表示已经配置成功。
7、设置为随系统一并启动 Tomcat 服务.
[root@localhost ~]# cd /etc/rc.d/init.d/
[root@localhost init.d]# vi tomcat8 — 创建一个 tomcat8 脚文件.
#!/bin/sh # # tomcat: Start/Stop/Restart tomcat # # chkconfig: 2345 80 20 # description: Tomcat is a Java Servlet Container # # match these values to your environment: # Source function library. source /etc/profile ./etc/rc.d/init.d/functions TOMCAT=/usr/local/tomcat8/ start() { echo -n “Starting Tomcat: “ $TOMCAT/bin/catalina.sh start } stop() { echo -n “Stopping Tomcat: “ $TOMCAT/bin/catalina.sh stop } # See how we were called. case “$1″ in start) start ;; stop) stop ;; status) ;; restart) stop start ;; *) echo “Usage: $0 {start stop restart}” ;; esac exit $RETVAL
[root@localhost init.d]# chmod a+x tomcat8
[root@localhost init.d]# chkconfig –add tomcat8
[root@localhost init.d]# chkconfig –list tomcat8
[root@localhost init.d]# chkconfig tomcat8 on
[root@localhost init.d]# reboot