尊敬的各位大佬,亲爱的小白们,以及正在刚入门zabbix的精英们,你们好,本文章适读范围:
搭建zabbix可以参考我的这篇文章:https://blog.csdn.net/qq_39591494/article/details/78983861 (此文章为3.2版本)本章使用zabbix3.4.8版本,由于版本不同的问题,在配置方面也会有不同之处,那么同时可以参考以下内网一键安装zabbix脚本来完成此搭建。
#!/bin/bash
#Data: Fri May 4 09:37:26 CST 2018
#Founder:
#describe: One button installation zabbix3.4.8
#Edition: V1
#OS: Centos7.2x86_64
. /etc/init.d/functions
MMM=`rpm -qa | grep mariadb`
Route=/usr/local/src
################################################################
#mount iamges!
################################################################
function MOUNT(){
rm -rf /etc/yum.repos.d/*
mount /usr/local/src/CentOS-7-x86_64-DVD-1511.iso /mnt
cat < /etc/yum.repos.d/aaa.repo
[aaa]
name=aaa
baseurl=file:///mnt
enabled=1
gpgcheck=0
daasbank
sleep 3
yum install -y make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel perl compat* mpfr cpp glibc libgomp
sleep 3
yum install -y libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm*
sleep 3
yum install -y freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel2
sleep 3
yum install -y freetype-devel net-snmp-devel freetype-devel net-snmp-devel net-snmp net-snmp-devel curl-devel
sleep 3
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel
}
################################################################
#Install MySQL5.7.18
################################################################
function Mysql(){
if [ -n $MMM ];then
rpm -e mariadb-libs --nodeps 2&>/dev/null
else
echo "Mariadb error!!!"
return 1
fi
tar zxf $Route/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && {
mv $Route/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql && \
cd /usr/local/mysql/ && mkdir data && mkdir log && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
if [ "$?" -eq 0 ];then
source /etc/profile && groupadd mysql && useradd -r -g mysql -s /bin/false mysql
else
echo "Mysql error !!!"
return 1
fi
}
cat << daasbank-mysql > /etc/my.cnf
[client]
socket=/usr/local/mysql/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
socket=/usr/local/mysql/mysql.sock
log_error=/usr/local/mysql/log/mysql.err
daasbank-mysql
if [ -f /etc/my.cnf ];then
chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && bin/mysqld --initialize --user=mysql && cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && service mysqld start
else
echo "/etc/my.cnf error !!!"
return 1
fi
#######################################################################
#Mysql password install
#######################################################################
ln -s /usr/local/mysql/bin/mysql /usr/local/sbin
ln -s /usr/local/mysql/bin/mysqladmin /usr/local/sbin
PASS=`cat /usr/local/mysql/log/mysql.err | grep password | awk '{print $11}'`
mysqladmin -uroot -p${PASS} password 111111 &> /dev/null
if [ "$?" -eq 0 ];then
echo "Mysql password is ok!"
else
echo "Mysql password is not ok!!!"
return 1
fi
}
#######################################################################
#Install Nginx1.12.2
#######################################################################
function Nginx(){
cd $Route && {
tar zxf $Route/nginx-1.12.2.tar.gz && cd nginx-1.12.2/ && \
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx && make && make install
useradd -M -s /sbin/nologin nginx
}
if [ "$?" -eq 0 ];then
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin && /usr/local/nginx/sbin/nginx
else
echo "Nginx Install error!!!"
exit 1
fi
}
########################################################################
#Intsall LIB.so
########################################################################
function Lib(){
cd $Route && {
tar zxf libevent-2.1.8-stable.tar.gz && cd libevent-2.1.8-stable && ./configure && make && make install
if [ "$?" -eq 0 ];then
echo "libevent install is ok!!!"
else
echo "libevent install is not ok!!!"
return 1
fi
}
cd $Route && {
tar zxf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7 && ./configure && make && make install
if [ "$?" -eq 0 ];then
echo "libmcrypt-2.5.7 install is ok!!!"
else
echo "libmcrypt-2.5.7 install is not ok!!!"
return 1
fi
}
cd $Route && {
tar zxf fping-3.10.tar.gz && cd fping-3.10/ && ./configure && make && make install
if [ "$?" -eq 0 ];then
echo "fping-3.10.tar.gz install is ok!!!"
else
echo "fping-3.10.tar.gz install is not ok!!!"
return 1
fi
}
}
##########################################################################
#Install php5.6
##########################################################################
function php(){
cd $Route && {
tar zxf php-5.6.25.tar.gz && cd php-5.6.25 && \
./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl
if [ "$?" -eq 0 ];then
make && make install
else
echo "php install ./configure error!!!!"
return 1
fi
}
cd $Route/php-5.6.25 && {
cp php.ini-production /etc/php.ini && cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on
}
if [ "$?" -eq 0 ];then
cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
else
echo "php Environmental Science ERROR!!!"
return 1
fi
if [ ! -d /usr/local/php5.6/etc/php-fpm.conf ]
then
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9000/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.max_children = 5/pm.max_children = 300/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.start_servers = 2/pm.start_servers = 20/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 20/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 100/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/user = nobody/user = nginx/g' /usr/local/php5.6/etc/php-fpm.conf
sed -i 's/group = nobody/group = nginx/g' /usr/local/php5.6/etc/php-fpm.conf
else
echo "php-fpm.conf ERROR!!!"
return 1
fi
if [ $? -eq 0 ]
then
systemctl start php-fpm && echo "php install is ok!!!"
else
echo "php install is not ok!!!"
return 1
fi
}
##################################################################################
#Install nginx && php config!
##################################################################################
function nginx-php(){
if [ -f /usr/local/nginx/conf/nginx.conf ];then
sed -i 's/index index.html index.htm;/index index.php index.html index.htm;/g' /usr/local/nginx/conf/nginx.conf
sed -i 's/# root html;/ root html;/g' /usr/local/nginx/conf/nginx.conf
sed -i 's/# fastcgi_pass 127.0.0.1:9000;/ fastcgi_pass 127.0.0.1:9000;/g' /usr/local/nginx/conf/nginx.conf
sed -i 's/# fastcgi_index index.php;/ fastcgi_index index.php;/g' /usr/local/nginx/conf/nginx.conf
sed -i 's*# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;* fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;*g' /usr/local/nginx/conf/nginx.conf
sed -i 's/# include fastcgi_params;/ include fastcgi.conf;/g' /usr/local/nginx/conf/nginx.conf
sed -i '71d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;70a}' /usr/local/nginx/conf/nginx.conf
sed -i '65d' /usr/local/nginx/conf/nginx.conf && sed -i 'N;64alocation ~ \\.php$ {' /usr/local/nginx/conf/nginx.conf
else
echo "Nginx && php ERROR!!!"
return 1
fi
touch /usr/local/nginx/html/daasbank.php
cat << daasbank-lnmp >/usr/local/nginx/html/daasbank.php
daasbank-lnmp
/usr/local/nginx/sbin/nginx -s reload
if [ "$?" -eq 0 ];then
echo "LNMP is ok! Please Visit http://IP/daasbank.php"
else
echo "LNMP is not ok!!!"
return 1
fi
}
############################################################################
#Install zabbix3.4.8
############################################################################
function zabbix(){
groupadd zabbix && useradd -g zabbix zabbix
sed -i 's/;date.timezone =/date.timezone = PRC/g' /etc/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' /etc/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini
sed -i 's/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/g' /etc/php.ini
sed -i 's/;mbstring.func_overload = 0/mbstring.func_overload = 0/g' /etc/php.ini
cd $Route && {
tar zxf zabbix-3.4.8.tar.gz && cd zabbix-3.4.8 && \
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl
if [ "$?" -eq 0 ];then
make && make install
else
echo "zabbix install error !!!"
return 1
fi
}
ln -s /usr/local/zabbix/bin/* /usr/local/bin/
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
/usr/local/mysql/bin/mysql -uroot -p111111 -e "create database zabbix character set utf8;"
/usr/local/mysql/bin/mysql -uroot -p111111 -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
if [ "$?" -eq 0 ]
then
echo "user zabbix mysql is ok!!!"
else
echo "user zabbix mysql is not ok!!!"
return 1
fi
cd $Route/zabbix-3.4.8/database/mysql && {
/usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql
/usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql
/usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < data.sql
}
if [ "$?" -eq 0 ]
then
echo "zabbix is mysql database is ok!"
else
echo "zabbix is mysql database is not ok!"
fi
sed -i 's$LogFile=/tmp/zabbix_server.log$LogFile=/usr/local/zabbix/logs/zabbix_server.log$g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's$# PidFile=/tmp/zabbix_server.pid$PidFile=/usr/local/zabbix/logs/zabbix_server.pid$g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# DBHost=localhost/DBHost=localhost/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# DBPassword=/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/# DBPort=3306/DBPort=3306/g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's$# FpingLocation=/usr/sbin/fping$FpingLocation=/usr/sbin/fping$g' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's$# DBSocket=/tmp/mysql.sock$DBSocket=/usr/local/mysql/mysql.sock$g' /usr/local/zabbix/etc/zabbix_server.conf
mkdir -p /usr/local/zabbix/logs && chown -R zabbix:zabbix /usr/local/zabbix/
cat << daasbank-zabbix >/etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/lib
/usr/local/lib
daasbank-zabbix
/usr/local/nginx/sbin/nginx -s reload && /etc/init.d/php-fpm restart
if [ "$?" -eq 0 ];then
echo "zabbix && nginx && php restart is ok!!!"
else
echo "zabbix && nginx && php restart is not ok!!!"
return 1
fi
cd $Route/zabbix-3.4.8/ && {
cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_server
chmod +x /etc/rc.d/init.d/zabbix_agentd
chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
sed -i 's$BASEDIR=/usr/local$BASEDIR=/usr/local/zabbix/$g' /etc/rc.d/init.d/zabbix_server
sed -i 's*PIDFILE=/tmp/$BINARY_NAME.pid*PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid*g' /etc/rc.d/init.d/zabbix_server
sed -i 's$BASEDIR=/usr/local$BASEDIR=/usr/local/zabbix/$g' /etc/rc.d/init.d/zabbix_agentd
sed -i 's*PIDFILE=/tmp/$BINARY_NAME.pid*PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid*g' /etc/rc.d/init.d/zabbix_agentd
ldconfig && systemctl daemon-reload
/etc/init.d/zabbix_agentd start &>/dev/null
/etc/init.d/zabbix_server start &>/dev/null
}
if [ "$?" -eq 0 ];then
echo "zabbix Being configured....."
else
echo "zabbix start is not ok!!!"
fi
mkdir /usr/local/nginx/html/zabbix/
if [ -d /usr/local/nginx/html/zabbix ];then
cp -r $Route/zabbix-3.4.8/frontends/php/* /usr/local/nginx/html/zabbix/
else
echo "zabbix mkdir error!!!"
return 1
fi
chown -R nginx:nginx /usr/local/nginx/html/zabbix
if [ "$?" -eq 0 ];then
echo "zabbix install is ok pleses http://IP/zabbix"
else
echo "zabbix install is not ok!!! error!"
return 1
fi
}
function main(){
MOUNT
Mysql
Nginx
Lib
php
nginx-php
zabbix
}
main
可能会有疑问了,这个脚本怎么运行啊?我咋运行不起来呢?
解答:此脚本专门为:Centos7.2x86_64位操作系统编写的一键安装,并且为纯内网环境,所以打包,下载,本地yum源都需要软件提供,在运行此脚本之前需要上传5-6个安装包。 那如何获取包。这里可以联系我。WeChat 声明:(非广告-文章特殊情况) 获取完包之后上传至->zabbix服务器/usr/local/src --> 解压如下:
2.1、运行脚本安装zabbix监控如下:
[root@bogon src]# source zabbix_install.sh
此时可以去抽根烟、躺会、看会电视、等待着结束。安装过程时间(10-15分钟)
2.2、脚本结束会有以下提示:
2.3、提示访问http://IP/zabbix 访问如下:
初始账号密码:admin---zabbix
到此刻-zabbix服务已经搭建完毕!
3.1、软件下载
下载软件安装包可以在:http://www.hmailserver.com/ 官网下载
安装该软件需要提供需要Microsoft .NET Framework Version 2.0支持,微软官方下载地址:
hs-3879http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&displayLang=en
3.2、安装
设置管理控制台的密码
等待安装结束
当我们连接到管理控制台的时候需要输入之前此的密码(此处填写刚刚设置的密码)
如何汉化?
参考:https://www.hmailserver.org/viewtopic.php?f=5&t=13
汉化完成后如下:
若按照以上操作并没有汉化成功,请重启计算机
3.3、配置邮件服务器
先添加一个域
如果需要,可以更改一下限制,域使用的空间、邮件的最大尺寸、用户最大空间、用户数等等,比如,这里整个硬盘只有60G空间的话,每个用户1G,允许最大的邮件为30M,太大了对服务器的压力太大了,我们可以按如下图设置进行限制设定
接着我们要为用户创建帐号了,输入用户名、密码,保存,记得这里也要设置一下用户空间大小不超过1G就可以保存了,因为上面我们做好了限制.
在这里为了测试邮件能够正常发送 我建立两个账号
到目前为止,邮件服务器配置结束,接下来配置客户端
3.4、配置邮件客户端
邮件客户端,我们可以使用foxmail或者outlook等,这里我使用的是foxmail
foxmail官网:http://www.foxmail.com/ 下载即可(安装过程:略)
登录foxmail账号 yankai及zhangsan 测试邮件是否可以正常发送
192.168.1.120 是邮件服务器的IP地址(点击创建出现以下界面)
提示:zhangsan用户的邮箱和以上设置是一样的 这里不做演示
3.5、测试邮件是否能够正常通信
3.5.1、测试zhangsan发送邮件---->[email protected] 邮箱账号
3.5.2、使用yankai邮箱账号测试是否收到邮件
到目前为止内网邮件服务器搭建完毕!
zabbix客户端的安装可以参考:https://blog.csdn.net/qq_39591494/article/details/78983861 此文章。
或者可以使用以上脚本中的zabbix-agent片段来运行,在此处不做演示!
5.1、添加主机
提示:本章不会做太详细的配置监控说明,可以参考:https://blog.csdn.net/qq_39591494/article/details/80504256 (详细配置说明文章)
5.2、配置监控web服务若状态码非200,则触发灾难触发器
5.3、配置web场景监控zabbix_agent_webserver(配置过程:略)
https://blog.csdn.net/qq_39591494/article/details/80504256 (详细配置说明文章)
5.4、为了方便测试配置web场景触发器当最新的状态码==200时触发灾难警告!!!(配置过程:略)
https://blog.csdn.net/qq_39591494/article/details/80504256 (详细配置说明文章)
5.5、配置zabbix邮件报警设置,当zabbix-agent(webserver)== 200时 触发邮件报警
前言:在配置邮件报警的过程中可以参考我的这篇文章:https://blog.csdn.net/qq_39591494/article/details/80504256 (详细配置说明文章)
需要注意并严谨的配置如下:
5.5.1、动作配置
5.5.2、报警媒介类型配置
以上走25端口不走ssl 具体看邮件服务器配置~ 在用户名称下面有密码 直接输入邮箱密码就可以了。
其他的都可以参考:https://blog.csdn.net/qq_39591494/article/details/80504256
6.1、在以上设置的触发器条件中如果状态码==200 那么就触发灾难,那么在配置邮件的时候(如果有灾难发生-那么我就触发动作-那么在这里的动作就是email邮件报警)
流程:首先配置了web检测 ----->配置了触发器条件如果状态码==200则灾难 ---->配置了动作如果出现了灾难情况那么触发email-->通过email中的配置指向内网邮箱地址[email protected]
以上图片中显示已经发送成功 这时候需要去邮箱中查看邮件报警内容
此时我们可以正常的收到邮件。
一、为什么会一直发送那么多邮件,为什么==200时仪表盘的问题闪的会那么多。
答:因为在配置web触发器中配置了多重,所以会有那么多。
2、用163邮箱和qq邮箱不行吗? 为什么还要自己搭建个邮件服务器?
答:用163和qq当然可以,只不过在很多大型公司都是内网如果要求使用zabbix去监控并发送邮件报警该怎么办?
3、你写的这个文章IP地址好乱,能不能写一下客户端服务端邮件服务器的IP地址?
答:可以
zabbix_server-IP地址:192.168.1.100
zabbix_agent-IP地址:192.168.1.110
邮件服务器IP地址:192.168.1.120
邮件客户端foxmail-IP地址:192.168.1.130
4、我觉得写的还是可以看的下去的,我以后要看咋办?
点击关注应该就不会迷路,多一份关注,多一份爱~~~~
本章内容到此结束,若在过程中遇到问题---->请前往主页左侧找到显眼的wx 我们就会产生美好的故事~
谢谢观看~ 再见!