一、關閉防火牆和SELinux
[root@zabbix ~]# systemctl stop firewalld
[root@zabbix ~]# systemctl disable firewalld
[root@zabbix ~]# setenforce 0
[root@zabbix ~]# sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config
二、安裝部署LAMP環境
1、安裝LAMP基礎環境,yum需要提前配置好,才不會出現問題
[root@zabbix ~]# yum install -y httpd php php-mysql
2、啟動相關服務、初始化資料庫
①啟動Apache
[root@zabbix ~]# systemctl start httpd
②設定Apache和mariadb開機自啟動
[root@zabbix ~]# systemctl enable httpd
③初始化資料庫
按照之前配置
3、安裝Zabbix
①安裝Zabbix源
[root@zabbix ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm ②導入Zabbix源的秘鑰
[root@zabbix ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
③安裝Zabbix相關服務
[root@zabbix ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
三、啟動Zabbix服務
1、配置Zabbix服務端主配置檔案、并開啟Zabbix服務
①編輯/etc/zabbix/zabbix_server.conf
[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf #僅需修改以下列出部分
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=Admin@123
四、建立和讀入資料庫
①建立資料庫并授權
MySQL [(none)]> use mysql
Database changed
MySQL [mysql]> use zabbix
Database changed
MySQL [zabbix]> create user 'zabbix'@'localhost' identified by 'Admin@123';
Query OK, 0 rows affected (0.11 sec)
MySQL [zabbix]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.01 sec)
MySQL [zabbix]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
②讀入資料庫
[root@zabbix ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.28/
[root@zabbix zabbix-server-mysql-4.0.28]# zcat create.sql.gz | /usr/local/mysql/bin/mysql -uroot -p zabbix
Enter password:
[root@zabbix zabbix-server-mysql-4.0.28]#
# cd /usr/share/doc/zabbix-server-mysql-4.0.28/
# zcat create.sql.gz | /usr/local/mysql/bin/mysql -uroot -p zabbix
③檢查導入的資料庫
# mysql -u root -p
[(none)]> use zabbix
[zabbix]> SHOW TABLES;
[root@zabbix zabbix-server-mysql-4.0.28]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use zabbix
Database changed
mysql> SHOW TABLES;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| items |
| items_applications |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_remote_command |
| task_remote_command_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
144 rows in set (0.00 sec)
mysql>
# vim /etc/zabbix/zabbix_server.conf #僅需修改以下列出部分
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
②開啟zabbix-server服務,并設定為開機自啟動
# systemctl start zabbix-server.service
# systemctl enable zabbix-server.service
2、編輯Zabbix前端PHP配置檔案
# vim /etc/httpd/conf.d/zabbix.conf
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
否則安裝 zabbix web時會報錯誤
3、重新開機Apache服務,同步更新一下系統時間
systemctl restart httpd
ntpdate ntp.sjtu.edu.cn #或者使用cn.pool.ntp.org這個時間同步伺服器 ---因為沒配置這個就不做了
3 Jul 18:53:36 ntpdate[5330]: the NTP socket is in use, exiting
四、安裝Zabbix Web
1、浏覽器通路你的Zabbix伺服器IP(http://IP位址/zabbix),然後點選"Next step"
注意這一步容易出問題,需要配置好my.cnf ,這個配置以後,這個配置
[client]
port = 3306
socket =/var/lib/mysql/mysql.sock 權限問題需要注意
[mysqld_safe]
socket =/var/lib/mysql/mysql.sock 權限問題需要注意
如果配置的時候有可能需要,如果之前socket沒有配置好, ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
參考:
https://blog.csdn.net/one2more/article/details/94619548?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-5.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-5.control