Centos 7.4下Zabbix 4.0.0 源码编译配置(图文超详细)

阶段一:准备工作

  • 服务器
Centos 7.4	zabbix-100	192.168.44.100	4核8G
  • 相关资源
    • 资源链接:https://pan.baidu.com/s/1B6y_-_3UMoXzmzM-cqe1rg 提取码:lbg6
      在这里插入图片描述
  • 关闭selinux
#关闭selinux
setenforce 0
 
#永久关闭selinux
vim /etc/selinux/config 

#修改SELINUX=enforcing 为值为disabled
SELINUX=disabled

#重启
reboot
  • 更换yum镜像源
#安装wget
yum install -y wget

#下载阿里镜像http://mirrors.aliyun.com/ epo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#清除缓存
yum clean all  

#生成缓存
yum makecache

阶段二:Nginx 部署

  • 拉取资源
#拉取Nginx【若已有则跳过】
cd /opt/software
wget http://nginx.org/download/nginx-1.7.6.tar.gz

#安装依赖
yum install –y gcc gcc-c++ make cmake pcre-devel openssl-devel

#解压
tar -zxvf nginx-1.7.6.tar.gz -C /opt/module/
cd /opt/module/nginx-1.7.6/ && ll

在这里插入图片描述

  • 检测并安装
    • 为nginx创建一个不用登陆的用户
    #为nginx创建一个不用登陆的用户
    useradd -M -s /sbin/nologin nginx
    
    • 检测环境
    #检测
    ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
    
    在这里插入图片描述
    • 编译安装
    #编译安装
    make && make install
    
    在这里插入图片描述
    • 授权
    #授权
    chown nobody -R /usr/local/nginx/
    
    • 修改pid文件位置
    #编辑
    vim /usr/local/nginx/conf/nginx.conf
    
    #路径
    pid 	/var/run/nginx.pid
    
    在这里插入图片描述
  • 使用systemctl管理Nginx
#编辑命令
vim /usr/lib/systemd/system/nginx.service

#加入内容
[Unit]
Description=nginx service
After=network.target 
   
[Service] 
Type=forking 
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

#刷新配置
systemctl daemon-reload

在这里插入图片描述

  • Nginx操作相关

    • 开机自启
    systemctl enable nginx   
    
    • 启动
    #启动命令
    systemctl start nginx
    
    #查看进程
    ps -ef|grep nginx
    

    在这里插入图片描述

    • 停止
    systemctl stop nginx
    
    • 刷新配置【服务不重启】
    systemctl reload nginx
    

阶段三:PHP 源码部署

  • 拉取资源
#安装依赖包
yum install -y gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel libxslt-devel

#拉取PHP【若已有则跳过】
cd /opt/software
wget http://docs.php.net/distributions/php-5.6.36.tar.gz

#解压
tar -zxvf php-5.6.36.tar.gz -C /opt/module/
cd /opt/module/php-5.6.36/ 
  • 检测并安装
    • 检测环境
    #安装目录为/usr/local/php
    ./configure --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --enable-fpm --enable-opcache \
    --with-mysql --with-mysqli  \
    --enable-session --with-zlib --with-curl --with-gd \
    --with-jpeg-dir --with-png-dir --with-freetype-dir \
    --enable-mbstring --enable-xmlwriter --enable-xmlreader \
    --enable-xml --enable-sockets --enable-bcmath --with-gettext
    
    在这里插入图片描述
    • 编译安装
    #编译安装
    make -j 8 && make install
    
    在这里插入图片描述
    • 拷贝相关配置文件至安装目录
    #切换目录
    cd /opt/module/php-5.6.36/ 
    
    #拷贝相关配置文件
    cp php.ini-production /usr/local/php/etc/php.ini
    cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
    cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
    
  • 配置使用systemctl管理PHP
#编辑
vim /usr/lib/systemd/system/php-fpm.service 

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

#刷新配置
systemctl daemon-reload

在这里插入图片描述

  • PHP启停相关
#开机自启
systemctl enable php-fpm

#启停相关
systemctl start php-fpm
systemctl stop php-fpm
systemctl restart php-fpm

#查看进程
ps -ef|grep php-fpm

在这里插入图片描述

阶段四:Zabbix 4.0.0源码部署

  • 拉取资源
#安装依赖
yum install -y libxml2-devel libcurl-devel libevent-devel net-snmp-devel mysql-community-devel 

#解压
cd /opt/software
tar -zxvf zabbix-4.0.0.tar.gz -C /opt/module/
cd /opt/module/zabbix-4.0.0/ && ll

在这里插入图片描述

  • 创建zabbix用户组
#创建zabbix 组
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
  • 检测环境并安装
    • 检测环境
    #检测环境
    ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
    
    在这里插入图片描述
    • 编译安装
    #编译安装 安装在/usr/local/zabbix下
    make install
    
    在这里插入图片描述
  • 登录MYSQL服务器为zabbix创建链接账户
#登录Mysql
mysql -uroot -p您的密码
#创建专用数据库
create database zabbix character set utf8 collate utf8_bin;
#创建授权账户
GRANT ALL PRIVILEGES ON  *.* TO 'zabbix'@'%' IDENTIFIED BY 'SYS_666_zabbix';
#刷新
flush privileges;
#退出
exit;

在这里插入图片描述

  • 给zabbix数据库中导入sql脚本信息
#切换目录
cd /opt/module/zabbix-4.0.0/database/mysql

#导入脚本【注意顺序】
mysql -uzabbix -p'SYS_666_zabbix' zabbix < schema.sql
mysql -uzabbix -p'SYS_666_zabbix' zabbix < images.sql
mysql -uzabbix -p'SYS_666_zabbix' zabbix < data.sql

在这里插入图片描述

阶段五:zabbix_server 配置

  • 配置zabbix_server数据源信息
#编辑命令
vim /usr/local/zabbix/etc/zabbix_server.conf

#配置内容
DBHost=192.168.44.100
DBName=zabbix
DBUser=zabbix
DBPassword=SYS_666_zabbix
ListenIP=192.168.44.100

在这里插入图片描述

  • 使用systemctl管理zabbix_server
#编辑命令
vim /usr/lib/systemd/system/zabbix_server.service

#加入内容
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

#刷新配置
systemctl daemon-reload

在这里插入图片描述

  • zabbix_server相关操作
#开机自启
systemctl enable zabbix_server

#启停相关
systemctl start zabbix_server
systemctl stop zabbix_server
systemctl restart zabbix_server

#查看进程
ps -ef|grep zabbix_server

在这里插入图片描述

阶段六:zabbix_agentd配置

  • 配置zabbix_agentd数据源信息
#编辑命令
vim /usr/local/zabbix/etc/zabbix_agentd.conf

#配置内容
EnableRemoteCommands=1 
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
#Zabbix Server IP 地址
Server=192.168.44.100
#Zabbix Server 发送监控内容
ServerActive=192.168.44.100
#本机主机名 内容要和Zabbix Server 配置的 Hostname 一致
Hostname=zabbix server
ListenPort=10050
#用于Item获取数据
HostMetadataItem=system.uname 
User=zabbix
#是否启用自定义key,zabbix监控mysql、tomcat等数据时需要自定义key
UnsafeUserParameters=1 
  • 使用systemctl管理zabbix_agentd
#编辑
vim /usr/lib/systemd/system/zabbix_agentd.service
 
#脚本内容
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
#EnvironmentFile=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
Type=forking
Restart=on-failure
#PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

#刷新配置
systemctl daemon-reload
  • zabbix_agentd相关操作
#开机自启
systemctl enable zabbix_agentd

#启停相关
systemctl start zabbix_agentd
systemctl stop zabbix_agentd
systemctl restart zabbix_agentd

#查看进程
ps -ef|grep zabbix_agentd

在这里插入图片描述

阶段七:zabbix_web 配置

  • 部署Zabbix Web界面
    • 说明:Zabbix前端使用PHP写的,所以必须运行在PHP支持的Web服务器上
#拷贝zabbix_web页面至nginx相关目录
cp /opt/module/zabbix-4.0.0/frontends/php/* /usr/local/nginx/html/ -rf

#配置php信息
vim /usr/local/php/etc/php.ini

#内容
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
#取消注释即可
always_populate_raw_post_data = -1
#取消注释并设置时区为上海
date.timezone = Asia/Shanghai

#重启动php
systemctl restart php-fpm
  • Nginx与PHP整合
#编辑nginx配置
vim /usr/local/nginx/conf/nginx.conf

#修改内容
server {
      listen       80;
      server_name  localhost;

      access_log  logs/zabbix.access.log  main;

      location / {
          root   html;
          index  index.php index.html index.htm;
      }

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

在这里插入图片描述

  • 重启Nginx
#重启Nginx并刷新配置
systemctl restart nginx
systemctl reload nginx

阶段八:WEB 页面配置

  • 访问测试
    • http://192.168.44.100/
      在这里插入图片描述
  • 先决条件检测【假设有fail的修改php配置即可】
    在这里插入图片描述
  • zabbix链接数据库配置
    在这里插入图片描述
  • zabbix server 详细信息
    在这里插入图片描述
  • 安装前总结
    在这里插入图片描述
  • 根据提示写入zabbix server信息
    • 方式一
      • 下载文件 -->上传至服务器 --> 并拷贝至目录
      #下载文件并上传至/opt/目录
      cd /opt/
      #拷贝至目标目录
      cp zabbix.conf.php /usr/local/nginx/html/conf/
      
      #重启Nginx
      /usr/local/nginx/sbin/nginx -t
      /usr/local/nginx/sbin/nginx -s reload
      
    • 方式二
      • 下载文件 --> 通过vim编辑指定文件并加入内存
      #编辑命令
      vim /usr/local/nginx/html/conf/zabbix.conf.php
      
      #重启Nginx
      /usr/local/nginx/sbin/nginx -t
      /usr/local/nginx/sbin/nginx -s reload
      
      在这里插入图片描述
  • 安装完成
    在这里插入图片描述
  • Zabbix WEB端登录页【用户名:Admin 密码:zabbix】
    在这里插入图片描述
  • Zabbix 监控主页
    在这里插入图片描述
  • 修改Zabbix 登录密码及语言
    在这里插入图片描述
  • 到此,Zabbix 4.0.0源码配置完成。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你编译安装后启动Zabbix Server,但网页上无法检测到Server正在运行,你可以尝试以下解决方法: 1. 检查Zabbix Server的日志文件:查看Zabbix Server的日志文件以获取更多信息。默认情况下,日志文件位于`/usr/local/etc/zabbix_server.conf`,可通过以下命令查看: ```shell sudo vi /usr/local/etc/zabbix_server.conf ``` 在日志配置部分,确认`LogFile`参数的路径,然后查看该文件以获取任何错误或警告信息: ```conf # 日志文件路径 LogFile=/var/log/zabbix/zabbix_server.log ``` 2. 检查Zabbix Server是否在运行:使用以下命令检查Zabbix Server进程是否正在运行: ```shell ps aux | grep zabbix_server ``` 如果没有找到运行中的Zabbix Server进程,使用以下命令启动它: ```shell sudo systemctl start zabbix-server ``` 确保启动命令没有报错,并再次检查进程是否在运行。 3. 确保防火墙允许Zabbix Server的端口访问:如果你的服务器开启了防火墙,请确保防火墙允许Zabbix Server的端口通过。默认情况下,Zabbix Server使用端口10051进行通信。你可以使用以下命令添加防火墙规则: ```shell sudo firewall-cmd --zone=public --add-port=10051/tcp --permanent sudo firewall-cmd --reload ``` 确保防火墙规则已成功添加。 4. 检查Zabbix Server的配置文件:确认Zabbix Server的配置文件`zabbix_server.conf`中的相关参数是否正确配置。特别是以下参数: ```conf # Zabbix Server监听的IP地址 ListenIP=0.0.0.0 # Zabbix Server监听的端口 ListenPort=10051 ``` 确保`ListenIP`参数设置为Zabbix Server所在的IP地址,并且`ListenPort`参数设置为正确的端口。 5. 重启Zabbix Server和Web服务器:如果你尝试了以上步骤但仍然无法解决问题,可以尝试重新启动Zabbix Server和Web服务器(例如Apache): ```shell sudo systemctl restart zabbix-server sudo systemctl restart httpd ``` 确保重启命令没有报错,并再次检查Zabbix Server是否在运行。 如果你按照上述步骤检查和调整,仍然无法解决问题,请提供更多详细的错误信息和日志内容,以便进一步帮助你解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值