Centos7安裝部署zabbix4.0監控服務

1.1 Linux環境說明
zabbix 安裝要求 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements

[root@node2 ~]# cat /etc/redhat-release    查看系統版本信息
CentOS Linux release 7.4.1708 (Core) 
[root@node2 ~]# systemctl stop firewalld.service                關閉防火牆
[root@node2 ~]# systemctl disable firewalld.service 

selinux setenforce 0 臨時關閉
getenforce 結果爲Disabled 爲關閉 檢查selinux是否關閉
1.2 搭建LAMP環境
Zabbix是建立在LAMP或者LNMP環境之上,在此爲了方便就使用yum安裝LAMP環境。

[root@node2 ~]# yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
[root@node2 ~]# rpm -qa httpd php mariadb                           安裝後檢查應用版本
httpd-2.4.6-89.el7.centos.x86_64
mariadb-5.5.60-1.el7_5.x86_64
php-5.4.16-46.el7.x86_64
1
2
3
4
5
1.2.2編輯httpd

[root@node2 ~]# vim /etc/httpd/conf/httpd.conf
95 ServerName www.aihuidi.com:80                             修改主機名,URL
164     DirectoryIndex index.html index.php                  修改首頁文件格式
1
2
3
1.2.3 編輯配置PHP,配置中國時區
[root@node2 ~]# vim /etc/php.ini

 878 date.timezone = PRC
1
1.2.4啓動mysqld

[root@node2 ~]# systemctl start mariadb               啓動數據庫
[root@node2 ~]# systemctl enable mariadb           加入開機自啓動
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@node2 ~]# systemctl status mariadb           查看運行狀態
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-06-13 00:31:21 CST; 11s ago
 Main PID: 2490 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─2490 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─2653 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma...

Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: MySQL manual for more instructions.
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Please report any problems at http://mariadb.org/jira
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: The latest information about MariaDB is available at http://mariadb.org/.
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: You can find additional information about the MySQL part at:
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: http://dev.mysql.com
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Consider joining MariaDB's strong and vibrant community:
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: https://mariadb.org/get-involved/
Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jun 13 00:31:21 node2 systemd[1]: Started MariaDB database server.
[root@node2 ~]# netstat -lntup|grep mysqld                             查看服務端口是否存在
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2653/mysqld   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1.2.5 初始化數據庫,並設置root用戶密碼

[root@node2 ~]# mysqladmin -u root password aihuidi     設置數據庫密碼
[root@node2 ~]# mysql -Uroot -p    登錄數據庫
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;     #創建zabbix數據庫
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;       #刷新權限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | node2     |
| root   | node2     |
+--------+-----------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@localhost;      # 刪除空用戶
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
| root   | localhost |
|        | node2     |
| root   | node2     |
+--------+-----------+
6 rows in set (0.00 sec)

MariaDB [(none)]> 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2、安裝zabbix
安裝依賴包+組件

[root@node2 ~]# yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch  javacc-javadoc.noarch javacc-maven-plugin.noarch javacc*
[root@node2 ~]# yum install php-bcmath php-mbstring -y  #安裝php支持zabbix組件
[root@node2 ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm     安裝zabbix   yum源
[root@node2 ~]# yum install zabbix-server-mysql zabbix-web-mysql -y  安裝zabbix組件
[root@node2 ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.9/create.sql.gz | mysql -uzabbix -p -h 192.168.200.157 zabbix
注意:這裏有可能找不到create.sql.gz  你要看下自己的zabbix-server-mysql-4.0.9這個文件是否在對應的目錄
Enter password: #導入數據到數據庫zabbix中(最後一個zabbix是數據庫zabbix),且因爲用戶zabbix是%(任意主機),所以登錄時需要加上當前主機ip(-h 192.168.200.157)密碼是用戶zabbix登陸密碼zabbix
[root@node2 ~]# vim /etc/zabbix/zabbix_server.conf 配置數據庫密碼

root@node2 ~]# 
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
100:DBName=zabbix
116:DBUser=zabbix
124:DBPassword=zabbix      把註釋打開寫zabbix庫的密碼
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000
[root@node2 ~]# 
[root@node2 ~]# vim /etc/httpd/conf.d/zabbix.conf 修改時區

[root@node2 ~]# systemctl enable zabbix-server      啓動zabbix服務並加入開機自啓動
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@node2 ~]# systemctl start zabbix-server
[root@node2 ~]# systemctl start httpd        啓動httpd服務並加入開機自啓動
[root@node2 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@node2 ~]# 

瀏覽器訪問 http://ip/zabbix

在這裏插入圖片描述

接下來就是關於Zabbix的使用和優化方法了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章