文章目录
阶段一:准备工作
- 服务器
Centos 7.4 zabbix-100 192.168.44.100 4核8G
- 相关资源
- 资源链接:https://pan.baidu.com/s/1B6y_-_3UMoXzmzM-cqe1rg 提取码:lbg6
- 资源链接: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/
- 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源码配置完成。