LNMP+Nagios server一键安装脚本

释放双眼,带上耳机,听听看~!

以下是LNMP+Nagios Server端的安装脚本,脚本预计需要执行半小时,当脚本执行完毕后你的基于LNMP的Nagios Server端就装好啦

 

下面是效果图:

 

下面是脚本代码:(
写的不太好,求大神们指点)


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
1#!/bin/bash
2#date:2015-5-27
3#author:yfshare
4#mail:838554604@qq.com
5echo ''
6echo -e "\t###########################################################"
7echo -e "\t###\t\t\t\t\t\t\t###"
8echo -e "\t###\twelcome to use Nagios&Nginx Install Scripts\t###"
9echo -e "\t###\tRequirement:\t\t\t\t\t###"
10echo -e "\t###\tSystem:\t\tCentOS 6.x\t\t\t###"
11echo -e "\t###\tprocessor:\tx86_64\t\t\t\t###"
12echo -e "\t###\t\t\t\t\t\t\t###"
13echo -e "\t###########################################################"
14function check_service() {
15network=`netstat -tunlp |grep ${1} |wc -l`
16Process=`ps -ef|grep ${1}|grep -v grep|wc -l`
17while true
18do
19  if [ ${network} -ge 1 ] || [ ${Process} -ge 1 ];then
20      echo -e "${1} started successfully"
21      break
22  else
23      echo -e "${1} failed to start"
24      /bin/sh $2
25      sleep 2
26  fi
27done
28}
29function Content() {
30echo ''
31read -p 'please input software path:' path
32mkdir ${path}/log
33log="${path}/log/install.log"
34echo ''
35echo -e 'Please input the password for user admin:'
36yum -y install httpd-tools >>${log} 2>&1
37declare -i count=3
38while true
39do
40  htpasswd -cm $path/conf/htpasswd.users admin
41  result=`echo $?`
42  ((--count))
43  if [[ $result != 0 ]];then
44          if [[ $count -ge 1 ]];then
45                  echo ''
46          else
47          exit 1
48          fi
49  else
50          break
51  fi
52done
53cd $path
54yum -y install gcc gcc-c++ perl perl-devel mysql mysql-devel libxml2 libxml2-devel unzip >>${log} 2>&1
55#install php
56tar -zxvf zlib-1.2.7.tar.gz -C $path >>${log} 2>&1
57cd $path/`tar -zxvf ${path}/zlib-1.2.7.tar.gz|head -n 1|awk -F/ '{print $1}'`
58./configure -prefix=/usr/local/zlib >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
59tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz -C $path >>${log} 2>&1
60cd $path/`tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz|head -n 1|awk -F/ '{print $1}'`
61./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
62useradd -s /sbin/nologin www >>${log} 2>&1
63groupadd nagcmd &&useradd -G nagcmd nagios &&usermod -G nagcmd www
64tar -jxvf $path/php-5.3.8.tar.bz2 -C $path >>${log} 2>&1
65yum install libpng.x86_64 freetype.x86_64 libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y >>${log} 2>&1
66cd $path/`tar -jxvf ${path}/php-5.3.8.tar.bz2|head -n 1|awk -F/ '{print $1}'`
67./configure --prefix=/usr/local/php --enable-mbstring --enable-soap --enable-wddx=shared --enable-xml --with-gd --with-gettext --with-regex=system --with-zlib-dir=/usr/local/zlib --enable-fpm --with-jpeg-dir --with-fpm-user=www --with-fpm-group=www --enable-shmop --with-mcrypt --with-mysqli=mysqlnd >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
68cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
69sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf
70sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
71sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
72sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
73/usr/local/php/sbin/php-fpm
74echo '/usr/local/php/sbin/php-fpm'>>/etc/rc.local
75check_service php "/usr/local/php/sbin/php-fpm"
76#install nginx
77tar -jxvf ${path}/pcre-8.12.tar.bz2 -C ${path} >>${log} 2>&1
78cd ${path}/`tar -jxvf ${path}/pcre-8.12.tar.bz2|head -n 1|awk -F/ '{print $1}'`
79./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
80tar -zxvf $path/openssl-1.0.1c.tar.gz -C $path >>${log} 2>&1
81cd $path/`tar -zxvf $path/openssl-1.0.1c.tar.gz|head -n 1|awk -F/ '{print $1}'`
82./config >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
83tar -zxvf $path/nginx-1.6.2.tar.gz -C $path >>${log} 2>&1
84cd $path/`tar -zxvf $path/nginx-1.6.2.tar.gz|head -n 1|awk -F/ '{print $1}'`
85./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=${path}/pcre-8.12 --with-zlib=${path}/zlib-1.2.7 --with-openssl=${path}/openssl-1.0.1c --with-http_stub_status_module >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
86cp $path/conf/etc_init.d_nginx /etc/init.d/nginx >>${log} 2>&1
87chown www:www /usr/local/nginx -R
88chmod 775 /etc/init.d/nginx &&/etc/init.d/nginx start >>${log} 2>&1
89chkconfig --add nginx && chkconfig nginx on
90check_service nginx "/etc/init.d/nginx start"
91cat $path/conf/nginx.conf >/usr/local/nginx/conf/nginx.conf
92cat $path/conf/fastcgi.conf >/usr/local/nginx/conf/fastcgi.conf
93cat $path/conf/fcgi.conf >/usr/local/nginx/conf/fcgi.conf
94cat $path/conf/start_perl_cgi.sh > /usr/local/nginx/start_perl_cgi.sh
95chmod 775 /usr/local/nginx/start_perl_cgi.sh
96#install FCGI
97tar -zxvf $path/FCGI-0.73.tar.gz -C $path >>${log} 2>&1
98cd $path/`tar -zxvf $path/FCGI-0.73.tar.gz|head -n 1|awk -F/ '{print $1}'`
99perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
100tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz -C $path >>${log} 2>&1
101cd $path/`tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz|head -n 1|awk -F/ '{print $1}'`
102perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
103tar -zxvf $path/IO-1.25.tar.gz -C $path >>${log} 2>&1
104cd $path/`tar -zxvf $path/IO-1.25.tar.gz|head -n 1|awk -F/ '{print $1}'`
105perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
106tar -zxvf $path/IO-All-0.39.tar.gz -C $path >>${log} 2>&1
107cd $path/`tar -zxvf $path/IO-All-0.39.tar.gz|head -n 1|awk -F/ '{print $1}'`
108perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
109tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz -C $path >>${log} 2>&1
110cd $path/`tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz|head -n 1|awk -F/ '{print $1}'`
111./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
112cd $path &&unzip $path/perl-fcgi.zip >>${log} 2>&1
113cp $path/perl-fcgi.pl /usr/local/nginx/
114chmod 755 /usr/local/nginx/perl-fcgi.pl
115/usr/local/nginx/start_perl_cgi.sh start
116echo "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.local
117IP=`ls /usr/local/nginx/logs/|grep "perl-fcgi.sock"|wc -l`
118while true
119do
120 if [ ${IP} -eq 1 ];then
121     echo -e 'start perl-fcgi done'
122     break
123 else
124     echo -e 'perl-fcgi failed to start'
125     /usr/local/nginx/start_perl_cgi.sh start
126 fi
127done
128#install Nagios
129yum -y install php-gd >>${log} 2>&1
130tar -zxvf $path/nagios-3.3.1.tar.gz -C $path >>${log} 2>&1
131cd $path/`tar -zxvf $path/nagios-3.3.1.tar.gz|head -n 1|awk -F/ '{print $1}'`
132./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include >>${log} 2>&1 &&make all >>${log} 2>&1 &&make install >>${log} 2>&1 &&make install-init >>${log} 2>&1 &&make install-config >>${log} 2>&1 &&make install-commandmode >>${log} 2>&1
133sed -i '/authorized\_for\_/s/nagiosadmin/&\,admin/g' /usr/local/nagios/etc/cgi.cfg
134mv $path/conf/htpasswd.users /usr/local/nagios/etc/
135mkdir /usr/local/nagios/logs -p
136sed -i '/use_authentication/s/1/0/g' /usr/local/nagios/etc/cgi.cfg
137sed -i '/requiretty$/s/^Defaults/#&/g' /etc/sudoers
138chown nagios:nagcmd /usr/local/nagios -R
139chkconfig --add nagios &&chkconfig nagios on
140/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total
141/etc/init.d/nagios start
142check_service nagios "/etc/init.d/nagios start"
143#install Nagios-plugin
144tar -zxvf $path/nagios-plugins-1.4.15.tar.gz -C $path >>${log} 2>&1
145cd $path/`tar -zxvf $path/nagios-plugins-1.4.15.tar.gz|head -n 1|awk -F/ '{print $1}'`
146./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules >>${log} 2>&1
147make >>${log} 2>&1 &&make install >>${log} 2>&1
148libexec=`ls /usr/local/nagios/libexec/|wc -l`
149echo -e "nagios/libexec:${libexec}"
150#install NRPE
151yum -y install openssl-devel >>${log} 2>&1
152tar -zxvf ${path}/nrpe-2.13.tar.gz -C $path >>${log} 2>&1
153cd $path/`tar -zxvf ${path}/nrpe-2.13.tar.gz|head -n 1|awk -F/ '{print $1}'`
154./configure >>${log} 2>&1 &&make all >>${log} 2>&1 &&make install-plugin >>${log} 2>&1 &&make install-daemon >>${log} 2>&1 &&make install-daemon-config >>${log} 2>&1
155e=`ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'`
156sed -i "/allowed_host/s/127.0.0.1/&,${e}/g" /usr/local/nagios/etc/nrpe.cfg
157echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
158chown nagios:nagcmd /usr/local/nagios -R
159ln -s /usr/local/nagios/share /usr/local/nginx/html/nagios
160/usr/local/nagios/libexec/check_nrpe -H localhost >>${log} 2>&1
161sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptables
162sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 5666 \-j ACCEPT' /etc/sysconfig/iptables
163sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 9000 \-j ACCEPT' /etc/sysconfig/iptables
164sed -i '/WorldWideWeb/s/http/#&/g' /etc/services
165sed -i '/HyperText/s/http/#&/g' /etc/services
166sed -i '/cslistener/s/cslistener/#&/g' /etc/services
167sed -i "/WorldWideWeb/anginx\t 80\/tcp\nnginx\t80\/udp\nnginx\t80\/sctp" /etc/services
168sed -i "9770 a php\-fpm\t9000\/tcp\nphp\-fpm\t9000\/udp" /etc/services
169sed -i "/sfm-db-server/anrpe\t5666\/tcp\nnrpe\t5666\/udp" /etc/services
170/etc/init.d/iptables restart >>${log} 2>&1 &&chkconfig iptables on
171/etc/init.d/nagios restart
172echo -e ''
173/etc/init.d/nginx reload
174echo ''
175echo "Script installation log in ${path}/log/install.log"
176}
177#
178ret_code=`curl -I -s --connect-timeout 15 www.baidu.com -w %{http_code}|tail -n 1`
179System=`cat /proc/version |grep -io Centos`
180ID=`cat /proc/version |awk -F'(' '{print $1}'`
181processor=`uname -p`
182if [[ ${ret_code} != '200' ]];then
183 echo ''
184 echo -e "\033[31;49;1m[Error]Network exception, please try again\033[39;49;0m"
185 exit 1
186else
187 if [[ ${System} != 'centos' ]] || [[ ${processor} != 'x86_64' ]];then
188echo 'Warn message:'
189echo -e "The current operation system:${ID} is not in the system support list\nSystem environment check fails, it may affect the program to run"
190read -p "Ignored the warning messages [Y/N]?  " key
191     if [[ ${key} != [Yy] ]];then
192         echo -e "\033[31;49;1mThanks for using\033[39;49;0m"
193         echo ''
194     else
195         echo ''
196         echo -e "\033[31;49;1mStart install...\033[39;49;0m"
197         Content
198         exit 1
199     fi
200 else
201     echo ''
202     echo -e "\033[31;49;1mStart install...\033[39;49;0m"
203     Content
204     exit 1
205 fi
206fi
207

 

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

详解Node.js API系列 Http模块(1) 构造一个简单的静态页服务器

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索