已有LNMP环境下搭建Zabbix5

已有LNMP环境下搭建Zabbix5

zabbix官方手册:https://www.zabbix.com/documentation/5.0/zh/manual

官方项目地址:https://cdn.zabbix.com/zabbix/sources/stable/

网上看到教程大多是使用zabbix官方环境下搭建的,但我们已经有了LNMP的情况下,再去使用官方的环境就有些许的多余了。

所以这里我写个已有lnmp+zabbix5.0

背景环境:

  • centos7.6
  • 已安装LNMP(nginx1.16,mysql5.7,php7.2)

如果没有安装lnmp,可使用我的脚本:

bash <(curl https://gitee.com/ffing/onekey/raw/master/onekey.sh)

流程:

  • 一,安装zabbix服务端客户端
  • 二,安装web界面
  • 三,配置
  • 四,测试

一,安装zabbix服务端客户端

1.下载zabbix源

#安装官方源
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
#替换阿里源
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

2.安装服务端、客户端、测试命令

yum -y install zabbix-server-mysql zabbix-agent zabbix-get

二,安装web界面

1.下载zabbix项目

#安装wget(如有可忽略)
yum -y install wget
#下载官方zabbix项目(根据自己版本需求下载,我这里下载5.0.15)
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.15.tar.gz

2.解压出zabbix包的web界面到nginx站点目录

(压缩包内“ui”的文件夹)

#解压刚刚下载的zabbix项目包
tar -xvf zabbix-5.0.15.tar.gz
#zabbix-5.0.15目录下的“ui”目录,复制并重命名为zabbix-web到/usr/share/nginx下
cp -r ./zabbix-5.0.15/ui /usr/share/nginx/zabbix-web
#修改目录权限(php写入权限,可自行查看php用户,我这里是apache)
chown -R apache:apache /usr/share/nginx/zabbix-web

三,修改配置

1.mysql相关

登陆mysql,创建默认数据库zabbix(也可以根据自己需求修改)

#创建数据库zabbix
create database zabbix character set utf8 collate utf8_bin;
#创建用户zabbix,并设置密码为“password”
create user zabbix@localhost identified by 'password';
#配置zabbix权限
grant all privileges on zabbix.* to zabbix@localhost;

修改zabbix服务端配置文件/etc/zabbix/zabbix_server.conf

#填写刚刚创建的zabbix数据库密码"password"
DBPassword=password

导入zabbix初始数据

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -ppassword zabbix

2.nginx相关

创建zabbix站点配置文件

vi /etc/nginx/conf.d/zabbix.80.conf

脚本内容如下:

server {
listen 80;
server_name zabbix.ffing.cn; #根据自己情况填写域名
root /usr/share/nginx/zabbix-web; #zabbix-web的目录
index index.php;

location / {

}

location ~ \.php$        {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include        fastcgi_params;
                        }

}

注:如果使用locatlhost时,需要修改端口,防止端口冲突。

3.php相关

修改/etc/php.ini,环境监测的时候会提示信息,也可以提前修改

默认的php配置通常需要修改4处:

sed -i 's#post_max_size = 8M#post_max_size = 16M #' /etc/php.ini
sed -i 's#max_execution_time = 30#max_execution_time = 300#' /etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#' /etc/php.ini
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /etc/php.ini
PHP version7.2.0
PHP option “memory_limit”128M
PHP option “post_max_size”16M
PHP option “upload_max_filesize”2M
PHP option “max_execution_time”300
PHP option “max_input_time”300
PHP option “date.timezone”Asia/Shanghai
PHP databases support
PHP bcmath
PHP mbstring
PHP option “mbstring.func_overload”off
PHP sockets
PHP gd2
PHP gd PNG support
PHP gd JPEG support
PHP gd GIF support
PHP gd FreeType support
PHP libxml2.6.15
PHP xmlwriter
PHP xmlreader
PHP LDAP
PHP OpenSSL
PHP ctype
PHP session
PHP option “session.auto_start”off
PHP gettext
PHP option “arg_separator.output”&

4.关闭selinux、放行端口

端口根据自己情况开放

10050-客户端端口

10051-服务器端口

关闭selinux

四,测试

重启lnmp和zabbix-server

systemctl restart nginx mysqld php-fpm zabbix-server

打开你的服务器地址:http://域名

https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-7.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0
https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-8.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0
https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-9.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0
https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-10.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0
https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-11.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

默认用户名:Admin

默认密码:zabbix

https://qnimg.ffing.cn/wp-content/uploads/2021/11/image-12.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0
https://qnimg.ffing.cn/wp-content/uploads/2021/09/image-2.png?imageView2/0/q/75|watermark/1/image/aHR0cHM6Ly9xbmltZy5mZmluZy5jbi9mbl9sb2dvLnBuZw==/dissolve/55/gravity/SouthEast/dx/0/dy/0

其他

在用户配置中设置中文后,字体乱码问题:

因为zabbix使用了自己的字体库: zabbix-web站点目录/assets/fonts/DejaVuSans.ttf

两种方法解决:(提前备份原有字体)

1.上传中文字体,覆盖zabbix-web站点目录/assets/fonts/DejaVuSans.ttf

2.yum中文字体库,后覆盖

#安装字体
yum install wqy-microhei-fonts -y
#覆盖字体
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc zabbix-web站点目录/assets/fonts/DejaVuSans.ttf

覆盖完成后,重启zabbix-server

付nginx检测脚本

#!bin/bash
#nginx监控地址
NGINX_HOST=127.0.0.1
NGINX_PORT=80
nginx
NGINX_STATUS=status
NGINX_COMMAND=$1

# 检测nginx进程是否存在
nginx_ping() {
    /sbin/pidof nginx | wc -l
}
nginx_active(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk '/Active/ {print $NF}'
}
nginx_reading(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk '/Reading/ {print $2}'
}
nginx_writing(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk '/Writing/ {print $4}'
       }
nginx_waiting(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk '/Waiting/ {print $6}'
       }
nginx_accepts(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk 'NR==3 {print $1}'
       }
nginx_handled(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk 'NR==3 {print $2}'
       }
nginx_requests(){
    /usr/bin/curl -s "http://$NGINX_HOST:"$NGINX_PORT"/$NGINX_STATUS/" |awk 'NR==3 {print $3}'
       }
  case $NGINX_COMMAND in
ping)
nginx_ping
;;
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
      *)
echo $"USAGE:$0 {ping|active|reading|writing|waiting|accepts|handled|requests}"
    esac
good good study, day day up!

发表评论

textsms
account_circle
email

已有LNMP环境下搭建Zabbix5
zabbix官方手册:https://www.zabbix.com/documentation/5.0/zh/manual 官方项目地址:https://cdn.zabbix.com/zabbix/sources/stable/ 网上看到教程大多是使用zabbix官方环境下搭…
扫描二维码继续阅读
2021-09-12