Centos7搭建zabbix6.0
Posted 微风◝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7搭建zabbix6.0相关的知识,希望对你有一定的参考价值。
此方法适用于zabbix6以上版本
zabbix6.0前期环境准备:Lamp(linux httpd mysql8.0 php)
mysql官网下载位置:https://dev.mysql.com/downloads/mysql/
Zabbix源码包地址:https://www.zabbix.com/cn/download_sources
Zabbix6官方文档地址: .https://www.zabbix.com/documentation/6.0/en/manual/installation/getting_zabbix
构建过程:
关闭防火墙和安全机制
#关闭防火墙 systemctl stop firewalld.service #关闭安全机制 setenforce 0
一 丶 安装MySQL8.0(RPM)
1:配置mysql源
#下载MySQL源 wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm #配置MySQL源 yum -y install mysql80-community-release-el7-5.noarch.rpm
2:为防止后续编译安装zabbix时报错 提前安装依赖
#安装MySQL相关依赖 yum -y install gcc-c++ mysql-devel net-snmp-devel libevent-devel
3:下载MySQL和zabbix
#下载zabbix wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz #下载MySQL wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
4:解压并安装下载好的MySQL安装包
#创建MySQL目录 mkdir /usr/local/mysql #解压MySQL安装包 tar xf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql #移动到mysql目录 cd /usr/local/mysql/ #RPM方式安装MySQL rpm -ivh mysql-community-* --force --nodeps
5:检查MySQL的个RPM包是否被安装
rpm -qa |grep mysql #显示如下安装包 mysql-community-server-8.0.28-1.el7.x86_64 mysql-community-libs-compat-8.0.28-1.el7.x86_64 mysql-community-client-plugins-8.0.29-1.el7.x86_64 mysql-community-common-8.0.29-1.el7.x86_64 mysql-community-devel-8.0.29-1.el7.x86_64 mysql-community-common-8.0.28-1.el7.x86_64 mysql-community-libs-8.0.29-1.el7.x86_64 mysql80-community-release-el7-5.noarch mysql-community-libs-compat-8.0.29-1.el7.x86_64 mysql-community-client-8.0.28-1.el7.x86_64 mysql-community-libs-8.0.28-1.el7.x86_64
6:启动MySQL并加入开机自启
#启动MySQL systemctl start mysqld #MySQL加入开启自启 systemctl enable mysqld
7:检查MySQL服务是否启动
#以下三种方法,均可(建议都看一遍) systemctl status mysqld.service netstat -anptu |grep mysql ps -ef |grep mysql
8:启动mysql后会初始化 查找mysql密码
cat /var/log/mysqld.log | grep password 2022-06-23T16:15:31.370137Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Dfo5Dm-!fVZG #密码为:Dfo5Dm-!fVZG
9:修改MySQL的root密码
#由于MySQL8.0 有密码验证组件,若希望设置简单的密码,需要修改服务验证条件 # 密码检查等级,0/LOW、1/MEDIUM、2/STRONG set global validate_password.policy=0; # 密码的最短长度 set global validate_password.length=6; # 密码至少要包含的小写字母个数和大写字母个数 set global validate_password.mixed_case_count=0; # 设置密码 mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY 'Likun@123';
10:创建zabbix库
#创建zabbix库 create database zabbix character set utf8 collate utf8_bin; #创建zabbix用户 create user zabbix@localhost identified by 'Likun@123'; #授权 grant all privileges on zabbix.* to zabbix@localhost;
二丶安装zabbix6.1
1:解压在官网上下载的zabbix源码包
#创建zabbix目录 mkdir /usr/local/zabbix #解压 tar -zxvf zabbix-6.0.1.tar.gz -C /usr/local/zabbix/
2:创建用户账户
(1)对于所有 Zabbix 守护进程,需要一个非特权用户,如果从非特权用户帐户启动 Zabbix 守护程序,它将以该用户身份运行。
(2)然而,如果一个守护进程以“root”启动,它会切换到“zabbix”用户,且这个用户必须存在。在 Linux系统中,可以使用下面命令建立一个用户(该用户属于自己的用户组,“ zabbix”)
#创建zabbix组 groupadd zabbix #创建zabbix用户 useradd -g zabbix -M -s /sbin/nologin zabbix
3:站在zabbix目录中编译安装
#移动到zabbix目录 cd /usr/local/zabbix/zabbix-6.0.1/ #编译 ./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-net-snmp --with-mysql make install
三丶安装PHP
1:由于CentOS7自带PHP版本为5.6,所以需要安装额外的库,也是remi的库
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm yum -y install yum-utils yum-config-manager --disable 'remi-php*' yum-config-manager --enable remi-php74 yum -y install php php-bcmath php-gd php-xml php-mbstring php-mysqlnd php-ldap yum -y install curl-devl libxml2 libxml2-devel
2:需要修改php参数(网页预配置必要条件)
vim /etc/php.ini 修改post_max_size为16M 修改max_execution_time为300 修改max_input_time为300
四丶配置httpd
1:移动前端文件至web服务的根目录并授权
cp -r /usr/local/zabbix/zabbix-6.0.1/ui/* /var/www/html/ chown apache:apache /var/www/html -R
2:导入数据库架构及数据
mysql -uzabbix -pLikun@123 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/schema.sql mysql -uzabbix -pLikun@123 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/images.sql mysql -uzabbix -pLikun@123 zabbix < /usr/local/zabbix/zabbix-6.0.1/database/mysql/data.sql
3:修改配置zabbixserver文件数据库密码
vim /usr/local/zabbix/etc/zabbix_server.conf # DBPassword= 修改为MySQL的zabbix用户密码 DBPassword=Likun@123
4:开启httpd zabbix
service httpd start systemctl enable httpd.service cd /usr/local/zabbix/sbin/ ./zabbix_server
五丶网页验证
1:网页测试:(谷歌浏览器)
本机ip:80
2:选择中文,并点击一步
3:必要条件都已满足,点击下一步
4:DB连接配置
5:输入账号密码
6:登录成功
文章修改于:2022年6月23日
未修改前文章有许多错误,现已改正,感谢评论区的各位
如有问题,请在评论区告知,后续会改正
centos 快速搭建lnmplamp+zabbix3.2监控系统
centos 快速搭建lnmp、lamp+zabbix3.2监控系统
所安装版本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
所有脚本放到附件
本文出自 “成长记录” 博客,请务必保留此出处http://juestnow.blog.51cto.com/1515305/1878023
以上是关于Centos7搭建zabbix6.0的主要内容,如果未能解决你的问题,请参考以下文章