一准备环境:
centos7;zabbix4.0;LNMP/LAMP(linux;apache;mysql;php)
1.1安装工具:
[root@zabbix_server ~]# yum install -y net-tools telnet sl wget vim cowsay bash-completion tree lrzsz
1.2配置yum源,epel源为阿里云镜像源
//yum [root@zabbix_server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo //epel [root@zabbix_server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //清理所有yum缓存 [root@zabbix_server ~]# yum clean all //yum缓存 [root@zabbix_server ~]# yum makecache //安装常用的工具 [root@zabbix_server ~]# yum install -y net-tools telnet sl cowsay bash-completion tree lrzsz //关闭防火墙 [root@zabbix_server ~]# systemctl disable firewalld.service
1.3关闭selinux:
[root@zabbix_server ~]# vim /etc/selinux/config
二.安装zabbix4.0
2.1首先安装lamp环境作为zabbix的运行环境,也就是web展示界面环境
yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
2.2修改一下apache的配置文件vi /etc/httpd/conf/httpd.conf
修改:DirectoryIndex index.html index.php //让apache支持php
先备份: cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak 有问题再用mv还原: mv /etc/httpd/conf/httpd.conf.bak /etc/httpd/conf/httpd.conf
2.3修改php时区为中国时区
vi /etc/php.ini date.timezone = PRC 可以搜索,先按esc,然后输入/date.timezone 这样就很快搜索到这行内容
2.4关闭防火墙和seliuux(之前关闭过就不用管了)
systemctl stop firewalld.service 临时关闭防火墙 setenforce 0 临时关闭selinux systemctl disable firewalld.service 永久关闭防火墙
2.5启动httpd服务和mairadb数据库服务,并设置为开机自启动
systemctl start httpd.service //启动apache systemctl enable httpd.service //将apache设为开机自启 systemctl start mariadb.service //启动mariadb systemctl enable mariadb.service //将mariadb设为开机自启
2.6初始化数据库
mysql_secure_installation
先回车,然后输入密码,再输入密码,最后一路回车即可。4个提示信息都输入y完成。
2.7进入数据库,并创建zabbix的数据库
//进入数据库 用户名:root 密码:123123 [root@zabbix_server ~]# mysql -uroot -p123123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> //查看当前数据库表 MariaDB [(none)]> show databases; //创建zabbix的数据库,数据库名叫zabbix,并设置字符集为utf8 MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; //授权所有的表,允许所有主机连,密码为admin123 MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; //刷一下权限 MariaDB [(none)]> flush privileges; //退出数据库 MariaDB [(none)]> quit
2.8安装php相关依赖,并安装zabbix的源
//安装php依赖 [root@zabbix_server ~]# yum install php-mbstring php-bcmath -y //把官方的源导入到本地 [root@zabbix_server ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm //安装zabbix源 ;zabbix-server-mysql;zabbix-web-mysql如果出现报错,多执行几次一般是网络问题 [root@zabbix_server ~]# yum install zabbix-server-mysql zabbix-web-mysql -y //导入数据库:这里可能会出现问题,根据版本的不同后面的版本号可能会不一样,按tab做补全就行了,实际根据自己的版本号做修改。导入数据,根据你自己的IP地址做修改然后数据你zabbix的数据库的密码(admin123),不是数据库的root的密码切记。 [root@zabbix_server ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.25/create.sql.gz | mysql -uzabbix -p -h 192.168.110.10 zabbix
2.9修改zabbix_server配置文件:让数据库能连接它
vi /etc/zabbix/zabbix_server.conf DBHost=192.168.110.10 zabbix服务器地址默认是localhost DBName=zabbix zabbix数据库名称 DBUser=zabbix zabbix用户名 DBPassword=admin123 数据库密码 修改好以后,保存并退出
2.10修改zabbix时区
vi /etc/httpd/conf.d/zabbix.conf php_value date.timezone Asia/Shanghai 修改为亚洲上海
2.11启动zabbix服务
systemctl enable zabbix-server //开机自启zabbix systemctl start zabbix-server //启动zabbix systemctl restart httpd.service //从启apache服务
2.12然后再浏览里面输入你服务器的IP地址后面加上zabbix
http://自己服务器的IP地址/zabbix
2.13 zabbix显示乱码
//进入fonts目录 cd /usr/share/zabbix/assets/fonts [root@zabbix_server fonts]# ls graphfont.ttf //备份graphfont.ttf为graphfont.ttf.bak [root@zabbix_server fonts]# cp graphfont.ttf graphfont.ttf.bak [root@zabbix_server fonts]# ls graphfont.ttf graphfont.ttf.bak //拖拽Windows桌面字体至目录 [root@zabbix_server fonts]# rz -E rz waiting to receive. [root@zabbix_server fonts]# ls graphfont.ttf graphfont.ttf.bak simsun.ttc //用simsun.ttc覆盖graphfont.ttf文件 [root@zabbix_server fonts]# mv simsun.ttc graphfont.ttf mv: overwrite 'graphfont.ttf'? y [root@zabbix_server fonts]# ls graphfont.ttf graphfont.ttf.bak [root@zabbix_server fonts]#
三。另一台服务器安装zabbix客户端;
3.1安装zabbix源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
3.2安装agent客户端
[root@zbbix_client ~]# yum install zabbix-agent -y
3.3配置agent客户端
root@zbbix_client ~]# vim /etc/zabbix/zabbix_agentd.conf //配置Server地址 Server=192.168.110.10 //设置开机自启zabbix-agent [root@zbbix_client ~]# systemctl enable zabbix-agent.service //启动zabbix-agent [root@zbbix_client ~]# systemctl start zabbix-agent.service //从启zabbix-agent systemctl restart zabbix-agent.service //查看zabbix-agent状态 systemctl status zabbix-agent.service //查看是否启动 [root@zbbix_client ~]# ss -ntl
3.4测试客户端是否可用,在服务端安装get;创建监控项
[root@zabbix_server ~]# yum install zabbix-get.x86_64 //测试K [root@zabbix_server ~]# zabbix_get -s 192.168.110.11 -k agent.hostname Zabbix server
3.5在服务端添加客户端主机
一准备环境:
centos7;zabbix4.0;LNMP/LAMP(linux;apache;mysql;php)
安装工具:
wget;vim
yum install wget vim -y
配置网络:
使用nmcli device show命令查看当前网卡的信息
[root@hadoop100 ~]# nmcli device show
GENERAL.DEVICE: ens33
查找网卡配置文件,找到ifcfg-ens33命名的文件,编辑这个文件
[root@hadoop100 ~]# cd /etc/sysconfig/network-scripts
[root@hadoop100 network-scripts]# ls
ifcfg-ens33 ifdown-ib ifdown-sit ifup-eth
使用vim命令编辑ifcfg-en33,找到最后一行,ONBOOT=no设为yes就会自动获取ip地址。
[root@hadoop100 network-scripts]# vim ifcfg-ens33
重启网络服务:service network restart 生效。
配置yum源,epel源为阿里云镜像源
//yum
[root@zabbix_server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
//epel
[root@zabbix_server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
//清理所有yum缓存
[root@zabbix_server ~]# yum clean all
//yum缓存
[root@zabbix_server ~]# yum makecache
//安装常用的工具
[root@zabbix_server ~]# yum install -y net-tools telnet sl cowsay bash-completion tree lrzsz
//关闭防火墙
[root@zabbix_server ~]# systemctl disable firewalld.service
关闭selinux:
[root@zabbix_server ~]# vim /etc/selinux/config
二.安装zabbix4.0
2.1首先安装lamp环境作为zabbix的运行环境,也就是web展示界面环境
yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
2.2修改一下apache的配置文件vi /etc/httpd/conf/httpd.conf修改:DirectoryIndex index.html index.php
让apache支持php
先备份:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
有问题再用mv还原:
mv /etc/httpd/conf/httpd.conf.bak /etc/httpd/conf/httpd.conf
2.3修改php时区为中国时区
vi /etc/php.ini
date.timezone = PRC
可以搜索,先按esc,然后输入/date.timezone 这样就很快搜索到这行内容
2.4关闭防火墙和seliuux(之前关闭过就不用管了)
systemctl stop firewalld.service 临时关闭防火墙
setenforce 0 临时关闭selinux
systemctl disable firewalld.service 永久关闭防火墙
2.5启动httpd服务和mairadb数据库服务,并设置为开机自启动
systemctl start httpd.service //启动apache
systemctl enable httpd.service //将apache设为开机自启
systemctl start mariadb.service //启动mariadb
systemctl enable mariadb.service //将mariadb设为开机自启
2.6初始化数据库
mysql_secure_installation
先回车,然后输入密码,再输入密码,最后一路回车即可。4个提示信息都输入y完成。
2.7进入数据库,并创建zabbix的数据库
//进入数据库 用户名:root 密码:123123
[root@zabbix_server ~]# mysql -uroot -p123123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
//查看当前数据库表
MariaDB [(none)]> show databases;
//创建zabbix的数据库,数据库名叫zabbix,并设置字符集为utf8
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
//授权所有的表,允许所有主机连,密码为admin123
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
//刷一下权限
MariaDB [(none)]> flush privileges;
//退出数据库
MariaDB [(none)]> quit
2.8安装php相关依赖,并安装zabbix的源
//安装php依赖 [root@zabbix_server ~]# yum install php-mbstring php-bcmath -y //把官方的源导入到本地 [root@zabbix_server ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm //安装zabbix源 ;zabbix-server-mysql;zabbix-web-mysql如果出现报错,多执行几次一般是网络问题 [root@zabbix_server ~]# yum install zabbix-server-mysql zabbix-web-mysql -y //导入数据库:这里可能会出现问题,根据版本的不同后面的版本号可能会不一样,按tab做补全就行了,实际根据自己的版本号做修改。导入数据,根据你自己的IP地址做修改然后数据你zabbix的数据库的密码(admin123),不是数据库的root的密码切记。 [root@zabbix_server ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.25/create.sql.gz | mysql -uzabbix -p -h 192.168.110.10 zabbix
2.9修改zabbix_server配置文件:让数据库能连接它
vi /etc/zabbix/zabbix_server.conf DBHost=192.168.110.10 zabbix服务器地址默认是localhost DBName=zabbix zabbix数据库名称 DBUser=zabbix zabbix用户名 DBPassword=admin123 数据库密码 修改好以后,保存并退出
2.10修改zabbix时区
vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
修改为亚洲上海
2.11启动zabbix服务
systemctl enable zabbix-server //开机自启zabbix
systemctl start zabbix-server //启动zabbix
systemctl restart httpd.service //从启apache服务
2.12然后再浏览里面输入你服务器的IP地址后面加上zabbix
http://192.168.110.10/zabbix/setup.php
如果报错:将host改为服务器的IP;port改为3306
密码:admin123
安装完成
登录名:Admin
登录密码:zabbix
2.13 zabbix显示乱码
//进入fonts目录
cd /usr/share/zabbix/assets/fonts
[root@zabbix_server fonts]# ls
graphfont.ttf
//备份graphfont.ttf为graphfont.ttf.bak
[root@zabbix_server fonts]# cp graphfont.ttf graphfont.ttf.bak
[root@zabbix_server fonts]# ls
graphfont.ttf graphfont.ttf.bak
//拖拽Windows桌面字体至目录
[root@zabbix_server fonts]# rz -E
rz waiting to receive.
[root@zabbix_server fonts]# ls
graphfont.ttf graphfont.ttf.bak simsun.ttc
//用simsun.ttc覆盖graphfont.ttf文件
[root@zabbix_server fonts]# mv simsun.ttc graphfont.ttf
mv: overwrite 'graphfont.ttf'? y
[root@zabbix_server fonts]# ls
graphfont.ttf graphfont.ttf.bak
[root@zabbix_server fonts]#
OK
三.在另一台服务器安装zabbix客户端;
3.1安装zabbix源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
3.2安装agent客户端
[root@zabbix_server ~]# yum install zabbix-agent -y
3.3配置agent客户端
[root@zbbix_client ~]# vim /etc/zabbix/zabbix_agentd.conf
//配置Server地址
Server=192.168.110.10
//设置开机自启zabbix-agent
[root@zbbix_client ~]# systemctl enable zabbix-agent.service
//启动zabbix-agent
[root@zbbix_client ~]# systemctl start zabbix-agent.service
//从启zabbix-agent
systemctl restart zabbix-agent.service
//查看zabbix-agent状态
systemctl status zabbix-agent.service
//查看是否启动
[root@zbbix_client ~]# ss -ntl
3.4测试客户端是否可用,在服务端安装get;创建监控项
[root@zabbix_server ~]# yum install zabbix-get.x86_64
//测试K
[root@zabbix_server ~]# zabbix_get -s 192.168.110.11 -k agent.hostname
Zabbix server