天天看点

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

【操作一】数据库端

01. 最小化安装操作系统,推荐 x86_64 版本

02. 升级系统组件到最新版本:

yum -y update

03. 关闭 SELinux:

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

04. 关闭防火墙:

systemctl stop firewalld.service && systemctl disable firewalld.service

05、开启端口

如果已执行了第4步,则第5步可忽略。如果有信息安全合规要求,不能直接关闭防火墙,则跳过第4步,执行第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,增加以下内容 *     soft     nproc     65535 *     hard    nproc     65535 *     soft     nofile     65535 *     hard    nofile     65535
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

07. 修改 vm.swappiness 的值

vi /etc/sysctl.conf,增加以下内容 vm.swappiness =  1

08. 安装 MariaDB 源

vi /etc/yum.repos.d/MariaDB.repo,增加以下内容 [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. 启动 MariaDB

systemctl enable mariadb && systemctl start mariadb

11. 进行 MariaDB 安全配置,除了修改为自定义密码(第 13 步设置 MariaDB 参数时会用到),其它选项选择 y 即可

mysql_secure_installation
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

12. 暂停 MariaDB

systemctl stop mariadb

13. 设置 MariaDB 参数(以 8GB 内存为例)

vim /etc/my.cnf.d/server.cnf,在 [mysqld] 字段下增加以下内容 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 # 如果需要开启复制或搭建高可用,则以下  7  行内容需要启用,否则禁用 #log_bin = mariadb1-bin #binlog_format = ROW # 如果对数据完整性要求高,则 sync_binlog =  1 #sync_binlog =  0 #binlog_cache_size = 4M #max_binlog_cache_size = 1G #max_binlog_size = 1G #expire_logs_days =  7   innodb_strict_mode = off 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 # 如果对数据完整性要求高,则 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     # 有性能监控要求的,则开启以下参数,否则禁用 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"
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)
vim /etc/my.cnf.d/mysql-clients.cnf, 在 [mysql] 字段下增加以下内容 prompt =  "\U[\R:\m][\d]> " no-auto-rehash default -character-set = utf8mb4 user=root password=Qingdao, 2018  # 此处就是第  12  步设置的 MariaDB root 密码   在 [mysqldump] 字段下增加以下内容 quick
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

原则上 innodb_buffer_pool_size 需要设置为主机内存的 80%,如果主机内存不是 8GB,以上参数可依据相应比例进行调整,例如主机内存为 16GB,则 innodb_buffer_pool_size 建议设置为 12GB。请注意innodb_buffer_pool_size的值必须是整数,例如主机内存是4G,那么innodb_buffer_pool_size可以设置为3G,而不能设置为3.2G 本设置以提升数据库性能为目标,降低了数据安全性。如果要保证数据安全,需对部分参数进行调整,具体请参考 MariaDB 官方文档中的相关内容,本文不展开讨论      

14. 配置 MariaDB 中Zabbix所需要的库和账号权限

  # mysql -uroot -p password mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to [email protected] identified by 'password'; mysql>flush privileges; mysql>exit;      

15. 重启主机

systemctl stop mariadb && reboot

【操作二】应用端

16. 最小化安装操作系统,推荐 x86_64 版本

17. 升级系统组件到最新版本

yum -y update

18. 关闭 SELinux

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

19. 关闭防火墙

systemctl stop firewalld.service && systemctl disable firewalld.service

20. 开启端口

如果已执行了第4步,则第5步可忽略。如果有信息安全合规要求,不能直接关闭防火墙,则跳过第4步,执行第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,增加以下内容 * soft nproc  65535 * hard nproc  65535 * soft nofile  65535 * hard nofile  65535

22. 修改 vm.swappiness 的值

vi /etc/sysctl.conf,增加以下内容 vm.swappiness =  1

23. 安装 MariaDB 源

vi /etc/yum.repos.d/MariaDB.repo,增加以下内容 [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. 安装Zabbix所需软件支持包

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. 安装Zabbix源

   RHEL7/CentOS7 vi /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - \$basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - \$basearch baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1  添加gpgkey   curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \ -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591   curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \ -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX    添加之后即可使用 yum makecache -y yum install zabbix-<...>  

27. 安装Zabbix

yum -y install zabbix-server-mysql zabbix-web-mysql

28. 将Zabbix创库文件传送到数据库主机上

scp /usr/share/doc/zabbix-server-mysql*/create.sql.gz [email protected]数据库主机IP地址:/root/

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

【操作三】数据库端

29. 导入Zabbix所需信息

zcat /root/create.sql.gz | mysql -uzabbix -p zabbix    

【操作四】应用端

30. 配置Zabbix参数

vim /etc/zabbix/zabbix_server.conf,主要是以下几个选项参数需要设置(以 8GB 内存为例)DBHost=数据库主机IP地址 DBPassword 配置为第  14  步中设置的自定义密码 CacheSize=512M HistoryCacheSize=128M HistoryIndexCacheSize=128M TrendCacheSize=128M ValueCacheSize=256M Timeout= 30

  其它参数保持默认值即可(如果监控主机数量较多,则调大 StartPollers 的值)

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

如果需要监控VMware虚拟机,则还需要设置以下选项参数:  

StartVMwareCollectors= 2 VMwareCacheSize=256M VMwareTimeout= 300

31. 配置 Apache 中的 PHP 参数(以 8GB 内存为例)

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
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

32. 重启主机

reboot

33. 启动Zabbix

systemctl start httpd && systemctl start zabbix-server

34. 在浏览器中输入 http://zbx监控服务器的IP地址/zabbix,进行Zabbix 的页面初始化配置,根据页面提示信息进行设置即可。

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

“Check of pre-requisites”页面中,需要全部为绿色 ok  

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

“Zabbix server detail”页面中,“Name”处可填写对此监控系统的描述性文字,支持中文

35. 第一次登录Zabbix监控系统,默认用户名 admin(或Admin),默认密码 zabbix,确认可正常登录系统,且红色箭头处为绿色的 Yes 后,点击右上角图标退出

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

36. 将 Windows 7 系统自带的雅黑字体( 此字体文件的默认位置是 c:\windows\fonts\msyh.ttf)上传到Zabbix监控服务器系统的 /usr/share/zabbix/assets/fonts 目录下
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

  有人说雅黑字体有版权限制,不能使用在非 Windows 操作系统的环境下,可以更换为宋体等字体文件。

37. 修改

/usr/share/zabbix/include/defines.inc.php 文件,将其中的45行ZBX_GRAPH_FONT_NAME和93行 ZBX_FONT_NAME 的值改为  

msyhvim /usr/share/zabbix/include/defines.inc.php
CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

38. 重启 Apache 和Zabbix

systemctl enable httpd && systemctl enable zabbix-server && systemctl restart httpd && systemctl restart zabbix-server

39.

        在浏览器中输入  http://zbx监控服务器的IP地址/zabbix,用户名  admin(或Admin),默认密码 zabbix,登录进入系统后,选择 Administrator --> Users --> Admin,Language 设置为 Chinese(zh_CN),点击 Update 按钮使之生效

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

40. 回到“监测中” --> “仪表板”,就可以看到监控系统已设置为中文界面了  

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

  40.一些常见错误   一、如果数据库用户有远程权限,在zabbix web界面始终提示权限被拒绝可进行如下操作: 修改httpd_can_network_connect值: getsebool -a | grep httpd    #查看一下,值知否为OFF setsebool httpd_can_network_connect 1   #修改值为on   二、如默认密码不正确: 1,登陆zabbix的数据库服务器,查看zabbix的登陆密码:

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

[[email protected] ~]# mysql -uroot -p -e " select * from zabbix.users\G " Enter password: *************************** 1 . row *************************** userid: 1 alias: Admin name: Zabbix surname: Administrator passwd: bcfdb6e18854fa4d45412340a04v89b12 url: autologin: 1 autologout: 0 lang: en_GB refresh: 30 type: 3 theme: default attempt_failed: 0 attempt_ip: 192. 168 . 1.20 attempt_clock: 1501141026 rows_per_page: 50

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

这里可以看出:用户: Admin ,密码:zabbix,上面的passwd就是zabbix的md5加密后的字符串。 2, 修改密码 利用:md5的对应值: 5f ce1b3e34b520afeffb37ce08c7cd66 = zabbix 因为zabbix默认密码就是zabbix [[email protected] ~]# mysql -uroot - p mysql > use zabbix; mysql > update users set passwd= ' 5fce1b3e34b520afeffb37ce08c7cd66 ' where userid= ' 1 ' ; Query OK, 1 row affected ( 0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 3,登录 Web

用户名:Admin 密码:zabbix

CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)CentOS 7 安装Zabbix 4.0 (应用和数据库分离版)

  三、 处理数据库和zabbix前台不匹配   mysql -uroot -p123 mysql> show databases; mysql> use zabbix; mysql> update dbversion set mandatory=4000000; mysql> flush privileges;              

继续阅读