博客列表 >CentOS7.2下部署zabbix4.0

CentOS7.2下部署zabbix4.0

哈
原创
2021年12月30日 10:49:37617浏览

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

1. 基础环境配置优化

1.1 关闭防火墙

  1. [root@monitor_53 ~]$ systemctl stop firewalld
  2. [root@monitor_53 ~]$ systemctl disable firewalld

1.2 关闭selinux

  1. [root@monitor_53 ~]$ setenforce 0
  2. [root@monitor_53 ~]$ sed -i "s#enforcing#disabled#g" /etc/sysconfig/selinux

1.3 下载官方源

  1. [root@monitor_53 ~]$ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  2. [root@monitor_53 ~]$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  3. [root@monitor_53 ~]$ yum clean all
  4. [root@monitor_53 ~]$ yum makecache
  5. [root@monitor_53 ~]$ yum update -y

1.4 安装扩展和依赖

  1. [root@monitor_53 ~]$ yum install -y php-mysql php-gd php-bcmath php-common php-xml php-mbstring php-cli pcre glibc gcc livevent zlib libcurl-devel curl-devel OpenIPMI-devel libssh2 fping net-snmp-devel perl-DBI openssl-devel iksemel libxml2

2. 安装lnmp架构

2.1 安装LNMP环境

  1. [root@monitor_53 ~]$ yum install -y httpd php mariadb mariadb-server ntp

2.2 配置时间同步

  1. [root@monitor_53 ~]$ ntpdate -u asia.pool.ntp.org
  2. [root@monitor_53 ~]$ systemctl enable ntpd
  3. [root@monitor_53 ~]$ echo '* /30 * * * * /usr/sbin/ntpdate -u asia.pool.ntp.org > /dev/null 2>&1' >>/var/spool/cron/root

2.3 配置数据库

  1. [root@monitor_53 ~]$ mkdir -p /home/mysql/{data,logs}
  2. [root@monitor_53 ~]$ touch /home/mysql/logs/slow_query_log.log
  3. [root@monitor_53 ~]$ touch /home/mysql/logs/error.log
  4. [root@monitor_53 ~]$ chown -R mysql:mysql /home/mysql
  5. [root@monitor_53 ~]$ cp /etc/my.cnf /etc/my.cnf.bak
  6. [root@monitor_53 ~]$ cat /etc/my.cnf
  7. [mysqld]
  8. user = mysql
  9. port = 3306
  10. datadir = /var/lib/mysql
  11. socket = /var/lib/mysql/mysql.sock
  12. pid-file = /var/run/mariadb/mariadb.pid
  13. log-error = /home/mysql/logs/error.log
  14. slow_query_log = on
  15. slow_query_log_file = /home/mysql/logs/slow_query_log.log
  16. long_query_time = 0.1
  17. log_queries_not_using_indexes =1
  18. long_query_time=2
  19. character_set_server=utf8
  20. [client]
  21. port = 3306
  22. socket = /var/lib/mysql/mysql.sock
  23. [mysqldump]
  24. quick
  25. max_allowed_packet = 32M

2.4 初始化数据库

  1. [root@monitor_53 ~]$ systemctl enable mariadb
  2. [root@monitor_53 ~]$ systemctl start mariadb
  3. [root@monitor_53 ~]$ mysql_secure_installation #初始化,配置完成root密码后,一路按Y即可
  4. [root@monitor_53 ~]$ mysql_secure_installation
  5. Enter current password for root (enter for none): 回车
  6. Set root password? [Y/n] 回车
  7. New password: 123456
  8. Re-enter new password: 123456
  9. Remove anonymous users? [Y/n] 回车
  10. Disallow root login remotely? [Y/n] 回车
  11. Remove test database and access to it? [Y/n] 回车
  12. Reload privilege tables now? [Y/n] 回车
  13. Thanks for using MariaDB!

2.5 启动http

  1. [root@monitor_53 ~]$ systemctl start httpd
  2. [root@monitor_53 ~]$ systemctl enable httpd
  3. [root@monitor_53 ~]$ netstat -ntap | egrep '(80|3306)'

3. 安装zabbix

3.1 安装Server、Web、Agent

  1. [root@monitor_53 ~]$ rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  2. [root@monitor_53 ~]$ yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

3.2 创建zabbix数据库

  1. [root@monitor_53 ~]$ mysql -uroot -p123456
  2. mysql> create database zabbix character set utf8 collate utf8_bin;
  3. mysql> grant all privileges on zabbix.* to 'zabbix'@'10.0.0.53' identified by 'zabbix';
  4. mysql> flush privileges;
  5. mysql> quit;

3.3 导入初始架构和数据

  1. [root@monitor_53 ~]$ zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h 10.0.0.53 -uzabbix -p zabbix

3.4 为Zabbix-server配置数据库

  1. [root@monitor_53 ~]$ cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
  2. [root@monitor_53 ~]$ cat /etc/zabbix/zabbix_server.conf
  3. LogFile=/var/log/zabbix/zabbix_server.log
  4. LogFileSize=0
  5. DebugLevel=3
  6. PidFile=/var/run/zabbix/zabbix_server.pid
  7. SocketDir=/var/run/zabbix
  8. DBHost=10.0.0.53
  9. DBName=zabbix
  10. DBUser=zabbix
  11. DBPassword=zabbix
  12. DBSocket=/var/lib/mysql/mysql.sock
  13. SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
  14. Timeout=4
  15. AlertScriptsPath=/usr/lib/zabbix/alertscripts
  16. ExternalScripts=/usr/lib/zabbix/externalscripts
  17. LogSlowQueries=3000

3.5 为Zabbix-server配置PHP

  1. [root@monitor_53 ~]$ cp /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf.bak
  2. [root@monitor_53 ~]$ vim /etc/httpd/conf.d/zabbix.conf
  3. php_value date.timezone Europe/Riga

3.6 修改zabbix-agent配置文件

  1. [root@monitor_53 ~]$ cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
  2. [root@monitor_53 ~]$ cat /etc/zabbix/zabbix_agentd.conf
  3. PidFile=/var/run/zabbix/zabbix_agentd.pid
  4. LogFile=/var/log/zabbix/zabbix_agentd.log
  5. LogFileSize=0
  6. ListenPort=10050
  7. Server=10.0.0.53
  8. ServerActive=10.0.0.53
  9. Hostname=10.0.0.53
  10. Include=/etc/zabbix/zabbix_agentd.d/*.conf
  11. HostMetadataItem=system.uname
  12. StartAgents=1
  13. RefreshActiveChecks=120
  14. BufferSize=200
  15. Timeout=10

3.7 启动server和agent

  1. [root@monitor_53 ~]$ systemctl restart zabbix-server zabbix-agent httpd
  2. [root@monitor_53 ~]$ systemctl enable zabbix-server zabbix-agent httpd

3.8 查看所有服务端口

  1. [root@monitor_53 ~]$ netstat -tnlp | egrep '(80|3306|10050|10051)'

file

3.9 配置Zabbix前端

浏览器连接到新安装的Zabbix前端: http://10.0.0.53/zabbix

  1. Database type MySQL
  2. Database server 10.0.0.53
  3. Database port 3306
  4. Database name zabbix
  5. Database user zabbix
  6. Database password zabbix
  7. Zabbix server 10.0.0.53
  8. Zabbix server port 10051
  9. Zabbix server name 运维监控

本文转自:https://developer.aliyun.com/article/847055

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议