所安装版本mysql 5.6 php5.5 zabbix3.2
centos7 lnmp+zabbix3.2 脚本
#!/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/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-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 [email protected] identified by ‘zabbix‘;" | mysql echo "grant all privileges on zabbix.* to [email protected]‘%‘ 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 脚本
#/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/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-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 [email protected] identified by ‘zabbix‘;" | mysql echo "grant all privileges on zabbix.* to [email protected]‘%‘ 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
使用方法:
给脚本可执行权限chmod +x 脚本文件 数据默认用户名密码zabbix 发邮件脚本名字:SendEmail.sh 登陆zabbix web账号密码 admin:zabbix ./zabbix_lamp.sh smtp.test.com admin 123456 [email protected] ./zabbix_lnmp.sh smtp.test.com admin 123456 [email protected] lnmp+zabbix 访问 lamp+zabbix 访问 http://ip/zabbix centos6 脚本名字zabbix_lamp_6.sh zabbix_lnmp_6.sh
zabbix web配置以lamp+zabbix 为实例:
中文设置默认图像微软雅黑
zabbix 邮件配置
3.2邮件配置必须添加
参数 {ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
打开默认动作测试报警
关闭zabbix_agent 看是否正常发邮件
centos7 /bin/systemctl stop zabbix-agent.service
centos6 service zabbix-agent stop
所有脚本放到附件
时间: 2024-10-05 05:21:17