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-libs unixODBC 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-devel net-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-1.el7.noarch.rpm
if [ $? -ne 0 ];then
echo "zabbix-release err"
exit
fi
fi
yum -y install wget zabbix-server-mysql zabbix-web-mysql zabbix-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 restart mysql.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/ ... dEmail-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
|