CentOS 7上yum安裝Zabbix 3.0(單機版)

01、最小化安裝操作系統(tǒng),推薦 x86_64 版本

02、升級系統(tǒng)組件到最新版本
yum -y update

03、關(guān)閉 SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

04、關(guān)閉防火墻
systemctl stop firewalld.service && systemctl disable firewalld.service

05、開啟端口(如果已執(zhí)行了第4步,則第5步可忽略。如果有信息安全合規(guī)要求,不能直接關(guān)閉防火墻,則跳過第4步,執(zhí)行第5步)
firewall-cmd --zone=public --list-interfaces
firewall-cmd --zone=public --permanent --add-interface=eth0
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10050/udp --permanent
firewall-cmd --set-default-zone=public
firewall-cmd --complete-reload

06、增加 nproc 和 nofile 的上限值
vi /etc/security/limits.conf,增加以下內(nèi)容
*? ? ?soft? ? ?nproc? ? 65535
*? ? ?hard? ? nproc? ? 65535
*? ? ?soft? ? ?nofile? ? 65535
*? ? ?hard? ? nofile? ? 65535

07、修改 vm.swappiness 的值
vi /etc/sysctl.conf,增加以下內(nèi)容
vm.swappiness = 1

08、安裝 MariaDB 源
vi /etc/yum.repos.d/MariaDB.repo,增加以下內(nèi)容
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

09、安裝 zbx 所需軟件支持包
yum -y install ntsysv wget telnet net-tools python-paramiko php php-mysqlnd php-gd libjpeg* php-snmp php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-common httpd gcc gcc-c++ dejavu-sans-fonts python-setuptools python-devel sendmail mailx pcre-devel net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC unixODBC-devel MariaDB-server MariaDB-client MariaDB-devel?MySQL-python vim?epel-release?xorg-x11-xauth tree?deltarpm

10、停止并卸載 postfix
systemctl disable postfix.service && rpm -e --nodeps postfix

11、啟動 MariaDB
systemctl enable mariadb && systemctl start mariadb

12、進行 MariaDB 安全配置,除了修改為自定義密碼(第 14 步設(shè)置 MariaDB 參數(shù)時會用到),其它選項選擇 y 即可
mysql_secure_installation

13、配置相關(guān)參數(shù)
mkdir -p /etc/systemd/system/mariadb.service.d/
vim /etc/systemd/system/mariadb.service.d/limits.conf,增加以下內(nèi)容
[Service]
LimitNOFILE=65535

systemctl daemon-reload
systemctl stop mariadb
systemctl start mariadb

14、設(shè)置 MariaDB 參數(shù)(以 8GB 內(nèi)存為例)
vim /etc/my.cnf.d/server.cnf,在 [mysqld] 字段下增加以下內(nèi)容

port=3306
socket=/var/lib/mysql/mysql.sock
user=mysql

character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
character-set-client-handshake=0
init_connect='SET NAMES utf8mb4'

max_connections=1000
connect_timeout=60
wait_timeout=600
interactive_timeout=600
lock_wait_timeout=3600
skip_name_resolve=1
skip_external_locking=1
open_files_limit=65535
explicit_defaults_for_timestamp=1
pid_file=zabbix.pid
log_error=zabbix.err
slow_query_log=1
slow_query_log_file=zabbix.slow
thread_concurrency=16
key_buffer_size=1M
read_buffer_size=4M
read_rnd_buffer_size=2M
table_open_cache=1024
table_definition_cache=2000
table_open_cache_instances=64
thread_cache_size=512
sort_buffer_size=4M
join_buffer_size=4M
bulk_insert_buffer_size=128M
tmp_table_size=32M
max_heap_table_size=32M
query_cache_limit=0
query_cache_size=0
symbolic-links=0
max_allowed_packet=32M
bind-address=0.0.0.0

# 如果需要開啟復(fù)制或搭建高可用,則以下 7 行內(nèi)容需要啟用,否則禁用
#log_bin = mariadb1-bin
#binlog_format = ROW
# 如果對數(shù)據(jù)完整性要求高,則 sync_binlog = 1
#sync_binlog = 0
#binlog_cache_size = 4M
#max_binlog_cache_size = 1G
#max_binlog_size = 1G
#expire_logs_days = 7

innodb_buffer_pool_size=6G
innodb_buffer_pool_instances=8
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_dump_at_shutdown=1
innodb_log_file_size=1G
innodb_log_buffer_size=32M
innodb_log_files_in_group=2
# 如果對數(shù)據(jù)完整性要求高,則 innodb_flush_log_at_trx_commit =?1
innodb_flush_log_at_trx_commit=2
innodb_lock_wait_timeout=10
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
innodb_thread_concurrency=0
innodb_flush_method=O_DIRECT
innodb_io_capacity=10000
innodb_io_capacity_max=20000
innodb_purge_threads=1
innodb_page_cleaners=1
innodb_open_files=65535
innodb_max_dirty_pages_pct=50
innodb_lru_scan_depth=4000
innodb_status_file=1
innodb_change_buffer_max_size=50
innodb_sync_spin_loops=288
innodb_write_io_threads=16
innodb_read_io_threads=16
innodb_random_read_ahead=OFF
innodb_file_format=Barracuda
innodb_strict_mode=0
innodb_file_per_table=1

thread_handling=pool-of-threads
thread_pool_oversubscribe=30
thread_pool_size=64
thread_pool_idle_timeout=3600
thread_pool_max_threads=2000

# 有性能監(jiān)控要求的,則開啟以下參數(shù),否則禁用
performance_schema = 1
performance_schema_instrument = '%=on'

innodb_monitor_enable = "module_srv"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_buf_page"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_file"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_adaptive_hash"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_icp"
innodb_monitor_enable = "module_metadata"

vim /etc/my.cnf.d/mysql-clients.cnf,在 [mysql]?字段下增加以下內(nèi)容
prompt = "\U[\R:\m][\d]> "
no-auto-rehash
default-character-set = utf8mb4
user=root
password=Qingdao,2018 # 此處就是第 12 步設(shè)置的 MariaDB root 密碼

在 [mysqldump]?字段下增加以下內(nèi)容
quick

注:
1、原則上 innodb_buffer_pool_size 需要設(shè)置為主機內(nèi)存的 80%,如果主機內(nèi)存不是 8GB,以上參數(shù)可依據(jù)相應(yīng)比例進行調(diào)整,例如主機內(nèi)存為 16GB,則 innodb_buffer_pool_size 建議設(shè)置為 12GB。請注意innodb_buffer_pool_size的值必須是整數(shù),例如主機內(nèi)存是4G,那么innodb_buffer_pool_size可以設(shè)置為3G,而不能設(shè)置為3.2G
2、本設(shè)置以提升數(shù)據(jù)庫性能為目標,降低了數(shù)據(jù)安全性。如果要保證數(shù)據(jù)安全,需對部分參數(shù)進行調(diào)整,具體請參考 MariaDB 官方文檔中的相關(guān)內(nèi)容,本文不展開討論

15、配置 MariaDB 中 zbx 所需要的庫和賬號權(quán)限
systemctl start mariadb
mysql
mysql>create database zabbix character set utf8 collate utf8_bin;
mysql>create user zabbix@'localhost' identified by 'Qingdao,2018';
mysql>grant all privileges on zabbix.* to zabbix@'localhost';
mysql>flush privileges;
mysql>exit;

16、安裝 zbx 源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

17、安裝 zbx
yum -y install zabbix-server-mysql zabbix-web-mysql

18、導(dǎo)入 zbx 所需信息(本文編寫時,Zabbix 3.0 最新版本為 3.0.19)
cd /usr/share/doc/zabbix-server-mysql-3.0.19
zcat create.sql.gz | mysql zabbix

19、配置 zbx 參數(shù)
vim /etc/zabbix/zabbix_server.conf,主要是以下幾個選項參數(shù)需要設(shè)置(以?8GB 內(nèi)存為例)DBPassword 配置為第 15 步中設(shè)置的自定義密碼
CacheSize=512M
HistoryCacheSize=128M
HistoryIndexCacheSize=128M
TrendCacheSize=128M
ValueCacheSize=256M
Timeout=30
其它參數(shù)保持默認值即可(如果監(jiān)控主機數(shù)量較多,則調(diào)大 StartPollers 的值)

如果需要監(jiān)控VMware虛擬機,則還需要設(shè)置以下選項參數(shù):
StartVMwareCollectors=2
VMwareCacheSize=256M
VMwareTimeout=300

20、配置 Apache 中的 PHP 參數(shù)(以 8GB 內(nèi)存為例)
vim /etc/httpd/conf.d/zabbix.conf

max_execution_time 600
memory_limit 256M
post_max-size 32M
upload_max_filesize 32M
max_input_time 600
date.timezone 去掉注釋符號#,并將值修改為 Asia/Shanghai

21、重啟系統(tǒng)
systemctl stop mariadb && reboot

22、啟動 zbx
systemctl start httpd && systemctl start zabbix-server

23、在瀏覽器中輸入 http://zbx監(jiān)控服務(wù)器的IP地址/zabbix,進行 zabbix 的頁面初始化配置,根據(jù)頁面提示信息進行設(shè)置即可。

“Check of pre-requisites”頁面中,需要全部為綠色 ok

“Zabbix server detail”頁面中,“Name”處可填寫對此監(jiān)控系統(tǒng)的描述性文字,支持中文

24、第一次登錄zbx監(jiān)控系統(tǒng),默認用戶名 admin(或Admin),默認密碼 zabbix,確認可正常登錄系統(tǒng),且紅色箭頭處為綠色的 Yes 后,點擊右上角圖標退出

25、將 Windows 7 系統(tǒng)自帶的雅黑字體( 此字體文件的默認位置是 c:\windows\fonts\msyh.ttf)上傳到 zbx監(jiān)控服務(wù)器系統(tǒng)的 /usr/share/zabbix/fonts 目錄下

注:有人說雅黑字體有版權(quán)限制,不能使用在非 Windows 操作系統(tǒng)的環(huán)境下,可以更換為宋體等字體文件。

26、修改 /usr/share/zabbix/include/defines.inc.php 文件,將其中的 45 行 ZBX_GRAPH_FONT_NAME 和 93 行 ZBX_FONT_NAME 的值改為 msyh
vim?/usr/share/zabbix/include/defines.inc.php

27、重啟 Apache 和 zbx
systemctl enable httpd && systemctl enable zabbix-server && systemctl restart httpd && systemctl restart zabbix-server

28、在瀏覽器中輸入 http://zbx監(jiān)控服務(wù)器的IP地址/zabbix,用戶名 admin(或Admin),默認密碼 zabbix,登錄進入系統(tǒng)后,選擇 Administrator --> Users --> Admin,Language 設(shè)置為 Chinese(zh_CN),點擊 Update 按鈕使之生效

29、回到“監(jiān)測中” --> “儀表板”,就可以看到監(jiān)控系統(tǒng)已設(shè)置為中文界面了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容