【數(shù)據(jù)庫(kù)】
01课蔬、最小化安裝操作系統(tǒng)议经,推薦 x86_64 版本
02甥厦、升級(jí)系統(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蛾扇、開(kāi)啟端口(如果已執(zhí)行了第4步,則第5步可忽略魏滚。如果有信息安全合規(guī)要求镀首,不能直接關(guān)閉防火墻,則跳過(guò)第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麻敌、安裝 MariaDB
yum -y install ntsysv wget telnet net-tools python-paramiko python-setuptools python-devel MariaDB-server MariaDB-client MariaDB-devel?MySQL-python vim?epel-release?xorg-x11-xauth tree
10、啟動(dòng) MariaDB
systemctl enable mariadb && systemctl start mariadb
11掂摔、進(jìn)行 MariaDB 安全配置撤逢,除了修改為自定義密碼(第 13 步設(shè)置 MariaDB 參數(shù)時(shí)會(huì)用到)年栓,其它選項(xiàng)選擇 y 即可
mysql_secure_installation
12、暫停 MariaDB
systemctl stop mariadb
13、設(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
key_buffer_size = 1M
read_buffer_size = 4M
read_rnd_buffer_size = 2M
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_cache_size = 512
sort_buffer_size = 4M
join_buffer_size = 4M
bulk_insert_buffer_size = 64M
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
# 如果需要開(kāi)啟復(fù)制或搭建高可用,則以下 7 行內(nèi)容需要啟用溯泣,否則禁用
#log_bin = mariadb1-bin
#binlog_format = ROW
# 如果對(duì)數(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
# 如果對(duì)數(shù)據(jù)完整性要求高,則 innodb_flush_log_at_trx_commit =?1
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 10
innodb_autoinc_lock_mode = 2
innodb_doublewrite = 1
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
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
# 有性能監(jiān)控要求的趋观,則開(kāi)啟以下參數(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è)置為主機(jī)內(nèi)存的 80%编曼,如果主機(jī)內(nèi)存不是 8GB,以上參數(shù)可依據(jù)相應(yīng)比例進(jìn)行調(diào)整剩辟,例如主機(jī)內(nèi)存為 16GB掐场,則 innodb_buffer_pool_size 建議設(shè)置為 12GB往扔。請(qǐng)注意innodb_buffer_pool_size的值必須是整數(shù),例如主機(jī)內(nèi)存是4G熊户,那么innodb_buffer_pool_size可以設(shè)置為3G萍膛,而不能設(shè)置為3.2G
2、本設(shè)置以提升數(shù)據(jù)庫(kù)性能為目標(biāo)嚷堡,降低了數(shù)據(jù)安全性蝗罗。如果要保證數(shù)據(jù)安全,需對(duì)部分參數(shù)進(jìn)行調(diào)整蝌戒,具體請(qǐng)參考 MariaDB 官方文檔中的相關(guān)內(nèi)容串塑,本文不展開(kāi)討論
14、配置 MariaDB 中 zbx 所需要的庫(kù)和賬號(hào)權(quán)限
systemctl start mariadb
mysql
mysql>create database zabbix character set utf8;
mysql>create user zabbix@'應(yīng)用端主機(jī)IP' identified by 'Qingdao,2018';
mysql>grant all privileges on zabbix.* to zabbix@'應(yīng)用端主機(jī)IP';
mysql>flush privileges;
mysql>exit;
15北苟、重啟主機(jī)
systemctl stop mariadb && reboot
【應(yīng)用】
16桩匪、最小化安裝操作系統(tǒng),推薦 x86_64 版本
17友鼻、升級(jí)系統(tǒng)組件到最新版本
yum -y update
18傻昙、關(guān)閉 SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
19、關(guān)閉防火墻
systemctl stop firewalld.service && systemctl disable firewalld.service
20桃移、開(kāi)啟端口(如果已執(zhí)行了第4步屋匕,則第5步可忽略。如果有信息安全合規(guī)要求借杰,不能直接關(guān)閉防火墻过吻,則跳過(guò)第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
21蔗衡、增加 nproc 和 nofile 的上限值
vi /etc/security/limits.conf纤虽,增加以下內(nèi)容
*? ? ?soft? ? ?nproc? ? 65535
*? ? ?hard? ? nproc? ? 65535
*? ? ?soft? ? ?nofile? ? 65535
*? ? ?hard? ? nofile? ? 65535
22、修改 vm.swappiness 的值
vi /etc/sysctl.conf绞惦,增加以下內(nèi)容
vm.swappiness = 1
23逼纸、安裝 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
24济蝉、安裝 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-client MySQL-python vim?epel-release?xorg-x11-xauth tree
25杰刽、停止并卸載 postfix
systemctl disable postfix.service && rpm -e --nodeps postfix
26、安裝 zbx 源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
27王滤、安裝 zbx
yum -y install zabbix-server-mysql zabbix-web-mysql
28贺嫂、將 zbx 創(chuàng)庫(kù)文件傳送到數(shù)據(jù)庫(kù)主機(jī)上(本文編寫(xiě)時(shí),Zabbix 3.0 最新版本為 3.0.19)
scp create.sql.gz root@數(shù)據(jù)庫(kù)主機(jī)IP地址:/root/
【數(shù)據(jù)庫(kù)】
29雁乡、導(dǎo)入 zbx 所需信息
zcat /root/create.sql.gz | mysql zabbix
rm -rf /root/create.sql.gz
【應(yīng)用】
30第喳、配置 zbx 參數(shù)
vim /etc/zabbix/zabbix_server.conf,主要是以下幾個(gè)選項(xiàng)參數(shù)需要設(shè)置(以?8GB 內(nèi)存為例)DBHost=數(shù)據(jù)庫(kù)主機(jī)IP地址
DBPassword 配置為第 14 步中設(shè)置的自定義密碼
CacheSize=512M
HistoryCacheSize=128M
HistoryIndexCacheSize=128M
TrendCacheSize=128M
ValueCacheSize=256M
Timeout=30
其它參數(shù)保持默認(rèn)值即可(如果監(jiān)控主機(jī)數(shù)量較多踱稍,則調(diào)大 StartPollers 的值)
如果需要監(jiān)控VMware虛擬機(jī)曲饱,則還需要設(shè)置以下選項(xiàng)參數(shù):
StartVMwareCollectors=2
VMwareCacheSize=256M
VMwareTimeout=300
31悠抹、配置 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 去掉注釋符號(hào)#,并將值修改為 Asia/Shanghai
32扩淀、重啟主機(jī)
reboot
32楔敌、啟動(dòng) zbx
systemctl start httpd && systemctl start zabbix-server
33、在瀏覽器中輸入 http://zbx監(jiān)控服務(wù)器的IP地址/zabbix引矩,進(jìn)行 zabbix 的頁(yè)面初始化配置梁丘,根據(jù)頁(yè)面提示信息進(jìn)行設(shè)置即可侵浸。
“Check of pre-requisites”頁(yè)面中旺韭,需要全部為綠色 ok
“Zabbix server detail”頁(yè)面中,“Name”處可填寫(xiě)對(duì)此監(jiān)控系統(tǒng)的描述性文字掏觉,支持中文
34区端、第一次登錄zbx監(jiān)控系統(tǒng),默認(rèn)用戶名 admin(或Admin)澳腹,默認(rèn)密碼 zabbix织盼,確認(rèn)可正常登錄系統(tǒng),且紅色箭頭處為綠色的 Yes 后酱塔,點(diǎn)擊右上角圖標(biāo)退出
35沥邻、將 Windows 7 系統(tǒng)自帶的雅黑字體( 此字體文件的默認(rèn)位置是 c:\windows\fonts\msyh.ttf)上傳到 zbx監(jiān)控服務(wù)器系統(tǒng)的 /usr/share/zabbix/fonts 目錄下
注:有人說(shuō)雅黑字體有版權(quán)限制,不能使用在非 Windows 操作系統(tǒng)的環(huán)境下羊娃,可以更換為宋體等字體文件唐全。
36、修改 /usr/share/zabbix/include/defines.inc.php 文件蕊玷,將其中的 45 行 ZBX_GRAPH_FONT_NAME 和 93 行 ZBX_FONT_NAME 的值改為 msyhvim?/usr/share/zabbix/include/defines.inc.php
37邮利、重啟 Apache 和 zbx
systemctl enable httpd && systemctl enable zabbix-server && systemctl restart httpd && systemctl restart zabbix-server
38、在瀏覽器中輸入 http://zbx監(jiān)控服務(wù)器的IP地址/zabbix垃帅,用戶名 admin(或Admin)延届,默認(rèn)密碼 zabbix,登錄進(jìn)入系統(tǒng)后贸诚,選擇 Administrator --> Users --> Admin方庭,Language 設(shè)置為 Chinese(zh_CN),點(diǎn)擊 Update 按鈕使之生效
39酱固、回到“監(jiān)測(cè)中” --> “儀表板”械念,就可以看到監(jiān)控系統(tǒng)已設(shè)置為中文界面了