以前,我一直都是使用Windows server 2008 作为java的应用部署环境来使用,但是貌似主流的软件公司都是使用linux,这对我来说,是一个硬伤啊。
正好,现在公司现在有个项目,自主选择的余地比较大,在使用操作环境上,队友强烈建议使用linux,并吧嗒吧嗒的说了一堆linux的好处,好吧,那就用linux吧,虽然我之前不会,但是我也有强烈的信心,把环境搭好,于是我就真的搭建好了,现在把整个过程分享出来,包含:jdk 1.8的安装和tomcat 8.0的安装
然后到linux的黑窗口
输入:javac –version 查看服务器上,当前默认的jdk 版本
[root@sxora01 ~]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
再输入:rpm -qa|grep java
[root@sxora01 ~]# rpm -qa|grep java
java-1.6.0-openjdk-devel-1.6.0.0-1.66.1.13.0.el6.x86_64
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
tzdata-java-2013g-1.el6.noarch
java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
libvirt-java-devel-0.4.9-1.el6.noarch
java-1.7.0-openjdk-devel-1.7.0.45-2.4.3.3.el6.x86_64
libvirt-java-0.4.9-1.el6.noarch
[root@sxora01 ~]#
这个时候,我们可以看到linux 默认java 版本,但是现在我们想使用jdk 1.8 那么我们就要去卸载默认的版本
卸载以上三个文件(需要root权限,登录root权限卸载)
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
rpm -e --nodeps tzdata-java-2013g-1.el6.noarch
完毕后,再执行 java -version
如果黑窗口出现,没有那个文件或目录的提示那就说明是卸载完毕了,如果没有则
输入:rpm -qa|grep java
输入:rpm -e --nodeps java XXX 把剩余的版本卸载完成
如果上面的步骤执行完毕,那么进入到下一步
[root@sxweb ~]# cd /usr
[root@sxweb usr]# mkdir java
在 usr 目录下创建java 文件夹
然后在 mv jdk-8u111-linux-x64.tar.gz /usr/java
将压缩包移入到指定的目录
tar -xvzf jdk-8u111-linux-x64.tar.gz
将文件进行解压
然后进行环境配置
[root@sxweb java]# vi ~/.bashrc
出现后,键盘单击 a 进入编辑模式
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export JAVA_HOME=/usr/java/jdk1.8.0_111
export JAVA_BIN=$JAVA_HOME/bin
export JAVA_LIB=$JAVA_HOME/lib
export CLASSPATH=.:$JAVA_LIB/tools.jar:$JAVA_LIB/dt.jar
export PATH=$JAVA_BIN:$PATH
编辑完成 按esc 退出编辑
在输入:wq 关闭并退出
使jdk环境变量生效,source ~/.bashrc
[root@sxweb java]# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
[root@sxweb java]#
再次输入 java -version
则可以看见,环境搭建成功
现在,我们再来安装tomcat
cd /usr 进入 usr 目录
mkdir tomcat 创建tomcat 文件夹
mv apache-tomcat-8.0.39.tar.gz /usr/tomcat 将tomcat 包移动到tomcat里面
tar -xvzf apache-tomcat-8.0.39.tar.gz 进行解压
[root@sxweb tomcat]# mv apache-tomcat-8.0.39/* /usr/tomcat
[root@sxweb tomcat]# ll
total 9204
drwxr-xr-x 2 root root 4096 Jan 5 10:24 apache-tomcat-8.0.39
-rw-r--r-- 1 root root 9304967 Dec 27 17:16 apache-tomcat-8.0.39.tar.gz
drwxr-xr-x 2 root root 4096 Jan 5 10:24 bin
drwxr-xr-x 2 root root 4096 Nov 9 16:53 conf
drwxr-xr-x 2 root root 4096 Jan 5 10:24 lib
-rw-r--r-- 1 root root 57011 Nov 9 16:53 LICENSE
drwxr-xr-x 2 root root 4096 Nov 9 16:48 logs
-rw-r--r-- 1 root root 1444 Nov 9 16:53 NOTICE
-rw-r--r-- 1 root root 6741 Nov 9 16:53 RELEASE-NOTES
-rw-r--r-- 1 root root 16195 Nov 9 16:53 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jan 5 10:24 temp
drwxr-xr-x 7 root root 4096 Nov 9 16:50 webapps
drwxr-xr-x 2 root root 4096 Nov 9 16:48 work
[root@sxweb tomcat]# cd apache-tomcat-8.0.39
[root@sxweb apache-tomcat-8.0.39]# ll
total 0
执行后,在将解压文件夹内容移出到tomcat 目录下
删除空文件夹
[root@sxweb tomcat]# rm -rf apache-tomcat-8.0.39
cp /usr/tomcat/bin/catalina.sh /etc/init.d/tomcat
将catalina.sh 复制成/etc/init.d/tomcat
在对该文件进行编辑
[root@sxweb ~]# cd /etc/init.d
[root@sxweb init.d]# ll
total 404
-rwxr-xr-x. 1 root root 1288 Nov 23 2013 abrt-ccpp
-rwxr-xr-x. 1 root root 1628 Nov 23 2013 abrtd
-rwxr-xr-x. 1 root root 1642 Nov 23 2013 abrt-oops
-rwxr-xr-x. 1 root root 1725 Aug 19 2010 acpid
-rwxr-xr-x. 1 root root 2062 Jan 30 2012 atd
-rwxr-xr-x. 1 root root 3378 Jun 22 2012 auditd
-rwxr-xr-x. 1 root root 4043 Nov 23 2013 autofs
-r-xr-xr-x. 1 root root 1340 Nov 24 2013 blk-availability
-rwxr-xr-x. 1 root root 710 Nov 11 2010 bluetooth
-rwxr-xr-x. 1 root root 2094 Feb 22 2013 certmonger
-rwxr-xr-x. 1 root root 5160 Nov 23 2013 cgconfig
-rwxr-xr-x. 1 root root 3580 Nov 23 2013 cgred
-rwxr-xr-x. 1 root root 11355 Aug 13 2013 cpuspeed
-rwxr-xr-x. 1 root root 2826 Nov 23 2013 crond
-rwxr-xr-x. 1 root root 3034 Aug 17 2013 cups
-rwxr-xr-x. 1 root root 1702 Feb 22 2013 dnsmasq
-rwxr-xr-x. 1 root root 3245 Jul 9 2013 firstboot
-rw-r--r--. 1 root root 18586 Oct 10 2013 functions
-rwxr-xr-x. 1 root root 1801 Jul 20 2011 haldaemon
-rwxr-xr-x. 1 root root 5866 Oct 10 2013 halt
-rwxr-xr-x. 1 root root 2001 Aug 14 2013 htcacheclean
-rwxr-xr-x. 1 root root 3371 Aug 14 2013 httpd
-rwxr-xr-x. 1 root root 10804 Nov 23 2013 ip6tables
-rwxr-xr-x. 1 root root 10688 Nov 23 2013 iptables
-rwxr-xr-x. 1 root root 1938 Aug 23 2013 irqbalance
-rwxr-xr-x. 1 root root 18133 Nov 23 2013 kdump
-rwxr-xr-x. 1 root root 652 Oct 10 2013 killall
-rwxr-xr-x. 1 root root 15432 Nov 23 2013 libvirt-guests
-r-xr-xr-x. 1 root root 2134 Nov 24 2013 lvm2-lvmetad
-r-xr-xr-x. 1 root root 2665 Nov 24 2013 lvm2-monitor
-rwxr-xr-x. 1 root root 2571 Oct 11 2013 mdmonitor
-rwxr-xr-x. 1 root root 2200 Sep 14 2012 messagebus
-rwxr-xr-x. 1 root root 2989 Oct 10 2013 netconsole
-rwxr-xr-x. 1 root root 5428 Oct 10 2013 netfs
-rwxr-xr-x. 1 root root 6334 Oct 10 2013 network
-rwxr-xr-x. 1 root root 2205 Nov 23 2013 NetworkManager
-rwxr-xr-x. 1 root root 6364 Nov 22 2013 nfs
-rwxr-xr-x. 1 root root 3526 Nov 22 2013 nfslock
-rwxr-xr-x. 1 root root 1923 Jul 15 2013 ntpd
-rwxr-xr-x. 1 root root 2043 Jul 15 2013 ntpdate
-rwxr-xr-x. 1 root root 1875 Oct 15 2012 numad
-rwxr-xr-x. 1 root root 2261 Jun 25 2011 oddjobd
-rwxr-xr-x. 1 root root 2023 Apr 3 2012 portreserve
-rwxr-xr-x. 1 root root 3852 Dec 3 2011 postfix
-rwxr-xr-x. 1 root root 1556 Jul 17 2012 psacct
-rwxr-xr-x. 1 root root 2034 Jun 13 2013 quota_nld
-rwxr-xr-x. 1 root root 1513 Sep 17 2013 rdisc
-rwxr-xr-x. 1 root root 1822 Nov 23 2013 restorecond
-rwxr-xr-x. 1 root root 1808 Dec 18 2011 rngd
-rwxr-xr-x. 1 root root 2073 Feb 22 2013 rpcbind
-rwxr-xr-x. 1 root root 2518 Nov 22 2013 rpcgssd
-rwxr-xr-x. 1 root root 2305 Nov 22 2013 rpcidmapd
-rwxr-xr-x. 1 root root 2464 Nov 22 2013 rpcsvcgssd
-rwxr-xr-x. 1 root root 2011 Aug 15 2013 rsyslog
-rwxr-xr-x. 1 root root 1698 Nov 23 2013 sandbox
-rwxr-xr-x. 1 root root 2056 Nov 20 2012 saslauthd
-rwxr-xr-x. 1 root root 647 Oct 10 2013 single
-rwxr-xr-x. 1 root root 3002 Feb 22 2013 smartd
-rwxr-xr-x. 1 root root 2162 Nov 22 2013 snmpd
-rwxr-xr-x. 1 root root 1738 Nov 22 2013 snmptrapd
-rwxr-xr-x. 1 root root 2472 Nov 23 2013 spice-vdagentd
-rwxr-xr-x. 1 root root 4534 Nov 23 2013 sshd
-rwxr-xr-x. 1 root root 2712 Nov 23 2013 sssd
-rwxr-xr-x. 1 root root 2276 Apr 2 2013 svnserve
-rwxr-xr-x. 1 root root 1144 Nov 23 2013 sysstat
-rwxr-xr-x 1 root root 22616 Jan 5 10:48 tomcat
-rwxr-xr-x. 1 root root 2294 Nov 23 2013 udev-post
-rwxr-xr-x. 1 root root 1674 Feb 22 2013 wdaemon
-rwxr-xr-x. 1 root root 1608 Nov 23 2013 winbind
-rwxr-xr-x. 1 root root 1866 Feb 4 2013 wpa_supplicant
-rwxr-xr-x. 1 root root 3555 Oct 8 2013 xinetd
-rwxr-xr-x. 1 root root 4799 Feb 22 2013 ypbind
[root@sxweb init.d]# vim tomcat
在文件中加入,我下段全部内容
# chkconfig: 2345 63 37
# description: tomcat server init script
# Source Function Library
. /etc/init.d/functions
JAVA_HOME=/usr/java/jdk1.8.0_111
CATALINA_HOME=/usr/tomcat
注释掉的也要加上,不要漏掉
完整:
#!/bin/sh
# chkconfig: 2345 63 37
# description: tomcat server init script
# Source Function Library
. /etc/init.d/functions
JAVA_HOME=/usr/java/jdk1.8.0_111
CATALINA_HOME=/usr/tomcat
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
# Control Script for the CATALINA Server
"tomcat" 619L, 22616C
然后执行