forked from totemtec/documents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tomcat Installation.txt
155 lines (125 loc) · 2.95 KB
/
Tomcat Installation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Tomcat安装在/data/tomcat7
下载压缩包
wget下载 或者 scp上传
解压缩包
tar -xvzf apache-tomcat-7.0.53.tar.gz
重命名解压出来的目录
mv apache-tomcat-7.0.53 tomcat7
进入webapps目录清空该目录
# rm -rf docs/
# rm -rf examples/
# rm -rf host-manager/
# rm -rf manager/
运行Tomcat
./startup.sh
停止Tomcat
./shutdown.sh
新增用户tomcat/tomcat专门管理Tomcat的
$ sudo adduser tomcat
passwd tomcat 回车然后修改密码同用户名也是tomcat
尝试使用用户tomcat启动和关闭服务
如果权限不够,需要用root用户变更权限:
sudo chown -R tomcat /data/tomcat7
sudo chmod -R u+rw /data/tomcat7
安装Tomcat成自启动服务
1. 新建启动文件/etc/init.d/tomcat
https://gist.github.com/valotas/1000094
======内容开始,有些设置要修改 ====
#!/bin/bash
#
# tomcat7 This shell script takes care of starting and stopping Tomcat
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Release implementation for Servlet 2.5 and JSP 2.1
# Short-Description: start and stop tomcat
### END INIT INFO
## Source function library.
#. /etc/init.d/tomcat
export JAVA_HOME=/usr/java/default
export JAVA_OPTS="-Dfile.encoding=UTF-8 \
-Dcatalina.logbase=/var/log/tomcat7 \
-Dnet.sf.ehcache.skipUpdateCheck=true \
-XX:+DoEscapeAnalysis \
-XX:+UseConcMarkSweepGC \
-XX:+CMSClassUnloadingEnabled \
-XX:+UseParNewGC \
-XX:MaxPermSize=128m \
-Xms512m -Xmx1024m"
export PATH=$JAVA_HOME/bin:$PATH
TOMCAT_HOME=/data/tomcat7
SHUTDOWN_WAIT=20
tomcat_pid() {
echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}
start() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is already running (pid: $pid)"
else
# Start tomcat
echo "Starting tomcat"
ulimit -n 100000
umask 007
/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/startup.sh
fi
return 0
}
stop() {
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Stoping Tomcat"
/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/shutdown.sh
let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $pid
fi
else
echo "Tomcat is not running"
fi
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pid=$(tomcat_pid)
if [ -n "$pid" ]
then
echo "Tomcat is running with pid: $pid"
else
echo "Tomcat is not running"
fi
;;
esac
exit 0
======内容结束====
2. 添加执行权限
chmod +x /etc/init.d/tomcat
3. 随系统启动
chkconfig --add tomcat
4. 重启检查测试一下