一键部署nginx
|
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
|
#!/bin/bashsystemctl stop firewalld && setenforce 0#首先安装nginx的依赖环境yum -y install gcc pcre-devel zlib-devel net-tools wget#解压nginx的安装包if [ ! -d "/root/nginx-1.16.1" ]; then wget http://nginx.org/download/nginx-1.16.1.tar.gz tar -zxf nginx-1.16.1.tar.gz echo "压缩包已解压"else echo "此文件已存在" continuefi#进去文件开始检查环境 编译安装if [ ! -d /usr/local/nginx ]; then cd /root/nginx-1.16.1 && ./configure && make && make installelse continuefi#判断是否nginx的端口被占用pid_file="/usr/local/nginx/logs/nginx.pid"if [ ! -e ${pid_file} ]; then echo "被占用的pid是:`cat ${pid_file}`" kill `cat ${pid_file}` echo "服务被占用,已删掉"else echo "服务没有被占用" continuefinginx=/usr/local/nginx/sbin/nginx#开始启动nginxread -p "请输入你接下来要做的操作:" actioncheck(){ netstat -anptu | grep nginx if [ $? -eq 0 ];then continue fi}case $action in start) netstat -anptu | grep nginx if [ $? -eq 0 ]; then continue else $nginx fi ;; stop) netstat -anptu | grep nginx if [ $? -eq 0 ]; then echo "nginx-server is already running nginx-server begin stop" $nginx -s stop else echo "nginx-server is not start" fi ;; reload) netstat -anptu | grep nginx if [ $? -eq 0 ]; then echo "nginx-server is already running nginx-server begin reload" $nginx -s reload else echo "nginx-server is not running now begin start nginx-server" $nginx $nginx -s reload fi ;; statue) check ;; *) echo "please enter{start|stop|reload|statue}" ;;esacip=`/sbin/ifconfig -a|awk '{print $2}'|sed -n '2p'`code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://${ip}`if [ $code -eq 200 ]; then echo "nginx-server is ok"else echo "nginx-server is not ok"fi |