基於CentOS 7下最小化安裝的操做系統搭建Zabbix3.0環境

環境說明

系統版本:CentOS Linux release 7.3.1611 (Core)
內核版本:3.10.0-514.el7.x86_64
Httpd版本:Apache/2.4.6 (CentOS)
MariaDB版本:5.5.52-MariaDB
PHP版本:PHP 5.4.16

環境準備

[root@master ~]# setenforce 0
[root@master ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@master ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@master ~]# yum install epel-release.noarch wget vim gcc gcc-c++ lsof chrony tree nmap unzip rsync -y
[root@master ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

基於LAMP環境的Zabbix3.0


LAMP環境安裝

[root@master ~]# yum install httpd mariadb mariadb-server mariadb-client php php-mysql

安裝Zabbix服務

[root@master ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
[root@master ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
[root@master ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent

建立數據庫

[root@master ~]# mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
MariaDB [(none)]> GRANT ALL ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
MariaDB [(none)]> quit

導入數據

[root@master ~]# cd /usr/share/doc/zabbix-server-mysql-3.0.3/
[root@master zabbix-server-mysql-3.0.3]# zcat create.sql.gz | mysql -uroot -p zabbix
[root@master zabbix-server-mysql-3.0.3]# cd

修改配置

[root@master ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

上述配置文件中,咱們只須要關注DBHost、DBName、DBUser、DBPassword幾項便可。這幾項是配置zabbix server鏈接mysql數據庫的參數。php

[root@master ~]# vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Chongqing

其中php_value date.timezone Asia/Chongqing主要是定義php的時區html

啓動

[root@master ~]# systemctl start httpd
[root@master ~]# systemctl start zabbix-server
[root@master ~]# systemctl start zabbix-agent

經過 http://ip/zabbix 訪問
默認用戶名/密碼:Admin/zabbix,注意用戶名也區分大小寫node

# 配置中重寫了訪問路徑
[root@master ~]# vim /etc/httpd/conf.d/zabbix.conf
Alias /zabbix /usr/share/zabbix

基於LNMP環境的Zbbix3.0


LNMP環境安裝

[root@master ~]# yum install nginx mariadb mariadb-server mariadb-client php php-mysql php-fpm -y
/run/php-fpm/php-fpm.pid

安裝Zabbix服務

[root@master ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
[root@master ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
[root@master ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent

修改文件屬主和屬組

zabbix的rpm包裏默認編譯apache爲文件擁有者,把httpd服務替換爲nginx服務,相應文件的擁有者須要進行對應的更改。mysql

[root@master ~]# ll /etc/zabbix/
total 28
drwxr-x---. 2 apache apache    32 Apr 20 09:41 web
-rw-r--r--. 1 root   root   10341 Apr 20  2016 zabbix_agentd.conf
drwxr-xr-x. 2 root   root      37 Apr 20 09:41 zabbix_agentd.d
-rw-r-----. 1 root   zabbix 14876 Apr 20  2016 zabbix_server.conf
[root@master ~]# chown nginx:nginx /etc/zabbix/web/
[root@master ~]# ll -d /var/log/php-fpm
drwxrwx---. 2 apache root 6 Jun 23  2015 /var/log/php-fpm
[root@master ~]# chown nginx /var/log/php-fpm
[root@master ~]# ll -d /var/log/php-fpm
drwxrwx---. 2 apache root 22 Apr 20 09:53 /var/log/php-fpm
[root@master ~]# ll -d /var/lib/php/session
drwxrwx---. 2 root apache 44 Apr 20 10:22 /var/lib/php/session
[root@master ~]# chown root:nginx /var/lib/php/session/
[root@master ~]# ll -d /var/lib/php/session
drwxrwx---. 2 root nginx 44 Apr 20 10:28 /var/lib/php/session
[root@master ~]# cp -r /usr/share/zabbix /var/www
[root@master ~]# chown nginx:nginx -R /var/www/zabbix

修改php配置

[root@master ~]# sed -i 's/^user = .*/user = nginx/' /etc/php-fpm.d/www.conf
[root@master ~]# sed -i 's/^group = .*/group = nginx/' /etc/php-fpm.d/www.conf
[root@master ~]# sed -i 's/^;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini
[root@master ~]# sed -i 's/^post_max_size =.*/post_max_size = 16M/' /etc/php.ini
[root@master ~]# sed -i 's/^max_execution_time =.*/max_execution_time = 300/' /etc/php.ini
[root@master ~]# sed -i 's/^max_input_time =.*/max_input_time = 300/' /etc/php.ini

建立數據庫

[root@master ~]# mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
MariaDB [(none)]> GRANT ALL ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
MariaDB [(none)]> quit

導入數據

[root@master zabbix-server-mysql-3.0.3]# cd /usr/share/doc/zabbix-server-mysql-3.0.3/
[root@master zabbix-server-mysql-3.0.3]# zcat create.sql.gz | mysql -uroot -p zabbix
[root@master zabbix-server-mysql-3.0.3]# cd

配置nginx虛擬主機

[root@master ~]# cat /etc/nginx/conf.d/zabbix.conf
server {
    root /var/www;
    index index.php index.html;
    access_log   /var/log/nginx/access_zabbix.log;
    error_log   /var/log/nginx/error_zabbix.log;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    }
}

YUM安裝的nginx服務,主配置文件裏有server項配置,須要進行註銷linux

[root@master ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
[root@master ~]# sed -i '35,54s/^/#/' /etc/nginx/nginx.conf
[root@master ~]# vim /etc/nginx/nginx.conf
[root@master ~]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

#    server {
#        listen       80 default_server;
#        listen       [::]:80 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }
}

啓動服務

[root@master ~]# systemctl start mariadb
[root@master ~]# systemctl start php-fpm
[root@master ~]# systemctl start nginx
[root@master ~]# systemctl start zabbix-server

Zabbix Agent


Zabbix Agent安裝

[root@client01 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
[root@client01 ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[root@client01 ~]# yum install zabbix-agent

配置修改

[root@client01 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.60.103
ServerActive=192.168.60.103
Hostname=client01

啓用Zabbix Agent

[root@client01 ~]# systemctl start zabbix-agent

Zabbix-Get的使用

Zabbix-Get是Zabbix中的一個應用程序,用於Zabbix-Server到Zabbix-Agent的數據獲取,一般能夠用來測試Agent的配置是否正確。nginx

使用幫助c++

usage:
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address] -k item-key
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address]
                --tls-connect cert --tls-ca-file CA-file
                [--tls-crl-file CRL-file] [--tls-agent-cert-issuer cert-issuer]
                [--tls-agent-cert-subject cert-subject]
                --tls-cert-file cert-file --tls-key-file key-file -k item-key
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address]
                --tls-connect psk --tls-psk-identity PSK-identity
                --tls-psk-file PSK-file -k item-key
  zabbix_get -h
  zabbix_get -V

測試 Agent 配置git

[root@master zabbix-server-mysql-3.0.3]# zabbix_get -s 192.168.60.104 -k system.uname
Linux client01 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64

zabbix用戶忘記密碼

進入數據庫直接更改密碼github

[root@master ~]# mysql -uroot -p

MariaDB [(none)]> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

MariaDB [zabbix]> select userid, alias, name, passwd from users;
+--------+-------+--------+----------------------------------+
| userid | alias | name   | passwd                           |
+--------+-------+--------+----------------------------------+
|      1 | Admin | Zabbix | *DEEF4D7D88CD046ECA02A80393B7780 |
|      2 | guest |        | d41d8cd98f00b204e9800998ecf8427e |
+--------+-------+--------+----------------------------------+
2 rows in set (0.00 sec)

MariaDB [zabbix]> update users set passwd=md5('zabbix') where userid='1';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

Grafana 2.6

[root@master ~]# yum install https://grafanarel.s3.amazonaws.com/builds/grafana-2.6.0-1.x86_64.rpm
[root@master ~]# systemctl start grafana-server
[root@master ~]# yum install https://grafanarel.s3.amazonaws.com/builds/grafana-2.6.0-1.x86_64.rpm
[root@master ~]# cp -r grafana-zabbix-2.5.1/zabbix/  /usr/share/grafana/public/app/plugins/datasource/
[root@master ~]# systemctl restart grafana-server

[root@master ~]# mkdir /var/lib/grafana/plugins
[root@master ~]# cd /var/lib/grafana/plugins
[root@master plugins]# git clone https://github.com/alexanderzobnin/grafana-zabbix-app
[root@master plugins]# cd grafana-zabbix-app/
[root@master grafana-zabbix-app]# git pull
[root@master grafana-zabbix-app]# systemctl restart grafana-server

CentOS 7下最小化安裝系統之快速部署Zabbix3.0測試環境

基於LAMP環境的Zabbix3.0測試環境

# 初始環境調整
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install epel-release.noarch wget vim gcc gcc-c++ lsof chrony tree nmap unzip rsync -y
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

# LAMP環境部署
yum install httpd mariadb mariadb-server mariadb-client php php-mysql -y

systemctl start mariadb

# MariaDB數據庫安全調整
mysql -e "DELETE FROM mysql.user WHERE User=''"
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')"
mysql -e "DROP DATABASE test;"
mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
mysql -e "FLUSH PRIVILEGES"

# 建立Zabbix服務端的數據庫和使用的帳號
mysql -e "CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -e "GRANT ALL ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';"

# Zabbix應用部署
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
yum install zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent -y

# 導入Zabbix服務端的表結構
cd /usr/share/doc/zabbix-server-mysql-3.0.3/
zcat create.sql.gz | mysql -uroot zabbix
cd

sed -i '/^# DBPassword=/a \\nDBPassword=zabbix' /etc/zabbix/zabbix_server.conf

#sed -i 's/^;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini
sed -i 's@# \(php_value date.timezone \).*@\1Asia/Shanghai@' /etc/httpd/conf.d/zabbix.conf

systemctl start httpd
systemctl start zabbix-agent
systemctl start zabbix-server

經過 http://ip/zabbix 訪問 默認用戶名/密碼:Admin/zabbixweb

基於LNMP環境的Zabbix3.0測試環境

# 初始環境調整
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install epel-release.noarch wget vim gcc gcc-c++ lsof chrony tree nmap unzip rsync -y
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

# LNMP環境部署
yum install nginx mariadb mariadb-server mariadb-client php php-mysql php-fpm -y
cat > /etc/nginx/conf.d/zabbix.conf << \EOF
server {
    root /var/www;
    index index.php index.html;
    access_log  /var/log/nginx/access_zabbix.log;
    error_log   /var/log/nginx/error_zabbix.log;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    }
}
EOF

sed -i '35,54s/^/#/' /etc/nginx/nginx.conf
sed -i 's/^;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini
sed -i 's/^post_max_size =.*/post_max_size = 16M/' /etc/php.ini
sed -i 's/^max_execution_time =.*/max_execution_time = 300/' /etc/php.ini
sed -i 's/^max_input_time =.*/max_input_time = 300/' /etc/php.ini
sed -i 's/^user = .*/user = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/^group = .*/group = nginx/' /etc/php-fpm.d/www.conf
chown nginx /var/log/php-fpm
systemctl start mariadb
# MariaDB數據庫安全調整
mysql -e "DELETE FROM mysql.user WHERE User=''"
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')"
mysql -e "DROP DATABASE test;"
mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
mysql -e "FLUSH PRIVILEGES"
# 建立Zabbix服務端的數據庫和使用的帳號
mysql -e "CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -e "GRANT ALL ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';"
# Zabbix應用部署
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
yum install zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent -y
# 導入Zabbix服務端的表結構
cd /usr/share/doc/zabbix-server-mysql-3.0.3/
zcat create.sql.gz | mysql -uroot zabbix
cd
# 文件權限修改
chown nginx:nginx -R /etc/zabbix/web/
cp -r /usr/share/zabbix /var/www
chown nginx:nginx -R /var/www/zabbix
chown root:nginx /var/lib/php/session
sed -i '/^# DBPassword=/a \\nDBPassword=zabbix' /etc/zabbix/zabbix_server.conf
systemctl start nginx
systemctl start php-fpm
systemctl start zabbix-agent
systemctl start zabbix-server

經過 http://ip/zabbix 訪問 默認用戶名/密碼:Admin/zabbix

Zabbix Agent快速部署

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install vim lsof chrony -y
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
yum install zabbix-agent -y
sed -i 's/^Server=.*/Server=192.168.60.103/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^ServerActive=.*/ServerActive=192.168.60.103/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^Hostname=.*/Hostname=client01/' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent

從安全角度,作以下改進:1. 保持 /var/www/zabbix 目錄的user和group均爲root,不容許nginx用戶寫入。使用符號連接替代目錄拷貝,用於提供nginx服務。# ln -s /var/www/zabbix /var/www/2. Zabbix 頁面初始化結束後,生成的配置文件應及時去掉可寫權限,並去掉other的可讀權限:# chown nginx:nginx /etc/zabbix/web/zabbix.conf.php# chmod 600 /etc/zabbix/web/zabbix.conf.php

相關文章
相關標籤/搜索