centos 快速搭建lnmp、lamp+zabbix3.2监控系统
centos 快速搭建lnmp、lamp+zabbix3.2监控系统所安装版本mysql 5.6 php5.5 zabbix3.2
centos7 lnmp+zabbix3.2 脚本
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
#!/bin/bash
if [ $(rpm -qi mysql-community-release-el7-5.noarch | wc -l) -lt 2 ];then
rpm -Uvh http://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
if [ $? -ne 0];then
echo "mysql-release err"
exit
fi
fi
yum install -y epel-release
if [ $? -ne 0];then
echo "epel-release err"
exit
fi
if [ $(rpm -qi webtatic-release-7-3.noarch | wc -l) -lt 2 ];then
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if [ $? -ne 0];then
echo "webtatic-release err"
exit
fi
fi
yum -y install openssl OpenIPMI-libsunixODBC libaio iksemel fping net-snmp net-snmp-utils mysql mysql-server mysql-devel php55w php55w-gd php55w-xml php55w-mysql php55w-mbstring php55w-bcmath perl-DBI curl libcurl-develnet-snmp-devel libssh2 libssh2-devel libxml2 libxml2-devel php55w-fpm nginx
if [ $? -ne 0];then
echo "yum install err"
exit
fi
if [ $(rpm -qi zabbix-release-3.2-1.el7.noarch | wc -l) -lt 2 ];then
rpm -Uvh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if [ $? -ne 0];then
echo "zabbix-release err"
exit
fi
fi
yum -y install wget zabbix-server-mysql zabbix-web-mysqlzabbix-agent zabbix-get zabbix-sender
if [ $? -ne 0];then
echo "zabbix install err"
exit
fi
cat >> /etc/php.ini << EOF
soap.wsdl_cache_enabled=1
max_input_time = 600
max_execution_time = 300
date.timezone = Asia/Shanghai
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 1
EOF
sed -i "/symbolic-links=0/a\character_set_server = utf8" /etc/my.cnf
cat > /etc/nginx/nginx.conf << EOF
usernginx;
worker_processes1;
error_log/var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections1024;
}
http {
include /etc/nginx/mime.types;
default_typeapplication/octet-stream;
log_formatmain'\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log/var/log/nginx/access.logmain;
sendfile on;
#tcp_nopush on;
keepalive_timeout65;
#gzipon;
include /etc/nginx/conf.d/*.conf;
}
EOF
cat > /etc/nginx/conf.d/default.conf<< EOF
server {
listen 80;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
root /usr/share/zabbix;
indexindex.php index.html index.htm;
}
#error_page404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504/50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME\$document_root\$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^.+\.(jpg|jpeg|gif|png|bmp)$ {
access_logoff;
root opencart;
expires 30d;
break;
}
}
EOF
/bin/systemctl restartmysql.service
echo "create database zabbix character set utf8;" | mysql
echo "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';" | mysql
echo "grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';" |mysql
cat >>/etc/services <<EOF
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF
sed -i 's/^DBUser=.*$/DBUser=zabbix/g' /etc/zabbix/zabbix_server.conf
sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
cd /usr/share/doc/zabbix-server-mysql-3.2.1
zcat create.sql.gz | mysql -uroot zabbix
cd /tmp
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if [ $? -ne 0];then
echo "wget sendEmail err"
exit
fi
tar xvzf sendEmail-v1.56.tar.gz
cp sendEmail-v1.56/sendEmail /usr/local/bin/
chmod +x /usr/local/bin/sendEmail
chown -R zabbix.zabbix/usr/lib/zabbix/alertscripts
cat > /usr/lib/zabbix/alertscripts/SendEmail.sh << EOF
#!/bin/bash
LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec 1>"\$LOGFILE"
exec 2>&1
SMTP_server='$1' # SMTP服务器
username='$2' # 用户名
password='$3' # 密码
from_email_address='$4' # 发件人Email地址
to_email_address="\$1" # 收件人Email地址,zabbix传入的第一个参数
message_subject_utf8="\$2" # 邮件标题,zabbix传入的第二个参数
message_body_utf8="\$3" # 邮件内容,zabbix传入的第三个参数
# 转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。
message_subject_gb2312=\`iconv -t GB2312 -f UTF-8 << EOF
\$message_subject_utf8
EOF\`
[ \$? -eq 0 ] && message_subject="\$message_subject_gb2312" || message_subject="\$message_subject_utf8"
# 转换邮件内容为GB2312
message_body_gb2312=\`iconv -t GB2312 -f UTF-8 << EOF
\$message_body_utf8
EOF\`
[ \$? -eq 0 ] && message_body="\$message_body_gb2312" || message_body="\$message_body_utf8"
# 发送邮件
sendEmail='/usr/local/bin/sendEmail'
set -x
\$sendEmail -s "\$SMTP_server" -xu "\$username" -xp "\$password" -f "\$from_email_address" -t "\$to_email_address" -u "\$message_subject" -m "\$message_body" -o message-content-type=text -o message-charset=gb2312
EOF
chmod +x /usr/lib/zabbix/alertscripts/SendEmail.sh
cd /usr/share/zabbix/fonts
mv graphfont.ttf graphfont.ttf.back
wget http://qkadownload.qkagame.com/msyh.ttf
if [ $? -ne 0];then
echo "wget msyh err"
exit
fi
mv msyh.ttf graphfont.ttf
chmod 777 graphfont.ttf
systemctl start zabbix-server
systemctl start nginx.service
systemctl start php-fpm.service
systemctl start zabbix-agent
systemctl enable zabbix-server.service
systemctl enable zabbix-agent.service
systemctl enable nginx.service
systemctl enable php-fpm.service
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --reload
centos7 lamp+zabbix3.2 脚本
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
#/bin/bash
if [ $(rpm -qi mysql-community-release-el7-5.noarch | wc -l) -lt 2 ];then
rpm -Uvh http://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
if [ $? -ne 0];then
echo "mysql-release err"
exit
fi
fi
yum install -y epel-release
if [ $? -ne 0];then
echo "epel-release err"
exit
fi
if [ $(rpm -qi webtatic-release-7-3.noarch | wc -l) -lt 2 ];then
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if [ $? -ne 0];then
echo "webtatic-release err"
exit
fi
fi
yum -y install openssl OpenIPMI-libsunixODBC libaio iksemel fping net-snmp net-snmp-utils httpd mysql mysql-server mysql-devel php55w php55w-gd php55w-xml php55w-mysql php55w-mbstring php55w-bcmath perl-DBI curl libcurl-develnet-snmp-devel libssh2 libssh2-devel libxml2 libxml2-devel
if [ $? -ne 0];then
echo "yum install err"
exit
fi
if [ $(rpm -qi zabbix-release-3.2-1.el7.noarch | wc -l) -lt 2 ];then
rpm -Uvh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if [ $? -ne 0];then
echo "zabbix-release err"
exit
fi
fi
yum -y install wget zabbix-server-mysql zabbix-web-mysqlzabbix-agent zabbix-get zabbix-sender
if [ $? -ne 0];then
echo "zabbix-install err"
exit
fi
cat >> /etc/php.ini << EOF
soap.wsdl_cache_enabled=1
max_input_time = 600
max_execution_time = 300
date.timezone = Asia/Shanghai
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 1
EOF
sed -i "/symbolic-links=0/a\character_set_server = utf8" /etc/my.cnf
cat >> /etc/httpd/conf.d/zabbix.conf << EOF
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/usr/share/zabbix/conf">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/api">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include/classes">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
EOF
/bin/systemctl restartmysql.service
echo "create database zabbix character set utf8;" | mysql
echo "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';" | mysql
echo "grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';" |mysql
cat >>/etc/services <<EOF
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper
EOF
sed -i 's/^DBUser=.*$/DBUser=zabbix/g' /etc/zabbix/zabbix_server.conf
sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
cd /usr/share/doc/zabbix-server-mysql-3.2.1
zcat create.sql.gz | mysql -uroot zabbix
cd /tmp
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if [ $? -ne 0];then
echo "wget sendEmail err"
exit
fi
tar xvzf sendEmail-v1.56.tar.gz
cp sendEmail-v1.56/sendEmail /usr/local/bin/
chmod +x /usr/local/bin/sendEmail
chown -R zabbix.zabbix/usr/lib/zabbix/alertscripts
cat > /usr/lib/zabbix/alertscripts/SendEmail.sh << EOF
#!/bin/bash
LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec 1>"\$LOGFILE"
exec 2>&1
SMTP_server='$1' # SMTP服务器
username='$2' # 用户名
password='$3' # 密码
from_email_address='$4' # 发件人Email地址
to_email_address="\$1" # 收件人Email地址,zabbix传入的第一个参数
message_subject_utf8="\$2" # 邮件标题,zabbix传入的第二个参数
message_body_utf8="\$3" # 邮件内容,zabbix传入的第三个参数
# 转换邮件标题为GB2312,解决邮件标题含有中文,收到邮件显示乱码的问题。
message_subject_gb2312=\`iconv -t GB2312 -f UTF-8 << EOF
\$message_subject_utf8
EOF\`
[ \$? -eq 0 ] && message_subject="\$message_subject_gb2312" || message_subject="\$message_subject_utf8"
# 转换邮件内容为GB2312
message_body_gb2312=\`iconv -t GB2312 -f UTF-8 << EOF
\$message_body_utf8
EOF\`
[ \$? -eq 0 ] && message_body="\$message_body_gb2312" || message_body="\$message_body_utf8"
# 发送邮件
sendEmail='/usr/local/bin/sendEmail'
set -x
\$sendEmail -s "\$SMTP_server" -xu "\$username" -xp "\$password" -f "\$from_email_address" -t "\$to_email_address" -u "\$message_subject" -m "\$message_body" -o message-content-type=text -o message-charset=gb2312
EOF
chmod +x /usr/lib/zabbix/alertscripts/SendEmail.sh
cd /usr/share/zabbix/fonts
mv graphfont.ttf graphfont.ttf.back
wget http://qkadownload.qkagame.com/msyh.ttf
if [ $? -ne 0];then
echo "wget msyh err"
exit
fi
mv msyh.ttf graphfont.ttf
chmod 777 graphfont.ttf
systemctl start zabbix-server
systemctl start httpd
systemctl start zabbix-agent
systemctl enable zabbix-server.service
systemctl enable zabbix-agent.service
systemctl enable httpd.service
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --reload
使用方法:
1
2
3
4
5
6
给脚本可执行权限chmod +x 脚本文件
数据默认用户名密码zabbix 发邮件脚本名字:SendEmail.sh 登陆zabbix web账号密码 admin:zabbix
./zabbix_lamp.sh smtp.test.com admin 123456 admin@test.com
./zabbix_lnmp.sh smtp.test.com admin 123456 admin@test.com
lnmp+zabbix 访问 lamp+zabbix 访问 http://ip/zabbix
centos6 脚本名字zabbix_lamp_6.sh zabbix_lnmp_6.sh
zabbix web配置以lamp+zabbix 为实例:
顶顶顶
页:
[1]