Script Install LNMP

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
#!/bin/bash

#

if [[ $1 == "uninstall" ]];then
echo "starting backup data..."
mkdir -p /www/backup
service mysqld stop
service nginxd stop
service httpd stop
service wdapache stop
service pureftpd stop
tar zcvf /www/backup/mysqldatdbk.tar.gz /www/wdlinux/mysql/var
tar zcvf /www/backup/ngconfbk.tar.gz /www/wdlinux/nginx/conf
tar zcvf /www/backup/apconfbk.tar.gz /www/wdlinux/apache/conf
rpm -e lanmp_wdcp --nodeps
rm -fr /www/wdlinux
echo
echo " lanmp,wdcp remove is OK"
echo
exit 0
fi

echo "Turn off selinux..."
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sed -i 's/^exclude=/#exclude=/g' /etc/yum.conf
yum install -y gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 iptables sendmail iptables unzip

#echo "Check the network..."
#ping -c 2 113.105.167.1
#if [[ $? != 0 ]];then
# echo
# echo "network err"
# exit 1
#fi
ping -c 3 dl.wdlinux.cn
if [[ $? == 2 ]];then
echo
echo "dns error"
exit 1
fi

if [[ ! -d /www/wdlinux ]];then
echo
echo "rpm remove..."
rpm -e php --nodeps
rpm -e httpd --nodeps
rpm -e mysql-server --nodeps
rpm -e mysql --nodeps
fi

echo "yum update..."
yum install -y make autoconf sudo wget libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel iptables

arch=i386
Aurl="http://dl.wdlinux.cn:5180/rpms"
if [[ `uname -m` == "x86_64" ]];then
arch="x86_64"
fi

function in_finsh {
echo
echo " configuration ,lamp or lnmp,wdcp install is finshed"
echo " visit http://ip"
echo " wdcp visit http://ip:8080"
echo " more infomation please visit http://www.wdlinux.cn"
echo
}

function in_check {
if [[ $1 == 1 ]];then
echo
echo "============ $2 install error ============="
echo
exit 1
else
echo
echo "============ $2 install OK =============="
echo
echo
fi
}

grep -E 'wdOS 1|5\.' /etc/redhat-release > /dev/null 2>&1
v1=$?
grep -E 'wdOS 2|6\.' /etc/redhat-release > /dev/null 2>&1
v2=$?
if [ $v1 == 0 ];then
RF="lanmp_wdcp-2-5.$arch.rpm";
elif [ $v2 == 0 ];then
RF="lanmp_wdcp-2-5.el6.$arch.rpm";
if [ $arch == "x86_64" ];then
wget -c http://dl.wdlinux.cn:5180/soft/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
else
wget -c http://dl.wdlinux.cn:5180/soft/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm
fi
yum install -y mhash-devel libmcrypt-devel
else
echo
echo "The current system does not support"
echo
exit
fi
wget -c http://dl.wdlinux.cn:5180/rpms/$RF
rpm -ivh $RF --nodeps
I_F=$?
if [ $I_F == 0 ];then
echo
fi
in_check $I_F lanmp_wdcp

rm -f wdcp_v*
wget -c http://down.wdlinux.cn/down/wdcp_v2.5.tar.gz > /dev/null 2>&1
tar zxvf wdcp_v2.5.tar.gz -C / > /dev/null 2>&1

in_finsh

Manage Tomcat Service Use Shell Script

Tomcat 项目管理交互式脚本.

  • Install pssh
  • Use Key Login Server Hosts
  • ~/.ssh/config 配置使用host名登录服务
  • 指定 Server Group Files 存放位置
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

#!/bin/bash

# Author Alex LU
# Date 2016-07-20
# Version 1.0

# HostFile
HostDIR=~/.ssh/host/

# war包上传到该目录
# /warfolder

:'
jobs_select (){
STRING=``cat $vmname | grep group
if [ -z "$STRING" ]
then
job_tomcat
else
job2_tomcat
fi
}
'

function HOST()
{
echo ""
echo "############ Host List ###############"
echo "ckgroup:ck01,ck02,ck03,ck04"
echo "sjgroup:sj01,sj02,sj03,sj04"
echo "ddgroup:dd01,dd02,dd03,dd04"
echo "htgroup:ht01,ht02"
echo "othergroup:report,tg"
echo "######################################"
echo ""
echo " Tips: 如果要选择ck01,则输入ck01即可,如果输入ck组,输入ckgroup即可,如果要退出当前脚本输入exit"
echo " Tips: 退回上一步请输入back"
read -p "请输入你的选择:" vmname

case "$vmname" in
ck01|ck02|ck03|ck04|sj01|sj02|sj03|sj04|dd01|dd02|dd03|dd04|report|tg|ht01|ht02)
job_tomcat $vmname
;;
ckgroup|sjgroup|htgroup|ddgroup|othergroup)
job2_tomcat $vmname
;;
exit)
exit 0;
;;
back)
clear
echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
main
;;
*)
echo "请输入的选择!"
HOST
;;
esac
}

function job_tomcat ()
{
echo ""
echo "############ 动作 ###############"
echo " 1. 查看当前tomcat7状态"
echo " 2. 关闭tomcat7"
echo " 3. 启动tomcat7"
echo " 4. 重启tomcat7"
echo " 5. 获取最近200行日志"
echo " 6. 重新选择主机"
echo " 7. 回到顶层目录"
echo ""
echo "#################################"

read -p "请输入你的选择:" service_tomcat

case $service_tomcat in
1)
pssh -H $vmname -i "ps aux | grep tomcat"
job_tomcat
;;
2)
pssh -H $vmname -i "service tomcat7 stop"
# tips: 下面grep的字符串要和你的tomcat项目名称契合
pssh -H $vmname -i "ps aux | grep tomcat7 | awk '{print $2}' | xargs kill -9 "
# tips: 下面用到的路径为绝对路径,请更改为自己tomcat的目录,也可以在前面增加自定义变量
pssh -H $vmname -i "rm -rf /tomcat7/work/*"
pssh -H $vmname -i "rm -rf /tomcat7/logs/*"
pssh -H $vmname -i "rm -rf /tomcat7/temp/*"
job_tomcat
;;
3)
pssh -H $vmname -i "service tomcat7 start"
job_tomcat
;;
4)
pssh -H $vmname -i "service tomcat7 stop"
# tips: 下面grep的字符串要和你的tomcat项目名称契合
pssh -H $vmname -i "ps aux | grep tomcat7 | awk '{print $2}' | xargs kill -9 "
# tips: 下面用到的路径为绝对路径,请更改为自己tomcat的目录,也可以在前面增加自定义变量
pssh -H $vmname -i "rm -rf /tomcat7/work/*"
pssh -H $vmname -i "rm -rf /tomcat7/logs/*"
pssh -H $vmname -i "rm -rf /tomcat7/temp/*"
sleep 1
pssh -H $vmname -i "service tomcat7 start"
job_tomcat
;;
5)
pssh -H $vmname -i "tail -n 200 /tomcat7/logs/catalina.out"
job_tomcat
;;
6)
echo ""
HOST
;;
7)
clear
echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
main
;;
*)
echo "请输入正确的选项!"
job_tomcat
;;
esac
}

function job2_tomcat ()
{
echo ""
echo "############ 动作 ###############"
echo " 1. 查看当前tomcat7状态"
echo " 2. 关闭tomcat7"
echo " 3. 启动tomcat7"
echo " 4. 重启tomcat7"
echo " 5. 获取最近200行日志"
echo " 6. 重新选择主机"
echo " 7. 回到顶层目录"
echo ""
echo "################################"

read -p "请输入你的选择:" service_tomcat

case $service_tomcat in
1)
pssh -h $HostDIR/$vmname -i "ps aux | grep tomcat"
job2_tomcat
;;
2)
pssh -h $HostDIR/$vmname -i "service tomcat7 stop"
# tips: 下面grep的字符串要和你的tomcat项目名称契合
pssh -h $HostDIR/$vmname -i "ps aux | grep tomcat7 | awk '{print $2}' | xargs kill -9 "
# tips: 下面用到的路径为绝对路径,请更改为自己tomcat的目录,也可以在前面增加自定义变量
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/work/*"
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/logs/*"
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/temp/*"
job2_tomcat
;;
3)
pssh -h $HostDIR/$vmname -i "service tomcat7 start"
job2_tomcat
;;
4)
pssh -h $HostDIR/$vmname -i "service tomcat7 stop"
# tips: 下面grep的字符串要和你的tomcat项目名称契合
pssh -h $HostDIR/$vmname -i "ps aux | grep tomcat7 | awk '{print $2}' | xargs kill -9 "
# tips: 下面用到的路径为绝对路径,请更改为自己tomcat的目录,也可以在前面增加自定义变量
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/work/*"
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/logs/*"
pssh -h $HostDIR/$vmname -i "rm -rf /tomcat7/temp/*"
sleep 1
pssh -h $HostDIR/$vmname -i "service tomcat7 start"
job2_tomcat
;;
5)
pssh -h $HostDIR/$vmname -i "tail -n 200 /tomcat7/logs/catalina.out"
job2_tomcat
;;
6)
echo ""
HOST
;;
7)
clear
echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
main
;;
*)
echo "请输入正确的选项!"
job_tomcat
;;
esac
}

function HOST2()
{
echo ""
echo "############ Host List ###############"
echo "ckgroup:ck01,ck02,ck03,ck04"
echo "sjgroup:sj01,sj02,sj03,sj04"
echo "ddgroup:dd01,dd02,dd03,dd04"
echo "htgroup:ht01,ht02"
echo "othergroup:report,tg"
echo "######################################"
echo ""
# 确认是否所有项目包发布后立即启动
echo -e "\033[7m 更新订单服务器的war包时,会自动启动tomcat程序,为了释放war包,修改order.no,请设置war包内order.no=0 ,其它服务器tomcat不会自启动,请使用命令操作 \033[0m"
echo " Tips: 如果要选择ck01,则输入ck01即可,如果输入ck组,输入ckgroup即可,如果要退出当前脚本输入exit"
echo " Tips: 退回上一步请输入back"
read -p "请输入你的选择:" vmname
case "$vmname" in
ck01|ck02|ck03|ck04|sj01|sj02|sj03|sj04|dd01|dd02|dd03|dd04|report|tg|ht01|ht02)
read -p "请输入war包的名称,例如:dzcx_ck.war :" warname
pscp_tomcat $vmname $warname
;;
ckgroup|sjgroup|htgroup|othergroup)
read -p "请输入war包的名称,例如:dzcx_ck.war :" warname
pscp2_tomcat $vmname $warname
;;
ddgroup)
read -p "请输入war包的名称,例如:dzcx_ck.war :" warname
pscp3_tomcat $vmname $warname
;;
exit)
exit 0;
;;
back)
clear
echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
main
;;
*)
echo "请输入的选择!"
HOST
;;
esac
}

function pscp_tomcat ()
{
# single host
pscp.pssh -H $vmname /warfolder/"$warname" /tomcat7/webapps/
HOST2
}

function pscp2_tomcat ()
{
# group
pscp.pssh -h $HostDIR/$vmname /warfolder/"$warname" /tomcat7/webapps/
HOST2
}

function pscp3_tomcat ()
{
# group dd 因为订单需要修改服务器编号
pscp.pssh -h $HostDIR/$vmname /warfolder/"$warname" /tomcat7/webapps/
pssh -h $vmname -i "service tomcat7 start"
sleep 10
pssh -H dd02 "sed -i 's/order.no=0/order.no=1/g' /tomcat7/webapps/dzcx_socket/WEB-INF/classes/base.properties"
pssh -H dd03 "sed -i 's/order.no=0/order.no=2/g' /tomcat7/webapps/dzcx_socket/WEB-INF/classes/base.properties"
pssh -H dd04 "sed -i 's/order.no=0/order.no=3/g' /tomcat7/webapps/dzcx_socket/WEB-INF/classes/base.properties"
HOST2
}

function main ()
{
echo ""
echo "######################################"
echo ""
echo "# 1. 更新war包"
echo "# 2. 管理tomcat7"
echo "# 3. 管理mysql"
echo "# 4. 管理redis"
echo "# 5. 同步服务器时间"
echo "# 6. 清理当前屏幕"
echo "# 7. 退出"
echo ""
echo "######################################"

read -p "请输入你的选择:" num

case "$num" in
1)
HOST2
;;
2)
HOST
;;
3)
echo "该功能暂未开放"
;;
4)
echo "该功能暂未开放"
;;
5)
pssh -h $HostDIR/allhost -i "service ntpd restart"
;;
6)
clear
echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
main
;;
7)
exit 0
;;
*)
echo "请输入正确的数值!"
main
;;
esac

}

# --------------------------------- main -------------------------------------------------

clear

echo ""
echo "Tips: 欢迎使用Tomcat项目服务管理工具,您需要预先安装pssh工具,以及配置好ssh免密登录到服务器"
command -v pssh > /dev/null 2>&1

if [ $? -eq 0 ]
then
main
else
echo -e "\033[07m"
echo -e "系统检测到您还没安装pssh,请预先安装pssh"
echo "yum install -y epel-release"
echo "yum install -y pssh"
echo "安装成功请重新运行此脚本"
echo -e "\033[0m"

fi
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×