设为首页 收藏本站
查看: 2320|回复: 1

[经验分享] centos 快速搭建lnmp、lamp+zabbix3.2监控系统

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-1 09:12:18 | 显示全部楼层 |阅读模式
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-libs  unixODBC 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-devel  net-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-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/nginx/nginx.conf << EOF
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '\$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.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
EOF

cat > /etc/nginx/conf.d/default.conf  << EOF
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/zabbix;
            index  index.php index.html index.htm;
        }

        #error_page  404              /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_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~* ^.+\.(jpg|jpeg|gif|png|bmp)$ {
            access_log  off;
            root        opencart;
            expires     30d;
                        break;
        }
}
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 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-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



使用方法:
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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-307993-1-1.html 上篇帖子: 演示 zabbix LLD(Low-Level Discovery) 如何使用 下篇帖子: zabbix怎么监控多组数据 监控系统
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表