Zabbix5.0Yum安裝


1.1、操作系統配置:

1、操作系統屬性(虛擬機下環境):

(1)操作系統版本:

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)


(2)ip地址:

eth1:僅主機模式——172.16.1.120/24

etho:Nat模式——10.0.0.120/24


(3)核數及內存:

線程數:2核4線程=8線程

內存:8GB


(4)磁盤容量:

sda磁盤:300GB

boot分區:200MB

swap分區:8GB

/(根)分區:剩余所有容量


2、修改主機名:

[root@localhost ~]# hostnamectl set-hostname controlnode

#關閉終端再打開,主機名就會發生改變了。


3、關閉不常用服務:

service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd

auditd chronyd microcode postfix firewalld)

for ((i=0;i<${#service_array[*]};i++)); do

/usr/bin/systemctl stop ${service_array[$i]}

done


service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd

auditd chronyd microcode postfix firewalld)

for ((i=0;i<${#service_array[*]};i++)); do

/usr/bin/systemctl disable ${service_array[$i]}

done


4、關閉selinux:

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

grep "SELINUX=disabled" /etc/selinux/config

setenforce 0

getenforce


5、安裝必備的軟件:

yum install lrzsz dos2unix bash-completion nmap telnet tree wget vim net-tools ntpdate salt-minion git -y


6、配置軟件的安裝源:

(1)配置阿里的yum源:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo


(2)配置阿里的epel源:

yum install epel-release

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

(3)設置yum和epel源的緩存:

yum clean all

yum makecache


(4)查看系統可用的源:

yum repolist enabled


7、修改字符集:

localectl set-locale LANG=zh_CN.UTF-8

source /etc/locale.conf


8、配置時間同步定時任務:

[root@localhost ~]# crontab -e

*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null


9、配置操作系統的文件描述符:

echo '* - nofile 65535' >>/etc/security/limits.conf

ulimit -SHn 65535

ulimit -n


10、優化內核:

cat >>/etc/sysctl.conf<<EOF

net.ipv4.tcp_fin_timeout = 2

net.ipv4.tcp_tw_reuse = 1

#net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_keepalive_time = 600

net.ipv4.tcp_keepalive_probes = 5

net.ipv4.tcp_keepalive_intvl = 15

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_max_tw_buckets =5000

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.core.somaxconn = 16384

net.core.netdev_max_backlog = 16384

net.ipv4.tcp_max_orphans = 16384

EOF


sysctl -p


1.2、配置zabbix5.0的yum源:

1、說明:

zabbix 5.0 版本於 5 月 11 日正式發布,是最新的 LTS(長期支持)版本,5.0 帶來很多功能和特性。

5.0 版本對基礎環境的要求有大的變化,最大的就是對 php 版本的要求,最低要求 7.2.0 版本,對 php

擴展組件版本也有要求,詳見官網文檔

https://www.zabbix.com/documentation/current/manual/installation/requirements


2、安裝阿里雲的zabbix鏡像源:

(1)安裝源:

[root@controlnode ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

[root@controlnode ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo


(2)啟用 zabbix 前端源,修改/etc/yum.repos.d/zabbix.repo,將[zabbix-frontend]下的 enabled 改為 1:

[zabbix-frontend]

name=Zabbix Official Repository frontend - $basearch

baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591


(3)清除yum源之前的緩存:

[root@controlnode ~]# yum clean all


3、驗證yum源:

[root@controlnode ~]# yum list | grep zabbix


1.3、安裝zabbix-server、zabbix-agent、zabbix-get:

[root@controlnode ~]# yum install zabbix-server-mysql zabbix-agent zabbix-get -y


1.4、安裝 Software Collections,便於后續安裝高版本的 php,默認 yum 安裝的 php 版本為 5.4 過低:

[root@controlnode ~]# yum install centos-release-scl -y


1.5、安裝 zabbix 前端和相關環境:

[root@controlnode ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y


1.6、到此zabbix相關軟件安裝完成,查看安裝的zabbix軟件:

[root@controlnode ~]# rpm -qa | grep zabbix

zabbix-server-mysql-5.0.0-1.el7.x86_64

zabbix-get-5.0.0-1.el7.x86_64

zabbix-web-mysql-scl-5.0.0-1.el7.noarch

zabbix-release-5.0-1.el7.noarch

zabbix-agent-5.0.0-1.el7.x86_64

zabbix-web-5.0.0-1.el7.noarch

zabbix-web-deps-scl-5.0.0-1.el7.noarch

zabbix-apache-conf-scl-5.0.0-1.el7.noarch


1.7、安裝mariadb數據庫:

1、安裝:

[root@controlnode ~]# yum install mariadb-server -y


2、優化my.cnf參數:/etc/my.cnf【2核4G的配置】:

#清空/etc/my.cnf文件中的內容,復制下面全部的參數到/etc/my.cnf中:

[client]

port=3306

default-character-set=utf8

socket=/var/lib/mysql/mysql.sock

[mysql]

no-auto-rehash

[mysqld]

user=mysql

port=3306

socket=/var/lib/mysql/mysql.sock

basedir=/usr

datadir=/var/lib/mysql

open_files_limit = 10240

symbolic-links=0

default-storage-engine = innodb

innodb_file_per_table = on

max_connections = 1000

max_connect_errors = 6000

back_log = 600

table_open_cache = 614

skip-external-locking

max_allowed_packet = 32M

character-set-server = utf8

skip-name-resolve

innodb_buffer_pool_size = 1024M

query_cache_size=16M

join_buffer_size = 2M

query_cache_limit = 4M

query_cache_min_res_unit = 2K

thread_stack = 192K

tmp_table_size = 64M

max_heap_table_size = 64M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

bulk_insert_buffer_size = 16M

key_buffer_size = 384M

server-id = 1

thread_concurrency = 4

thread_cache_size = 64

sort_buffer_size = 2M

slow_query_log = ON

long_query_time = 2

slow_query_log_file = /tmp/mysql-slow.log

innodb_thread_concurrency = 2

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 16M

innodb_log_file_size = 128M

lower_case_table_names = 1

innodb_additional_mem_pool_size = 16M

innodb_data_file_path = ibdata1:1024M:autoextend

innodb_file_io_threads = 4

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

innodb_write_io_threads = 2

innodb_read_io_threads = 2

sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

transaction_isolation = READ-COMMITTE

[mysqldump]

quick

max_allowed_packet = 32M

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid


3、啟動mariadb數據庫,並開機自啟動:

[root@controlnode ~]# systemctl start mariadb.service

[root@controlnode ~]# systemctl enable mariadb.service

[root@controlnode ~]# netstat -tunlp | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17226/mysqld


4、初始化Mariadb,並配置root密碼:

[root@controlnode ~]# mysql_secure_installation

#root密碼為 zabbix5.0@lc


5、創建zabbix庫:

[root@controlnode ~]# mysql -uroot -pzabbix5.0@lc

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@"%" identified by "zabbix5.0@lc";

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> quit;


6、初始化 zabbix 數據庫:

[root@controlnode ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -pzabbix5.0@lc zabbix

#驗證數據是否導入成功

[root@controlnode ~]# mysql -uroot -pzabbix5.0@lc -e "use zabbix;show tables"


1.8、修改/etc/zabbix/zabbix_server.conf連接數據庫的配置:

DBHost=127.0.0.1

DBPassword=zabbix5.0@lc


1.9、修改 zabbix 的 php 配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的時區:

php_value[date.timezone] = Asia/Shanghai


1.10、解決zabbix-web中文亂碼的問題:

1、查看zabbix-web鏈接的字體:

[root@controlnode ~]# ls -l /etc/alternatives/zabbix-web-font

lrwxrwxrwx 1 root root 38 6月 16 12:59 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf


2、在windows中找到需要的字體格式后上傳到"/usr/share/fonts/dejavu/"目錄下:

(1)在windows中查找需要的字體:


(2)將字體上傳到"/usr/share/fonts/dejavu/"目錄下:

[root@controlnode ~]# cd /usr/share/fonts/dejavu/

[root@controlnode dejavu]# rz -y


(3)對舊的字體備份后進行替換:

1)備份舊的字體:

[root@controlnode dejavu]# cp -a DejaVuSans.ttf DejaVuSans.ttf.bak

2)替換字體:

[root@controlnode dejavu]# \mv simkai.ttf DejaVuSans.ttf


1.11、啟動zabbix相關服務並設置為開機自啟動:

[root@controlnode ~]# systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm

[root@controlnode ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm


1.12、在頁面中配置連接:

1、訪問zabbix-server的配置頁面,點擊下一步:

http://172.16.1.120/zabbix/setup.php


2、點擊下一步:


3、配置mysql數據庫地址和密碼,點擊下一步:


4、配置zabbixServer的連接地址和zabbixServer的名稱(可選):


5、點擊下一步:


6、配置完成:


7、ZabbixSever安裝完成后,和ZabbixServer安裝在同一台服務器的zabbixAgent在啟動的情況下,會被ZabbixServer

添加為第一台主機,名為"Zabbix server"。


1.13、zabbixServer其它相關配置:

1、user settings 相關設置:


(1)調整前端網頁為中文字體和網頁的刷新時間:


(2)啟用前端網頁報警提示信息:


2、修改默認的 Web 訪問URL:

[root@controlnode ~]# sed -i 's#DocumentRoot "/var/www/html"#DocumentRoot "/usr/share/zabbix"#g' /etc/httpd/conf/httpd.conf

[root@controlnode ~]# systemctl restart httpd

這樣就可以通過http://172.16.1.120直接訪問zabbix監控頁面了。


3、監控zabbixServer自身所使用的數據庫:

(0)Template DB MySQL模板宏和監控項:

1)宏:


2)監控項:


(1)復制MySQL監控模板到/etc/zabbix/zabbix_agentd.d/目錄下:

[root@controlnode ~]# cp -a /usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/


(2)修改MySQL監控模板內容如下所示(比原文件增加了"-uzbx_monitor -pzabbix5.0@lc"參數):

[root@controlnode ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2

#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)

#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5

.7/en/option-files.html#The file must have three strings:

#[client]

#user=zbx_monitor

#password=<password>

#

UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc ping

UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc -sNX -e "show global status"

UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc version

UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc -sN -e "show databases"

UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABL

ES WHERE TABLE_SCHEMA='$3'"UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc -sNX -e "show slave status"

UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -uzbx_monitor -pzabbix5.0@lc -sNX -e "show slave status"


(3)重啟zabbix-agent:

[root@controlnode ~]# systemctl restart zabbix-agent.service


(4)找到Template DB MySQL模板,根據提示在要監控的mysql數據庫上創建監控用戶並賦權:

[root@controlnode ~]# mysql -uroot -pzabbix5.0@lc

MariaDB [(none)]> CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY 'zabbix5.0@lc';

MariaDB [(none)]> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';

MariaDB [(none)]> quit;


(5)在Zabbix server主機中添加Template DB MySQL模板:


(6)修改Zabbix server主機的宏,mysql IP地址改為127.0.0.1:


(7)修改Template DB MySQL模板的自動發現時間間隔,改為1m(默認時1h),方便快速得到自動發現中的監控項,得到結果后再將時間改回來即可:

自動發現中包括,數據庫使用大小的監控項和數據庫主從復制監控的監控項,如果有不支持的監控項不會報警,支持的監控項如果異常會報警。


(8)查看檢測mysql的最新數據:


1.14、zabbixServer優化操作:

說明:以上zabbixServer和zabbixAgent的配置參數都是默認,如果監控負載過高,對相關參數進行優化,如下:

1、/etc/zabbix/zabbix_server.conf:

#線程-吞吐量

StartPollers=10

StartPollersUnreachable=10

StartTrappers=10

StartPingers=10

StartDiscoverers=10

StartHTTPPollers=10

StartTimers=10

StartEscalators=10

StartAlerters=10

#緩存

CacheSize=256M

CacheUpdateFrequency=60

StartDBSyncers=10

HistoryCacheSize=256M

HistoryIndexCacheSize=256M

TrendCacheSize=256M

ValueCacheSize=256M

Timeout=15

TrapperTimeout=200


2、/etc/zabbix/zabbix-agent:

#線程-吞吐量

StartAgents=10

#緩存

RefreshActiveChecks=120

BufferSend=10

BufferSize=100

Timeout=15
























免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM