centos7搭建zabbix3.0监控系统

关闭防火墙和selinux

systemctl stop firewalld.service                (停止防火墙)

systemctl disable firewalld.service           (关闭防火墙)

关闭selinux;

setenforc 0

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

 

使用yum命令前,清除一下yum进程

 rm -rf /var/run/yum.pid

安装依赖包;

yum -y install wget net-snmp-devel OpenIPMI-devel httpd openssl-devel java lrzsz fping-devel libcurl-devel perl-DBI pcre-devel libxml2 libxml2-devel mysql-devel gcc php php-bcmath php-gd php-xml php-mbstring php-ldap php-mysql.x86_64 php-pear php-xmlrpc  net-tools wget vim-enhanced

1.  搭建lamp环境

在centos7上安装zabbix server3.0之前,我们首先搭建zabbix所需要的lamp环境。

下载最新的yum源,如下:

 # wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo

2. 安装lamp环境,使用如下命令:

[root@zabbix ~]# yum -y install mariadb mariadb-server php php-mysql httpd                         注意     centos7自带的mysql是mariadb,我们可以通过如下命令查看:yum search mysql|tac

 

centos7默认安装的是php5.4、httpd2.4和maradb5.5,这个完全符合zabbix3.0对软件版本的要求。

 

3. lamp安装完毕后,配置mysql数据库。

设置开机自启动mysql,并启动mysql,使用如下命令:

 设置链接 : ls -n /etc/systemd/system/multi-user.target.wants/mariadb.service /usr/lib/systemd/system/mariadb.service

[root@zabbix ~]# systemctl enable mariadb.service

[root@zabbix ~]# systemctl start mariadb.service

初始化mysql数据库,并配置root用户密码。使用如下命令:

[root@zabbix ~]# mysql_secure_installation

 

Remove anonymous users? 删除匿名用户?

Disallow root login remotely? 禁止root远程登陆

Remove test database and access to it? 删除测试数据库并且和访问它

Reload privilege tables now? 重新载入特权表

上图中主要是配置匿名用户、test用户以及root用户远程连接等相关配置。

 

mysql初始化完毕后,创建zabbix数据库及其用户

mysql -u root -pabc123

create database zabbix default character set utf8 collate utf8_bin;                (创建zabbix库,并指定语言)

 

grant all on zabbix.* to "zabbix"@"%" identified by "zabbix";                            (授权用户zabbix拥有zabbix库所有权限)

flush privileges;

验证用户是否可以登录数据库:mysql -uzabbix -pzabbix

启动apache以及开放80端口,如下:

[root@zabbix ~]# systemctl start httpd.service

[root@zabbix ~]# netstat -ltun

 

安装zabbix server3.0

 rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm      #下载zabbix yum源

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

 

 

导入zabbix数据库结构,如下:

[root@zabbix ~]# cd /usr/share/doc/zabbix-server-mysql-3.0.13/

[root@zabbix zabbix-server-mysql-3.0.5]# zcat create.sql.gz | mysql -uroot -pabc123 zabbix

 

 

 

三、修改配置文件

vim /etc/zabbix/zabbix_server.conf         #修改zabbix配置文件

DBHost=localhost                (去掉此行前面的#)
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix                (在此行设置密码,并去掉#)

 

systemctl start zabbix-server       #开启zabbix-server
ls -n /etc/systemd/system/multi-user.target.wants/zabbix-server.service /usr/lib/systemd/system/zabbix-server.service

systemctl enable zabbix-server  #设置开机自启动

 

配置时区
vim /etc/httpd/conf.d/zabbix.conf  #修改httpd中zabbix文件,设置时区
php_value date.timezone Asia/Chongqing ==>>php_value date.timezone Asia/Shanghai     (修改此条即可)    

systemctl restart httpd.service

 

ls -n /etc/systemd/system/multi-user.target.wants/httpd.service /usr/lib/systemd/system/httpd.service

systemctl enable httpd  # 设置开机自启动

 

最后配置zabbix

http://ip/zabbix/setup.php

 

 

 

 

 

  yum update trousers                       (一定要更新这个软件包,不然后面会出错)

 

搭建完成后重启主机

 

 

若是不关闭防火墙的话则设置

允许zabbix-agent的10050端口通过

firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --reload 

 

 

客户端配置

添加agent主机

rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
yum install zabbix-sender zabbix-agent zabbix

配置zabbix-agent

sed -i "s/Server=127.0.0.1/Server=服务器ip/" /etc/zabbix/zabbix_agentd.conf
 sed -i "s/ServerActive=127.0.0.1/ServerActive=服务器ip/" /etc/zabbix/zabbix_agentd.conf      (主动模式)
 sed -i "s/Hostname=Zabbix server/Hostname=客户端地址/" /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent.service
systemctl enable zabbix-agent.service

 

启动客户端

[root@zabbix ~]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf

[root@zabbix ~]# systemctl start zabbix-agent

[root@zabbix ~]# systemctl restart zabbix-agent

[root@zabbix ~]# systemctl enable zabbix-agent

 

posted @ 2017-12-11 17:21  暴走的泰迪  阅读(619)  评论(2编辑  收藏  举报