CentOS7 企業級分佈式監控系統Zabbix(01)

本次以CentOS 7.2 x64系統爲例php


系統環境html

[root@centos72-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@centos72-node1 ~]# uname -r
3.10.0-327.el7.x86_64
[root@centos72-node1 ~]# uname -m
x86_64
[root@centos72-node1 ~]# hostname
centos72-node1.wangdong.com
[root@centos72-node1 ~]# ifconfig | grep -w "inet" | awk '{print $2}'
192.168.56.51
127.0.0.1


設置yum源和epel源爲阿里java

[root@centos72-node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
......
[root@centos72-node1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
......


安裝Apachenode

[root@centos72-node1 ~]# yum install httpd -y
......


啓動Apachemysql

[root@centos72-node1 ~]# systemctl start httpd


設置開機啓動web

[root@centos72-node1 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.


設置防火牆策略(若不啓用防火牆,此步驟跳過)sql

[root@centos72-node1 ~]# firewall-cmd --permanent --add-service=http
success
[root@centos72-node1 ~]# systemctl restart firewalld


測試Apache(Apache默認使用TCP/80端口,確保沒有其餘程序佔用此端口)數據庫

wKioL1g1DQTQfQxXAAUAlG4Cgok636.jpg


安裝MariaDB(即MySQL)vim

[root@centos72-node1 ~]# yum install mariadb-server mariadb -y
......


啓動MariaDBcentos

[root@centos72-node1 ~]# systemctl start mariadb


設置開機啓動

[root@centos72-node1 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.


初始化MariaDB

[root@centos72-node1 ~]# mysql_secure_installation
......
Enter current password for root (enter for none):    # 輸入MySQL的root原密碼,密碼爲空,直接回車
......

Set root password? [Y/n] Y         # 是否設置root密碼,是
New password:            # 輸入新密碼,我設置123456
Re-enter new password:    # 輸入新密碼,我設置123456
......

Remove anonymous users? [Y/n] Y
......

Disallow root login remotely? [Y/n] n
......
Remove test database and access to it? [Y/n] Y
......
Reload privilege tables now? [Y/n] Y
......


安裝PHP

[root@centos72-node1 ~]# yum install php php-mysql php-gd php-pear -y
......


測試PHP

[root@centos72-node1 ~]# vim /var/www/html/testphp.php    # 建立php測試文件,將下面3行內容寫入文件保存
<?php 
phpinfo();
?>
[root@centos72-node1 ~]# systemctl restart httpd


使用瀏覽器訪問服務器地址的/testphp.php

wKiom1g1DRbjtQXXAALpV6kLPRU340.png


配置zabbix源

[root@centos72-node1 ~]# yum install epel-release -y
......
[root@centos72-node1 ~]# rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
[root@centos72-node1 ~]# rpm -Uv http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
Preparing packages...
zabbix-release-2.4-1.el7.noarch


安裝zabbix和相關

[root@centos72-node1 ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway -y
......


設置zabbix

[root@centos72-node1 ~]# vim /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
    <IfModule mod_php5.c>
        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 date.timezone Asia/Shanghai    # 設置時區爲上海
        # php_value date.timezone Europe/Riga
    </IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
    Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
    Require all denied
</Directory>

[root@centos72-node1 ~]# systemctl restart httpd


MariaDB建立zabbix庫

[root@centos72-node1 ~]# mysql -u root -p123456
......
MariaDB [(none)]> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges 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)]> exit;
Bye
[root@centos72-node1 ~]#


MariaDB導入zabbix模板

[root@centos72-node1 ~]# mysql -u zabbix -pzabbix
......
MariaDB [(none)]> use zabbix;
Database changed
MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/schema.sql
......
MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/p_w_picpaths.sql
......
MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.7/create/data.sql
......
MariaDB [zabbix]> exit;
Bye


配置zabbix server

[root@centos72-node1 ~]# vim /etc/zabbix/zabbix_server.conf
......
DBName=zabbix
......
DBUser=zabbix
......
DBPassword=zabbix
......


配置zabbix agent

[root@centos72-node1 ~]# vim /etc/zabbix/zabbix_agentd.conf
......
Server=127.0.0.1        # 約在85行
......
ServerActive=127.0.0.1    # 約在126行
......
Hostname=127.0.0.1    # 約在137行
......


修改PHP配置

[root@centos72-node1 ~]# vim /etc/php.ini
......
max_execution_time = 600        # 約384行
......
max_input_time = 600        # 約394行
......
memory_limit = 256        # 約405行
......
post_max_size = 32M        # 約672行
......
upload_max_filesize = 16M    # 約800行
......
[date]
......
date.timezone = Asia/Shanghai        # 此項默認沒有配置,須要添加,約880行
......


修改防火牆配置(若沒有開啓防火牆,則忽略)

[root@centos72-node1 ~]# firewall-cmd --permanent --add-port=10050/tcp
success
[root@centos72-node1 ~]# firewall-cmd --permanent --add-port=10051/tcp
success
[root@centos72-node1 ~]# systemctl restart firewalld


重啓服務

[root@centos72-node1 ~]# systemctl start zabbix-server
[root@centos72-node1 ~]# systemctl start zabbix-agent
[root@centos72-node1 ~]# systemctl restart httpd
[root@centos72-node1 ~]# systemctl restart mariadb
[root@centos72-node1 ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@centos72-node1 ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.


配置zabbix,訪問服務器地址的/zabbix/

點擊「Next」按鈕

wKioL1g1DSjTfebKAAF1YTFq_yo409.jpg


檢查各類測試,應所有顯示OK,點擊「Next」

wKioL1g1DT7hNLB5AAHwWnJ0kfI205.jpg


選擇數據庫類型爲MySQL,庫名爲zabbix,用戶名zabbix,密碼我使用的zabbix,點擊「Test connection」,顯示OK後點擊「Next」

wKiom1g1DV3CJ7_TAAHbWEhrsZE593.jpg


輸入Server Name(可選)

wKioL1g1DXKweeQ-AAGSqq4BsGU183.jpg


檢查信息是否有誤,點擊「Next」按鈕

wKioL1g1DYaRfnFVAAHT4PmWWLY083.jpg


配置完成,點擊「Finish」按鈕

wKiom1g1DZahDDK4AAGY3KFQkcw838.jpg


進入Zabbix的管理界面,默認用戶名爲admin,默認密碼爲zabbix

wKioL1g1DarjtMcmAAFMgfdkyfY970.jpg


進入界面後,若是想要使用中文,能夠點擊進入Profile

wKiom1g1DcjRJogKAAMBSmhRx-c666.pngwKioL1g1DdzwzuWqAAHMx8yCMnA518.png

相關文章
相關標籤/搜索