1. 程式人生 > 其它 >Centos7安裝zabbix4.4.1和grafana7.1.1

Centos7安裝zabbix4.4.1和grafana7.1.1

這裡使用的的yum安裝的

先關閉selinux和防火牆,然後重啟伺服器。

安裝zabbix

#下載yum源
wget http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

#安裝原始碼庫
rpm -ivh zabbix-release-4.4-1.el7.noarch.rpm

#安裝Zabbix部署包
yum -y install zabbix-agent zabbix-get zabbix-server-mysql zabbix-sender zabbix-web zabbix-web-mysql

安裝資料庫

#下載mysql原始碼包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

#安裝mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm -y

#安裝MySQL5.7
yum install mysql-community-server -y

#啟動服務
systemctl  enable --now mysqld

#修改root本地登入密碼
#mysql安裝完成之後,在/var/log/mysqld.log檔案中給root生成了一個預設密碼。通過下面的方式找到root預設密碼.
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2021-11-19T17:21:41.433493Z 1 [Note] A temporary password is generated for root@localhost: QjEg/pll6N(c

#登入mysql修改密碼
#mysql5.7預設安裝了密碼安全檢查外掛(validate_password),預設密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.36

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> set password = password('Passwd123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)


#通過msyql環境變數可以檢視密碼策略的相關資訊
mysql> show variables like '%password%';
+----------------------------------------+-----------------+
| Variable_name                          | Value           |
+----------------------------------------+-----------------+
| default_password_lifetime              | 0               |
| disconnect_on_expired_password         | ON              |
| log_builtin_as_identified_by_password  | OFF             |
| mysql_native_password_proxy_users      | OFF             |
| old_passwords                          | 0               |
| report_password                        |                 |
| sha256_password_auto_generate_rsa_keys | ON              |
| sha256_password_private_key_path       | private_key.pem |
| sha256_password_proxy_users            | OFF             |
| sha256_password_public_key_path        | public_key.pem  |
| validate_password_check_user_name      | OFF             |
| validate_password_dictionary_file      |                 |
| validate_password_length               | 8               |
| validate_password_mixed_case_count     | 1               |
| validate_password_number_count         | 1               |
| validate_password_policy               | MEDIUM          |
| validate_password_special_char_count   | 1               |
+----------------------------------------+-----------------+
validate_password_policy:密碼策略,預設為MEDIUM策略 
validate_password_dictionary_file:密碼策略檔案,策略為STRONG才需要 
validate_password_length:密碼最少長度 
validate_password_mixed_case_count:大小寫字元長度,至少1個 
validate_password_number_count :數字至少1個 
validate_password_special_char_count:特殊字元至少1個 

#修改密碼策略
在/etc/my.cnf檔案新增validate_password_policy配置,指定密碼策略
選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2需要提供密碼字典檔案
validate_password_policy=0
如果不需要密碼策略,新增my.cnf檔案中新增如下配置禁用即可
validate_password = off
重新啟動mysql服務使配置生效

修改/etc/my.cnf配置檔案,在[mysqld]下新增編碼配置

vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

#重啟服務,檢視資料庫預設編碼
systemctl restart mysqld

[root@localhost ~]# mysql -uroot -pPasswd123! -e "show variables like '%character%'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

#建立zabbix資料庫及其使用者
mysql -uroot -pPasswd123! -e "create database zabbix default character set utf8 collate utf8_bin"
mysql -uroot -pPasswd123! -e "grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix'"

#測試zabbix使用者是否能夠連線
[root@localhost ~]# mysql -uzabbix -pzabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+

匯入zabbix建庫指令碼

cd /usr/share/doc/zabbix-server-mysql-4.4.10/

zcat create.sql.gz| mysql -uzabbix -pzabbix zabbix

啟動Zabbix Server

在zabbix_server.conf中編輯資料庫配置

vim /etc/zabbix/zabbix_server.conf
#新增配置
DBHost=192.168.248.135
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

#啟動服務
systemctl  enable --now zabbix-server

配置web GUI

#Zabbix前端的Apache配置檔案位於/etc/httpd/conf.d/zabbix.conf 
vim /etc/httpd/conf.d/zabbix.conf
..........................
    <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 max_input_vars 10000
        php_value always_populate_raw_post_data -1
        # php_value date.timezone Europe/Riga  設定時區
        php_value date.timezone Asia/Shanghai #修改時區
        </IfModule>
....................

#啟動服務
systemctl  enable --now httpd

安裝grafana

官方:https://grafana.com/grafana/download

#下載包
 wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.1.1-1.x86_64.rpm

#安裝
yum -y install grafana-enterprise-7.1.1-1.x86_64.rpm 
#啟動服務
systemctl  enable --now grafana-server

測試訪問 ip:300

預設使用者和密碼:admin admin

安裝garfana-zabbix外掛
#過濾出zabbix外掛
[root@localhost ~]# grafana-cli plugins list-remote|grep zabbix
id: alexanderzobnin-zabbix-app version: 4.0.2

#安裝zabbix外掛
grafana-cli plugins install alexanderzobnin-zabbix-app

下載地址https://grafana.com/grafana/plugins/alexanderzobnin-zabbix-app/

[root@localhost ~]# ls /var/lib/grafana/plugins/
alexanderzobnin-zabbix-app-4.0.2.zip

#解壓縮
cd /var/lib/grafana/plugins/
unzip alexanderzobnin-zabbix-app-4.0.2.zip

#重啟grafana服務
 systemctl  restart grafana-server

登入到grafana上,啟用外掛

新增新資料來源

新增資料來源時,會發現找不到zabbix 修改grafana的配置,將zabbix外掛配置允許 找到 “;allow_loading_unsigned_plugins =“ 項,刪掉 “;“ ,加上 “alexanderzobnin-zabbix-datasource“

vim /etc/grafana/grafana.ini
[plugins]
..........
allow_loading_unsigned_plugins = alexanderzobnin-zabbix-datasource

#重啟服務
systemctl  restart grafana-server

再次新增就行

Name自定義,Type選擇Zabbix,Url填寫訪問zabbix-web的url(http://10.0.11.133/zabbix/api_jsonrpc.php),加上zabbix-api的php檔案,Zabbix API details使用者名稱密碼需要在Zabbix-web頁面中設定,也可以使用Zabbix的初始使用者

新增儀表盤

匯入模板

可以通過訪問https://grafana.com/dashboards來檢視已有儀表盤模板,選取合適的使用

我這邊已經匯入了所以會有報錯

應用匯入的模板