1. 程式人生 > 其它 >安裝部署zabbix

安裝部署zabbix

部署環境如下:

主機IP:192.168.121.30

系統:此文章以CentOS7.7為例

web應用:Nginx

程序:php7.2

資料庫:mariadb5.5

部署zabbix過程如下:

1.檢查並關閉防火牆

systemctl stop firewalld

systemctl disable firewalld

2.設定SELinux

即使用vim編輯/etc/selinux/config檔案將SELinux型別改為disabled模式並重啟生效

指令碼格式為:

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0

3.安裝nginx,但centos的yum源裡預設沒有nginx的二進位制包,因此需要先安裝epel-release,即fedora的yum源,fedora的源被譽為最全最完善的yum源

yum -y install epel-release

yum -y install nginx

安裝後啟動並設定下次開機啟動systemctl start nginx && systemctl enable nginx

可以使用nginx -v檢視安裝後的nginx版本

4.從zabbix官網下載zabbix的源

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

5.修改zabbix源,使其前端倉庫開機自啟

即使用vim編輯器將/etc/yum.repos.d/zabbix.repo中的zabbix-frontend前端的源改為開機自啟

指令碼格式為:

target1=`cat -n /etc/yum.repos.d/zabbix.repo | grep -A5 "zabbix-frontend" |grep "enabled" | awk '{print $1}'`
sed -i "${target1}s/0/1/" /etc/yum.repos.d/zabbix.repo

6.配置前端源,並安裝下載依賴

yum -y install centos-release-scl

7.安裝server服務
yum -y install zabbix-server-mysql

8.安裝前端元件
yum -y install install zabbix-web-mysql-scl zabbix-nginx-conf-scl

9.安裝並啟動mariadb資料庫
yum -y install mariadb-server
systemctl start mariadb && systemctl enable mariadb

10.使用mysql命令進入mariadb並建立zabbix業務庫、給zabbix使用者授權

create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;

可以將以上命令寫至檔案中作為mysql命令的輸入

即為:

cat >zabbix.txt <<EOF
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
exit

EOF

mysql <zabbix.txt

rm -f zabbix.txt

11.匯入業務到zabbix庫
path1=`rpm -ql zabbix-server-mysql |grep create.sql.gz`
zcat $path1 |mysql zabbix

12.檢視並配置zabbix_server連線資料庫
egrep -v "^#|^$" /etc/zabbix/zabbix_server.conf
echo 'DBPassword=zabbix' >>/etc/zabbix/zabbix_server.conf

13.檢視zabbix-nginx相關配置檔案

path2=`rpm -ql zabbix-nginx-conf-scl`
sed -i 's/#//; s/example.com/192.168.121.30/' $path2

14.配置php
path3=`find /etc -name zabbix.conf |grep php`
target2=`grep "^listen.acl_users" $path3 -n |cut -d: -f1`
target3=`grep "timezone" -n $path3 |cut -d: -f1`
sed -i "${target2}s/apache/apache,nginx/" $path3
sed -i "${target3}s/; //" $path3
sed -i "${target3}s#=.*#= Asia/Shanghai#" $path3

15.重啟服務並設定開機啟動
systemctl restart zabbix-server rh-nginx116-nginx.service rh-php72-php-fpm.service
systemctl enable zabbix-server rh-nginx116-nginx.service rh-php72-php-fpm.service

執行成功後即可使用IP地址訪問搭建好的zabbix頁面,如下圖所示: