CentOS 7.3安装Zabbix 3.2
一、准备搭建环境
1.系统:CentOS 7.3
2.软件:Zabbix 3.2
主机 | IP地址 | 系统 |
---|---|---|
Zabbix Server | 10.10.1.113 | CentOS 7.3 |
Linux-Agent | 10.10.10.114 | CentOS 7.3 |
二、安装前的准备
最小化安装CentOS 7系统时,需要做一下设置:
1.安装所需的软件包
yum groupinstall "Development Tools"
yum -y install vim lrzsz tree wget ntp mlocate
ntpdate time.nist.gov #与时间同步服务器同步
2.关闭firewalld和iptables防火墙服务
centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。所以你只要停止firewalld服务即可:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
如果你要改用iptables的话,需要安装iptables服务:
yum install iptables-services
systemctl enable iptables
systemctl enable ip6tables
systemctl start iptables
systemctl start ip6tables
3.关闭SElinux
使用这个命令查看SElinux状态
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# vim /etc/selinux/config
#在文件中找到这一行
SELINUX=enforcing
#把后面的参数修改为disabled
SELinux=disabled
- enforcing:开启防火墙
- permissive:关闭防火墙,但是会产生相应的日志
- disabled:彻底关闭防火墙,没日志产生
不关机情况下关闭SElinux,这个在重启之后会失效,临时关闭
[root@localhost ~]# setenforce 0
三、安装Zabbix3.2
1)安装LAMP环境
yum -y install mariadb mariadb-server php php-mysql httpd
#配置数据库开机启动
systemctl enable mariadb
systemctl start mariadb
#配置Apache服务开机自启
systemctl enable httpd
systemctl start httpd
2) 配置数据库
- 查看MariaDB数据库在进程的状态
[root@localhost ~]# ss -tulnp | grep mysqld
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=2674,fd=14))
- 初始化mysql数据库,并配置root用户密码(默认为空密码)
- mysql_secure_installation会执行以下几个设置:
- a)为root用户设置密码
- b)删除匿名账号
- c)取消root用户远程登录
- d)删除test库和对test库的访问权限
- e)刷新授权表使修改生效
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
- 创建zabbix数据库及访问用户
mysql -uroot -proot -e "create database zabbix default character set utf8 collate utf8_bin;"
mysql -uroot -proot -e "grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';"
- 测试刚创建的数据库及用户
mysql -uzabbix -pzabbix
show databases;
exit;
3)安装Zabbix Server端
- 导入yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
- 安装Zabbix
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
- 导入zabbix数据结构
[root@localhost ~]# updatedb #生成查找快照
[root@localhost ~]# locate create.sql #查找create.sql文件位置
/usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.7
[root@localhost zabbix-server-mysql-3.2.7]# zcat create.sql.gz | mysql -uroot -proot zabbix
- 修改Zabbix Server配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
新增如下内容:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
- 修改Zabbix的php配置文件
vim /etc/httpd/conf.d/zabbix.conf
取消内容为:php_value date.timezone的注释,并调整值为:Asia/Shanghai
- 启动Zabbix-Server,设置为开机自启动
[root@localhost ~]# systemctl enable zabbix-server
[root@localhost ~]# systemctl start zabbix-server
[root@localhost ~]# systemctl enable zabbix-agent
[root@localhost ~]# systemctl start zabbix-agent
- 重启Apache服务器
[root@localhost ~]# systemctl restart httpd
浏览器访问Zabbix-Server,进一步安装Zabbix
使用http://IP/zabbix访问
- 检查组件是否所有ok,直接下一步
- 创建数据库的连接:输入端口号和密码
- 完成安装
- 默认登录账户密码:Admin/zabbix
- 设置语言为中文:Chinese(zh_CN
- 简单设置一下,启用Zabbix Server的监控
解决乱码问题
解决办法如下:在Windows系统下Win+R打开运行,输入fonts,回车进入Windows字体目录,找到黑体-常规,复制出来将文件名修改为simhei.ttf,然后上传到/usr/share/zabbix/fonts
[root@localhost ~]# cd /usr/share/zabbix/fonts
[root@localhost fonts]# rz #上传simheil.ttf字体
[root@localhost fonts]# ls
graphfont.ttf simhei.ttf
上传成功后,编辑 /usr/share/zabbix/include/defines.inc.php这个文件
大约在45行,将'graphfont' 修改为simhei 。
[root@localhost fonts]# vim /usr/share/zabbix/include/defines.inc.php
44 define('ZBX_FONTPATH', realpath('fonts')); // where to search for font (GD > 2.0.18)
45 define('ZBX_GRAPH_FONT_NAME', 'simhei'); // font file name
46 define('ZBX_GRAPH_LEGEND_HEIGHT', 120); // when graph height is less then this value, some legend will not show up
修改完成后,刷新乱码就好了。
四、安装Zabbix-agent
1.监控Linux系统配置
客户端CentOS 7.3系统
(1). 导入yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
(2). 安装zabbix-agent
yum -y install zabbix-agent
(3). 配置zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
Server=10.10.10.113
ServerActive=10.10.10.113
Hostname=10.10.10.114
- 修改Server的IP,地址为服务端地址:Server=ServerIP
- 修改ServerAcive的IP,地址为服务端地址:ServerActive=ServerIP
- Hostname修改为网页里面添加的Hostname,需要保持一致,zabbix_agentd客户端计算机名:Hostname=Zabbix server
- 设置为0 仅为主动模式,如果需要发送数据等 可以不修改此项:StartAgents=0
(4). 启动zabbix-agent,并配置开机启动
systemctl enable zabbix-agent
systemctl start zabbix-agent
服务端配置监控Linux主机
配置 --> 主机 --> 创建主机
创建主机后,选择主机选项,然后填写:主机名称、可见的名称、群组、agent代理程序的接口IP,这几项添写就OK了
然后再添加模板
然后勾选刚刚添加的主机,点击"启用"
从拓扑图里右键可以查看主机聚合图形,具体查看Linux主机监控指标的图表
添加网络拓扑图 --> 更新
2.监控Windows系统配置
(1). 下载文件: http://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.win.zip
(2). 解压到C盘根目录,再修改文件:zabbix_agents_3.2.0.win/conf/zabbix_agentd.win.conf
Server=10.10.10.113
ServerActive=10.10.10.113
Hostname=Windows Server
(3).修改完后,"Win+R"打开cmd命令行运行安装Zabbix Agent服务注册,启动一下
# 安装注册服务
c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.exe -i -c c:\zabbix_agents_3.2.0.win\conf\zabbix_agentd.win.conf
# 删除注册服务
c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.exe -d -c c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.win.conf
(4).在服务端"配置" --> "主机" --> "创建主机"
最后再"配置" --> "主机"里勾选"[Windows Server测试主机]"启用,一会就可以看到图形
从拓扑图里右键可以查看主机聚合图形,具体查看Windows主机监控指标的图表
添加网络拓扑图 --> 更新
五、安装图形展示
1.趋势图集中显示Graphtree插件
插件地址:https://github.com/OneOaaS/graphtrees
(1).在Server上配置,下载补丁并升级
cd /usr/share/zabbix
wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3.0.4.patch
yum install -y patch #安装打补丁path包,安装过可忽略
patch -Np0
(2).安装好后,会在主页显示Graphtree插件
(3).删除广告信息
vim /usr/share/zabbix/oneoaas/templates/graphtree/graphtree.tpl
删除顶部图片8-12行和66-86底部广告
66