当前位置:   article > 正文

Zabbix5.0安装详解

zabbix5.0安装

一、环境准备

1、系统环境:Centos7.6

2、系统优化:

  1. 1)修改主机名
  2. hostnamectl set-hostname controlnode
  3. 2)关闭不常用服务
  4. service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd
  5. auditd chronyd microcode postfix firewalld)
  6. for ((i=0;i<${#service_array[*]};i++)); do
  7. /usr/bin/systemctl stop ${service_array[$i]}
  8. done
  9. service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd
  10. auditd chronyd microcode postfix firewalld)
  11. for ((i=0;i<${#service_array[*]};i++)); do
  12. /usr/bin/systemctl disable ${service_array[$i]}
  13. done
  14. 3)关闭selinux
  15. sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
  16. grep "SELINUX=disabled" /etc/selinux/config
  17. setenforce 0
  18. (4)优化内存(可选)
  19. cat >>/etc/sysctl.conf<<EOF
  20. net.ipv4.tcp_fin_timeout = 2
  21. net.ipv4.tcp_tw_reuse = 1
  22. #net.ipv4.tcp_tw_recycle = 1
  23. net.ipv4.tcp_syncookies = 1
  24. net.ipv4.tcp_keepalive_time = 600
  25. net.ipv4.tcp_keepalive_probes = 5
  26. net.ipv4.tcp_keepalive_intvl = 15
  27. net.ipv4.ip_local_port_range = 1024 65000
  28. net.ipv4.tcp_max_syn_backlog = 262144
  29. net.ipv4.tcp_max_tw_buckets =5000
  30. net.ipv4.tcp_syn_retries = 1
  31. net.ipv4.tcp_synack_retries = 1
  32. net.core.somaxconn = 16384
  33. net.core.netdev_max_backlog = 16384
  34. net.ipv4.tcp_max_orphans = 16384
  35. EOF
  36. sysctl -p

3、环境配置:

  1. 1)安装必备软件
  2. yum install lrzsz dos2unix bash-completion nmap telnet tree wget vim net-tools ntpdate salt-minion git -y
  3. 2)配置阿里源
  4. 配置阿里的yum源:
  5. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  6. 配置阿里的epel源:
  7. yum install epel-release
  8. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  9. 设置yum和epel源的缓存:
  10. yum clean all
  11. yum makecache
  12. 查看系统可用的源:
  13. yum repolist enabled
  14. (3)修改字符集
  15. localectl set-locale LANG=zh_CN.UTF-8
  16. source /etc/locale.conf
  17. (4)配置时间同步定时任务
  18. [root@localhost ~]# crontab -e
  19. */5 * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null

二、配置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. 1)安装源:
  2. [root@controlnode ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
  3. [root@controlnode ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
  4. 2)启用 zabbix 前端源,修改/etc/yum.repos.d/zabbix.repo,将[zabbix-frontend]下的 enabled 改为 1
  5. [zabbix-frontend]
  6. name=Zabbix Official Repository frontend - $basearch
  7. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
  8. enabled=1
  9. gpgcheck=1
  10. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  11. 3)清除yum源之前的缓存:
  12. [root@controlnode ~]# yum clean all

3、验证yum源:

yum list | grep zabbix

三、安装zabbix服务端及相关组件

1、安装zabbix-server、zabbix-agent、zabbix-get:

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

2、安装 Software Collections,便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4 过低:

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

3、安装 zabbix 前端和相关环境:

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

4、查看安装的zabbix软件:

  1. [root@controlnode ~]# rpm -qa | grep zabbix
  2. zabbix-server-mysql-5.0.0-1.el7.x86_64
  3. zabbix-get-5.0.0-1.el7.x86_64
  4. zabbix-web-mysql-scl-5.0.0-1.el7.noarch
  5. zabbix-release-5.0-1.el7.noarch
  6. zabbix-agent-5.0.0-1.el7.x86_64
  7. zabbix-web-5.0.0-1.el7.noarch
  8. zabbix-web-deps-scl-5.0.0-1.el7.noarch
  9. zabbix-apache-conf-scl-5.0.0-1.el7.noarch

四、安装mariadb数据库

1、安装

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

2、优化my.cnf参数:/etc/my.cnf【2核4G的配置】(可选):

  1. #清空/etc/my.cnf文件中的内容,复制下面全部的参数到/etc/my.cnf中:
  2. [client]
  3. port=3306
  4. default-character-set=utf8
  5. socket=/var/lib/mysql/mysql.sock
  6. [mysql]
  7. no-auto-rehash
  8. [mysqld]
  9. user=mysql
  10. port=3306
  11. socket=/var/lib/mysql/mysql.sock
  12. basedir=/usr
  13. datadir=/var/lib/mysql
  14. open_files_limit = 10240
  15. symbolic-links=0
  16. default-storage-engine = innodb
  17. innodb_file_per_table = on
  18. max_connections = 1000
  19. max_connect_errors = 6000
  20. back_log = 600
  21. table_open_cache = 614
  22. skip-external-locking
  23. max_allowed_packet = 32M
  24. character-set-server = utf8
  25. skip-name-resolve
  26. innodb_buffer_pool_size = 1024M
  27. query_cache_size=16M
  28. join_buffer_size = 2M
  29. query_cache_limit = 4M
  30. query_cache_min_res_unit = 2K
  31. thread_stack = 192K
  32. tmp_table_size = 64M
  33. max_heap_table_size = 64M
  34. read_buffer_size = 1M
  35. read_rnd_buffer_size = 4M
  36. bulk_insert_buffer_size = 16M
  37. key_buffer_size = 384M
  38. server-id = 1
  39. thread_concurrency = 4
  40. thread_cache_size = 64
  41. sort_buffer_size = 2M
  42. slow_query_log = ON
  43. long_query_time = 2
  44. slow_query_log_file = /tmp/mysql-slow.log
  45. innodb_thread_concurrency = 2
  46. innodb_flush_log_at_trx_commit = 2
  47. innodb_log_buffer_size = 16M
  48. innodb_log_file_size = 128M
  49. lower_case_table_names = 1
  50. innodb_additional_mem_pool_size = 16M
  51. innodb_data_file_path = ibdata1:1024M:autoextend
  52. innodb_file_io_threads = 4
  53. innodb_log_files_in_group = 3
  54. innodb_max_dirty_pages_pct = 90
  55. innodb_lock_wait_timeout = 120
  56. innodb_write_io_threads = 2
  57. innodb_read_io_threads = 2
  58. sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  59. transaction_isolation = READ-COMMITTE
  60. [mysqldump]
  61. quick
  62. max_allowed_packet = 32M
  63. [mysqld_safe]
  64. log-error=/var/log/mariadb/mariadb.log
  65. pid-file=/var/run/mariadb/mariadb.pid

3、启动mariadb数据库,并开机自启动:

  1. [root@controlnode ~]# systemctl start mariadb.service
  2. [root@controlnode ~]# systemctl enable mariadb.service
  3. [root@controlnode ~]# netstat -tunlp | grep 3306
  4. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17226/mysqld

4、初始化Mariadb,并配置root密码:

  1. [root@controlnode ~]# mysql_secure_installation
  2. #第二次回车,设置所需要的密码,重复输入密码完成后,再按回车至结束
  3. #root密码设置为1qaz@WSX

5、创建zabbix库:

  1. [root@controlnode ~]# mysql -uroot -p1qaz@WSX
  2. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  3. MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@"%" identified by "1qaz@WSX";
  4. MariaDB [(none)]> flush privileges;
  5. MariaDB [(none)]> quit;

6、初始化 zabbix 数据库:

  1. #导入数据
  2. [root@controlnode ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p1qaz@WSX zabbix
  3. #验证数据是否导入成功
  4. [root@controlnode ~]# mysql -uroot -p1qaz@WSX -e "use zabbix;show tables"

7、修改/etc/zabbix/zabbix_server.conf连接数据库的配置:

DBPassword=1qaz@WSX

五、时区和字体乱码解决

1、配置时区

  1. 修改 zabbix 的 php 配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的时区:
  2. php_value[date.timezone] = Asia/Shanghai

2、解决zabbix-web中文乱码的问题:

(1)查看zabbix-web链接的字体:

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

(2)在windows中找到需要的字体格式后上传到"/usr/share/fonts/dejavu/"目录下:
         在windows中查找需要的字体

(3)将字体上传到"/usr/share/fonts/dejavu/"目录下:

  1. [root@controlnode ~]# cd /usr/share/fonts/dejavu/
  2. [root@controlnode dejavu]# rz -y

(4)对旧的字体备份后进行替换:

  1. 备份旧的字体:
  2. [root@controlnode dejavu]# cp -a DejaVuSans.ttf DejaVuSans.ttf.bak
  3. 替换字体:
  4. [root@controlnode dejavu]# \mv simkai.ttf DejaVuSans.ttf

六、启动zabbix相关服务及配置连接

1、启动zabbix服务并设置开机自启动:

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

2、访问页面配置连接

2.1、访问zabbix-server的配置页面,点击下一步:

http://192.168.1.201/zabbix/setup.php

2.2、点击下一步:

2.3、配置mysql数据库地址和密码,点击下一步:

2.4、配置zabbixServer的连接地址和zabbixServer的名称(可选):

2.5、点击下一步:

2.6、配置完成:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/898499
推荐阅读
相关标签
  

闽ICP备14008679号