CentOS7安裝及配置 Zabbix全步驟,超詳細教程

林諾歐巴發表於2022-02-24

伺服器太多,還在不同的平臺和賬戶,監控不便

整個 Zabbix 監控,開始吧

 

一、關閉防火牆並開機不啟動

sudo setenforce 0
sudo sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

 

二、安裝部署 Zabbix 服務端

  1、安裝配置 Zabbix 專用 yum 源

sudo rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sudo yum clean all
sudo yum makecache fast

 

  2、安裝 Zabbix 服務端元件

sudo yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get --nogpgcheck

  安裝過程可能會報錯,zabbix版本衝突,是因為epel源裡也有zabbix

Transaction check error:
file /usr/bin/zabbix_get conflicts between attempted installs of zabbix-get-5.0.19-1.el7.x86_64 and zabbix40-4.0.36-1.el7.x86_64
file /usr/share/man/man1/zabbix_get.1.gz conflicts between attempted installs of zabbix-get-5.0.19-1.el7.x86_64 and zabbix40-4.0.36-1.el7.x86_64

Error Summary

  epel源改名即可解決,重新執行 Zabbix 服務端元件命令即可

cd /etc/yum.repos.d/
sudo mv epel.repo epel-bak

 

  3、安裝 Zabbix 前端元件

sudo yum -y install centos-release-scl

  編輯配置檔案

sudo vi /etc/yum.repos.d/zabbix.repo

# 將其設為1
[zabbix-frontend]
...
enabled=1
...

 

  4、安裝 Zabbix 前端頁面、初始資料庫、php及httpd元件

sudo yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl

 

三、安裝配置 MySQL 

  1、安裝 yum 源

sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

 

  2、安裝MySQL元件

sudo yum -y install yum-utils
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
sudo yum install mysql-community-server -y

 

  3、安裝配置MySQL

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
sudo tar zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/

sudo mv mysql-5.7.32-linux-glibc2.12-x86_64/ mysql 
cd mysql 

sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 
#這一步需記住列印的臨時密碼
sudo cp support-files/mysql.server /etc/init.d/mysqld -r 
sudo vim
/usr/local/mysql/my.cnf [mysqld]
datadir
=/usr/local/mysql/data basedir=/usr/local/mysql user=mysql socket=/usr/local/mysql/var/mysql.sock ## Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 ## instructions in http://fedoraproject.org/wiki/Systemd #[mysqld_safe] log-error=/usr/local/mysql/var/log/mysql/mysql.log pid-file=/usr/local/mysql/var/run/mysql/mysql.pid [client] port=3306 socket=/usr/local/mysql/var/mysql.sock

  

  4、建立資料夾及檔案,並授權

sudo mkdir /usr/local/mysql/var/log/mysql
sudo mkdir /usr/local/mysql/var/run/mysql

sudo touch /usr/local/mysql/var/log/mysql/mysql.log
sudo touch /usr/local/mysql/var/run/mysql/mysql.pid

sudo chown -R mysql:mysql /usr/local/mysql/var/

  

  5、啟動 MySQL

sudo /etc/init.d/mysqld start

 

  6、對映連結

sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
sudo ln -s /usr/local/mysql/var/mysql.sock /tmp/mysql.sock

  

  7、登入MySQL

mysql -uroot -p
# 輸入臨時密碼

 

  8、修改密碼並授權

ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwe123'; //單引號內自行設定
create database zabbix character set utf8 collate utf8_bin; //建立zabbix庫 create user zabbix@localhost identified by 'Zabbix666'; //建立zabbix資料庫使用者、密碼 grant all privileges on zabbix.* to zabbix@localhost; //設定zabbix使用者對zabbix資料庫具有本地管理許可權

  

  9、開啟遠端訪問

use mysql;
update user set host='%' where user='root';
update user set host='%' where user='zabbix';
flush privileges;  //重新整理
quit; // 退出

 

  10、匯入初始資料

sudo zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p'qwe123' zabbix

 

四、初始化 Zabbix 配置

  1、配置資料庫連線

sudo vim /etc/zabbix/zabbix_server.conf

  根據實際情況配置資料庫連線

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=qwe123
DBPort=3306

  

  2、設定時區

sudo vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

  去掉 php_value[date.timezone] = 前面的分號,填上海時區

php_value[date.timezone] = Asia/Shanghai

 

  3、設定字型,避免前臺中文亂碼

sudo yum -y install wqy-microhei-fonts
sudo mv /usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf.bak
sudo cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

 

  4、設定 Zabbix 及其相關服務開機啟動

systemctl restart zabbix-server httpd rh-php72-php-fpm
systemctl enable zabbix-server  httpd rh-php72-php-fpm

 

  5、初始化安裝介面

瀏覽器訪問 http://你的IP/zabbix

 

   連續2次 Next step,輸入MySQL密碼

 

   一直 Next step 就好了,預設使用者名稱是Admin,密碼是zabbix

  

  6、漢化

 

 

 

 到這裡 Zabbix server就安裝完成了,客戶端安裝 zabbix agent 下回分解 

 

相關文章