Linux 下面安装tomcat

一:停止tomcat服务,一般tomcat安装都是通过安装包的形式安装,因此,只需要将tomcat的安装文件删除掉即可。

1:找到tomcat的安装路径,停止服务

[root@li1062-188 /]# cd /usr/local
[root@li1062-188 local]# ls -l
total 56
drwxr-xr-x 9 root root  4096 Apr 29 03:14 apache-tomcat-7.0.69
drwxr-xr-x 2 root root  4096 Sep 23  2011 bin
drwxr-xr-x 2 root root  4096 Sep 23  2011 etc
drwxr-xr-x 2 root root  4096 Sep 23  2011 games
drwxr-xr-x 2 root root  4096 Sep 23  2011 include
drwxr-xr-x 2 root root  4096 Sep 23  2011 lib
drwxr-xr-x 2 root root  4096 Sep 23  2011 lib64
drwxrwxrwx 8  501 games 4096 Apr 11 03:55 libevent-1.4.12-stable
drwxr-xr-x 2 root root  4096 Sep 23  2011 libexec
drwxr-xr-x 5 root root  4096 Apr  8 09:08 memcached
drwxrwxr-x 7 1000  1000 4096 Apr  8 09:08 memcached-1.4.25
drwxr-xr-x 2 root root  4096 Sep 23  2011 sbin
drwxr-xr-x 5 root root  4096 Mar  9  2014 share
drwxr-xr-x 2 root root  4096 Sep 23  2011 src
[root@li1062-188 local]# cd apache-tomcat-7.0.69/
[root@li1062-188 apache-tomcat-7.0.69]# ls -l
total 116
drwxr-xr-x 2 root root  4096 Apr 29 03:31 bin
drwxr-xr-x 3 root root  4096 Apr 29 06:53 conf
drwxr-xr-x 2 root root  4096 Apr 29 03:14 lib
-rw-r--r-- 1 root root 56846 Apr 11 07:59 LICENSE
drwxr-xr-x 2 root root  4096 Apr 29 06:53 logs
-rw-r--r-- 1 root root  1239 Apr 11 07:59 NOTICE
-rw-r--r-- 1 root root  8965 Apr 11 07:59 RELEASE-NOTES
-rw-r--r-- 1 root root 16195 Apr 11 07:59 RUNNING.txt
drwxr-xr-x 2 root root  4096 Apr 29 03:14 temp
drwxr-xr-x 7 root root  4096 Apr 11 07:58 webapps
drwxr-xr-x 3 root root  4096 Apr 29 06:53 work
[root@li1062-188 apache-tomcat-7.0.69]# cd bin
[root@li1062-188 bin]# ./shutdown.sh 
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.69
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.69
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.69/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.69/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.69/bin/tomcat-juli.jar
[root@li1062-188 bin]# 

2:删除tomcat文件。

[root@li1062-188 local]# rm -rf apache-tomcat-7.0.69/
[root@li1062-188 local]#

3:查找对应的配置文件,在/etc/profile下面,如果有,就注释或者删除,然后,使之立即生效

[root@li1062-188 local]# echo $CATALINA_HOME

[root@li1062-188 local]# source /etc/profile
[root@li1062-188 local]# 

二:下载对应的tomat包,并配置环境,我们想要下载tomcat7.0

1:下载tomcat7.0

[root@li1062-188 local]# yum -y list tomcat*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * extras: mirrors.linode.com
 * updates: mirrors.linode.com
Available Packages
tomcat6.x86_64                                                                                                            6.0.24-94.el6_7                                                                                            updates
tomcat6-admin-webapps.x86_64                                                                                              6.0.24-94.el6_7                                                                                            updates
tomcat6-docs-webapp.x86_64                                                                                                6.0.24-94.el6_7                                                                                            updates
tomcat6-el-2.1-api.x86_64                                                                                                 6.0.24-94.el6_7                                                                                            updates
tomcat6-javadoc.x86_64                                                                                                    6.0.24-94.el6_7                                                                                            updates
tomcat6-jsp-2.1-api.x86_64                                                                                                6.0.24-94.el6_7                                                                                            updates
tomcat6-lib.x86_64                                                                                                        6.0.24-94.el6_7                                                                                            updates
tomcat6-servlet-2.5-api.x86_64                                                                                            6.0.24-94.el6_7                                                                                            updates
tomcat6-webapps.x86_64                                                                                                    6.0.24-94.el6_7                                                                                            updates
tomcatjss.noarch             


没有tomcat 7.0 因此,我们找到tomcat7.0的下载路径,使用wget进行下载。

去官网:http://tomcat.apache.org/

[root@li1062-188 local]# cd /tmp
[root@li1062-188 tmp]# wget http://apache.opencas.org/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
--2016-04-29 07:48:15--  http://apache.opencas.org/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
Resolving apache.opencas.org... 2001:cc0:2004:1:225:90ff:fe00:fe8b, 159.226.11.160
Connecting to apache.opencas.org|2001:cc0:2004:1:225:90ff:fe00:fe8b|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8910579 (8.5M) [application/x-gzip]
Saving to: 鈥渁pache-tomcat-7.0.69.tar.gz.1鈥

100%[==================================================================================================================================================================================================>] 8,910,579    343K/s   in 44s     

2016-04-29 07:49:00 (199 KB/s) - 鈥渁pache-tomcat-7.0.69.tar.gz.1鈥saved [8910579/8910579]

[root@li1062-188 tmp]# cd /tmp
[root@li1062-188 tmp]# wget http://apache.opencas.org/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
--2016-04-29 07:49:30--  http://apache.opencas.org/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
Resolving apache.opencas.org... 2001:cc0:2004:1:225:90ff:fe00:fe8b, 159.226.11.160
Connecting to apache.opencas.org|2001:cc0:2004:1:225:90ff:fe00:fe8b|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8910579 (8.5M) [application/x-gzip]
Saving to: 鈥渁pache-tomcat-7.0.69.tar.gz鈥

100%[==================================================================================================================================================================================================>] 8,910,579    175K/s   in 41s     

2016-04-29 07:50:13 (210 KB/s) - 鈥渁pache-tomcat-7.0.69.tar.gz鈥saved [8910579/8910579]

[root@li1062-188 tmp]# tar -zxvf apache-tomcat-7.0.69.tar.gz -C /usr/local

下载完成之后,解压到/usr/local路径下面。


2:配置环境变量

[root@li1062-188 bin]# vi catalina.sh 
#!/bin/sh
CATALINA_HOME=/usr/local/apache-tomcat-7.0.69/


3:启动,停止,查看日志 服务

[root@li1062-188 bin]# ./shutdown.sh 
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.69/
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.69/
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.69//temp
Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.69//bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.69//bin/tomcat-juli.jar
Apr 29, 2016 7:57:46 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8005. Tomcat may not be running.
Apr 29, 2016 7:57:46 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop: 
java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at java.net.Socket.connect(Socket.java:528)
        at java.net.Socket.(Socket.java:425)
        at java.net.Socket.(Socket.java:208)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:498)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:343)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:430)

[root@li1062-188 bin]# ./startup.sh 
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.69/
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.69/
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.69//temp
Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.69//bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.69//bin/tomcat-juli.jar
Tomcat started.
[root@li1062-188 bin]# cd ../logs
[root@li1062-188 logs]# tail -f catalina.out
Apr 29, 2016 7:57:58 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.69/webapps/manager
Apr 29, 2016 7:57:58 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.69/webapps/manager has finished in 157 ms
Apr 29, 2016 7:57:58 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 29, 2016 7:57:58 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Apr 29, 2016 7:57:58 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2328 ms


4:启动mysql后,访问 http://ip:8080/ 看看有没有出现界面。


你可能感兴趣的:(Linux)