文章目錄
階段一:準備工作
- 服務器
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源碼配置完成。