C/C++教程

CentOS7.2下部署zabbix4.0

本文主要是介绍CentOS7.2下部署zabbix4.0,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1. 基础环境配置优化

1.1 关闭防火墙

[root@monitor_53 ~]$ systemctl stop firewalld
[root@monitor_53 ~]$ systemctl disable firewalld

1.2 关闭selinux

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

1.3 下载官方源

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

1.4 安装扩展和依赖

[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环境

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

2.2 配置时间同步

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

2.3 配置数据库

[root@monitor_53 ~]$ mkdir -p /home/mysql/{data,logs}
[root@monitor_53 ~]$ touch /home/mysql/logs/slow_query_log.log
[root@monitor_53 ~]$ touch /home/mysql/logs/error.log
[root@monitor_53 ~]$ chown -R mysql:mysql /home/mysql
[root@monitor_53 ~]$ cp /etc/my.cnf /etc/my.cnf.bak
[root@monitor_53 ~]$ cat /etc/my.cnf
[mysqld]
user = mysql
port = 3306
datadir    = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
pid-file = /var/run/mariadb/mariadb.pid
log-error = /home/mysql/logs/error.log
slow_query_log = on
slow_query_log_file = /home/mysql/logs/slow_query_log.log
long_query_time = 0.1
log_queries_not_using_indexes =1
long_query_time=2
character_set_server=utf8

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqldump]
quick
max_allowed_packet = 32M

2.4 初始化数据库

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

2.5 启动http

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

3. 安装zabbix

3.1 安装Server、Web、Agent

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

3.2 创建zabbix数据库

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

3.3 导入初始架构和数据

[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配置数据库

[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
DebugLevel=3
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=10.0.0.53
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

3.5 为Zabbix-server配置PHP

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

3.6 修改zabbix-agent配置文件

[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
ListenPort=10050
Server=10.0.0.53
ServerActive=10.0.0.53
Hostname=10.0.0.53
Include=/etc/zabbix/zabbix_agentd.d/*.conf
HostMetadataItem=system.uname
StartAgents=1
RefreshActiveChecks=120
BufferSize=200
Timeout=10

3.7 启动server和agent

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

3.8 查看所有服务端口

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

file

3.9 配置Zabbix前端

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

Database type   MySQL
Database server   10.0.0.53
Database port   3306
Database name   zabbix
Database user   zabbix
Database password   zabbix
Zabbix server   10.0.0.53
Zabbix server port   10051
Zabbix server name   运维监控
这篇关于CentOS7.2下部署zabbix4.0的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!