apt安裝zabbix

火火7412發表於2022-02-13

下面介紹基於ubuntu18.04,使用apt在ubuntu安裝zabbix 4.0.x版本。規劃在10.0.0.101主機安裝zabbix server,在10.0.0.104安裝提供msyql服務支援zabbix server。
官網文件

一、安裝zabbix server

1.1 下載deb包

# wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-3+bionic_all.deb
# sudo dpkg -i zabbix-release_4.0-3+bionic_all.deb
# sudo apt update

1.2 安裝Zabbix server,Web前端,agent

# sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent -y

二、準備資料庫

2.1 安裝mysql

# apt update
# sudo apt -y install mysql-server mysql-client #或者安裝mariadb-server,mariadb-client
# vim /etc/mysql/mysql.conf.d/mysqld.cnf
	bind-address	=0.0.0.0		#修改監聽地址
# systemctl enable --now mysql

2.2 建立初始資料庫

# mysql -uroot
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@'10.0.0.%' identified by 'magedu.zabbix';
mysql> grant all privileges on zabbix.* to zabbix@'10.0.0.%';
mysql> quit;
# systemctl restart mysql

2.3 測試資料庫

# apt -y install mysql-client
# mysql -uzabbix -pmagedu.zabbix -h 10.0.0.104
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix	         |
+--------------------+
2 rows in set (0.01 sec)

2.4 初始化資料庫

##匯入基礎資料庫
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pmagedu.zabbix -h 10.0.0.104 zabbix

##在mysql主機檢驗發現生成很多資料庫
mysql> use zabbix;
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
	.....#初始化成功

三、編輯zabbix server配置檔案

編輯配置檔案,指定zabbix的相關資料庫賬戶密碼

# vim /etc/zabbix/zabbix_server.conf
# grep -v  "^#" /etc/zabbix/zabbix_server.conf|grep DB
DBHost=10.0.0.104
DBName=zabbix
DBUser=zabbix
DBPassword=magedu.zabbix
DBPort=3306

四、解決時區問題

# vim /etc/zabbix/apache.conf
 <IfModule mod_php7.c>
 	....
	php_value date.timezone Asia/shanghai

五、啟動服務並訪問web介面

5.1 啟動服務

# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2
# ss -ntl |grep "10050"
LISTEN   0         128                 0.0.0.0:10050            0.0.0.0:*       
LISTEN   0         128                    [::]:10050               [::]:* 
  ....省略.....

5.2 訪問web介面

開啟瀏覽器範文10.0.0.101/zabbix







由此,zabbix serve安裝完成