centos 快速搭建lnmp、lamp+zabbix3.2监控系统

前端之家收集整理的这篇文章主要介绍了centos 快速搭建lnmp、lamp+zabbix3.2监控系统前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

centos 快速搭建lnmp、lamp+zabbix3.2监控系统

所安装版本MysqL 5.6 PHP5.5 zabbix3.2

centos7 lnmp+zabbix3.2 脚本

#!/bin/bash
if[$(rpm-qiMysqL-community-release-el7-5.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.MysqL.com//MysqL-community-release-el7-5.noarch.rpm
if[$?-ne0];then
echo"MysqL-releaseerr"
exit
fi
fi
yuminstall-yepel-release
if[$?-ne0];then
echo"epel-releaseerr"
exit
fi
if[$(rpm-qiwebtatic-release-7-3.noarch|wc-l)-lt2];then
rpm-ivhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if[$?-ne0];then
echo"webtatic-releaseerr"
exit
fi
fi
yum-yinstallopensslOpenIPMI-libsunixODBClibaioiksemelfpingnet-snmpnet-snmp-utilsMysqLMysqL-serverMysqL-develPHP55wPHP55w-gdPHP55w-xmlPHP55w-MysqLPHP55w-mbstringPHP55w-bcmathperl-DBIcurllibcurl-develnet-snmp-devellibssh2libssh2-devellibxml2libxml2-develPHP55w-fpmNginx
if[$?-ne0];then
echo"yuminstallerr"
exit
fi
if[$(rpm-qizabbix-release-3.2-1.el7.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if[$?-ne0];then
echo"zabbix-releaseerr"
exit
fi
fi
yum-yinstallwgetzabbix-server-MysqLzabbix-web-MysqLzabbix-agentzabbix-getzabbix-sender
if[$?-ne0];then
echo"zabbixinstallerr"
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.logwarn;
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;

sendfileon;
#tcp_nopushon;

keepalive_timeout65;

#gzipon;

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

cat>/etc/Nginx/conf.d/default.conf<<EOF
server{
listen80;
server_namelocalhost;

#charsetkoi8-r;

#access_loglogs/host.access.logmain;

location/{
root/usr/share/zabbix;
indexindex.PHPindex.htmlindex.htm;
}

#error_page404/404.html;

#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
roothtml;
}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.PHP${
#proxy_passhttp://127.0.0.1;
#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.PHP${
root/usr/share/zabbix;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME\$document_root\$fastcgi_script_name;
includefastcgi_params;
}
location~*^.+\.(jpg|jpeg|gif|png|bmp)${
access_logoff;
rootopencart;
expires30d;
break;
}
}
EOF
/bin/systemctlrestartMysqL.service
echo"createdatabasezabbixcharactersetutf8;"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@localhostidentifiedby'zabbix';"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@'%'identifiedby'zabbix';"|MysqL
cat>>/etc/services<<EOF
zabbix-agent10050/tcpZabbixAgent
zabbix-agent10050/udpZabbixAgent
zabbix-trapper10051/tcpZabbixTrapper
zabbix-trapper10051/udpZabbixTrapper
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
zcatcreate.sql.gz|MysqL-urootzabbix
cd/tmp
wgethttp://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if[$?-ne0];then
echo"wgetsendEmailerr"
exit
fi
tarxvzfsendEmail-v1.56.tar.gz
cpsendEmail-v1.56/sendEmail/usr/local/bin/
chmod+x/usr/local/bin/sendEmail
chown-Rzabbix.zabbix/usr/lib/zabbix/alertscripts
cat>/usr/lib/zabbix/alertscripts/SendEmail.sh<<EOF
#!/bin/bash

LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec1>"\$LOGFILE"
exec2>&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-tGB2312-fUTF-8<<EOF
\$message_subject_utf8
EOF\`
[\$?-eq0]&&message_subject="\$message_subject_gb2312"||message_subject="\$message_subject_utf8"

#转换邮件内容为GB2312
message_body_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_body_utf8
EOF\`
[\$?-eq0]&&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"-omessage-content-type=text-omessage-charset=gb2312
EOF
chmod+x/usr/lib/zabbix/alertscripts/SendEmail.sh
cd/usr/share/zabbix/fonts
mvgraphfont.ttfgraphfont.ttf.back
wgethttp://qkadownload.qkagame.com/msyh.ttf
if[$?-ne0];then
echo"wgetmsyherr"
exit
fi
mvmsyh.ttfgraphfont.ttf
chmod777graphfont.ttf
systemctlstartzabbix-server
systemctlstartNginx.service
systemctlstartPHP-fpm.service
systemctlstartzabbix-agent
systemctlenablezabbix-server.service
systemctlenablezabbix-agent.service
systemctlenableNginx.service
systemctlenablePHP-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 脚本

#/bin/bash
if[$(rpm-qiMysqL-community-release-el7-5.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.MysqL.com//MysqL-community-release-el7-5.noarch.rpm
if[$?-ne0];then
echo"MysqL-releaseerr"
exit
fi
fi
yuminstall-yepel-release
if[$?-ne0];then
echo"epel-releaseerr"
exit
fi
if[$(rpm-qiwebtatic-release-7-3.noarch|wc-l)-lt2];then
rpm-ivhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
if[$?-ne0];then
echo"webtatic-releaseerr"
exit
fi
fi
yum-yinstallopensslOpenIPMI-libsunixODBClibaioiksemelfpingnet-snmpnet-snmp-utilshttpdMysqLMysqL-serverMysqL-develPHP55wPHP55w-gdPHP55w-xmlPHP55w-MysqLPHP55w-mbstringPHP55w-bcmathperl-DBIcurllibcurl-develnet-snmp-devellibssh2libssh2-devellibxml2libxml2-devel
if[$?-ne0];then
echo"yuminstallerr"
exit
fi
if[$(rpm-qizabbix-release-3.2-1.el7.noarch|wc-l)-lt2];then
rpm-Uvhhttp://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
if[$?-ne0];then
echo"zabbix-releaseerr"
exit
fi
fi
yum-yinstallwgetzabbix-server-MysqLzabbix-web-MysqLzabbix-agentzabbix-getzabbix-sender
if[$?-ne0];then
echo"zabbix-installerr"
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
#ZabbixmonitoringsystemPHPwebfrontend
#

Alias/zabbix/usr/share/zabbix

<Directory"/usr/share/zabbix">
OptionsFollowSymLinks
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>

<Directory"/usr/share/zabbix/conf">
Orderdeny,allow
Denyfromall
<files*.PHP>
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/api">
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/include">
Orderdeny,allow
Denyfromall
</files>
</Directory>

<Directory"/usr/share/zabbix/include/classes">
Orderdeny,allow
Denyfromall
</files>
</Directory>
EOF
/bin/systemctlrestartMysqL.service
echo"createdatabasezabbixcharactersetutf8;"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@localhostidentifiedby'zabbix';"|MysqL
echo"grantallprivilegesonzabbix.*tozabbix@'%'identifiedby'zabbix';"|MysqL
cat>>/etc/services<<EOF
zabbix-agent10050/tcpZabbixAgent
zabbix-agent10050/udpZabbixAgent
zabbix-trapper10051/tcpZabbixTrapper
zabbix-trapper10051/udpZabbixTrapper
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
zcatcreate.sql.gz|MysqL-urootzabbix
cd/tmp
wgethttp://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
if[$?-ne0];then
echo"wgetsendEmailerr"
exit
fi
tarxvzfsendEmail-v1.56.tar.gz
cpsendEmail-v1.56/sendEmail/usr/local/bin/
chmod+x/usr/local/bin/sendEmail
chown-Rzabbix.zabbix/usr/lib/zabbix/alertscripts
cat>/usr/lib/zabbix/alertscripts/SendEmail.sh<<EOF
#!/bin/bash

LOGFILE="/tmp/Email.log"
:>"\$LOGFILE"
exec1>"\$LOGFILE"
exec2>&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-tGB2312-fUTF-8<<EOF
\$message_subject_utf8
EOF\`
[\$?-eq0]&&message_subject="\$message_subject_gb2312"||message_subject="\$message_subject_utf8"

#转换邮件内容为GB2312
message_body_gb2312=\`iconv-tGB2312-fUTF-8<<EOF
\$message_body_utf8
EOF\`
[\$?-eq0]&&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"-omessage-content-type=text-omessage-charset=gb2312
EOF
chmod+x/usr/lib/zabbix/alertscripts/SendEmail.sh
cd/usr/share/zabbix/fonts
mvgraphfont.ttfgraphfont.ttf.back
wgethttp://qkadownload.qkagame.com/msyh.ttf
if[$?-ne0];then
echo"wgetmsyherr"
exit
fi
mvmsyh.ttfgraphfont.ttf
chmod777graphfont.ttf
systemctlstartzabbix-server
systemctlstarthttpd
systemctlstartzabbix-agent
systemctlenablezabbix-server.service
systemctlenablezabbix-agent.service
systemctlenablehttpd.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

使用方法

给脚本可执行权限chmod+x脚本文件
数据默认用户名密码zabbix发邮件脚本名字:SendEmail.sh登陆zabbixweb账号密码admin:zabbix
./zabbix_lamp.shsmtp.test.comadmin123456admin@test.com
./zabbix_lnmp.shsmtp.test.comadmin123456admin@test.com
lnmp+zabbix访问lamp+zabbix访问http://ip/zabbix
centos6脚本名字zabbix_lamp_6.shzabbix_lnmp_6.sh

zabbix web配置以lamp+zabbix 为实例:

wKiom1g-KofhxutnAACPFmRK0Q0504.png-wh_50

wKioL1g-KoiQaLjTAADSN18U46w463.png-wh_50

wKiom1g-KonyL_AWAACgXC4eS50416.png-wh_50

wKioL1g-KoqiYTK_AACAMvD5ynA424.png-wh_50

@L_502_4@

wKioL1g-KouC1d1iAACL8fqHjDI306.png-wh_50

wKioL1g-KouhmFI3AAA-v3lscFo499.png-wh_50

中文设置默认图像微软雅黑

wKioL1g-K5DC8X_YAACp1aMFK6Q910.png-wh_50

wKiom1g-K5DShFMOAACOduoZkhc828.png-wh_50

zabbix 邮件配置

3.2邮件配置必须添加

参数{ALERT.SENDTO}

{ALERT.SUBJECT}

{ALERT.MESSAGE}

wKiom1g-MBbgvjqJAACiwumnfXs893.png-wh_50

打开默认动作测试报警

wKiom1g-MnbzVIh4AABo8rhD4GU852.png-wh_50

wKiom1g-NEfD9-ioAABXWLKegAA469.png-wh_50

wKioL1g-MnfyXYz9AADBk2EF_m8883.png-wh_50

wKiom1g-MnfzNsl5AACUIANtuoE685.png-wh_50

wKiom1g-MnezRtqfAAA0_6jS8fE731.png-wh_50

wKioL1g-MnjizESjAAA7aTs16Ho729.png-wh_50

wKioL1g-MnjyUlM6AABGO-gN1MY768.png-wh_50

关闭zabbix_agent 看是否正常发邮件

centos7/bin/systemctl stop zabbix-agent.service

centos6 servicezabbix-agent stop

所有脚本放到附件

原文链接:https://www.f2er.com/centos/379676.html

猜你在找的CentOS相关文章