安装zabbix3.4的过程(一)

 目录

zabbix服务端安装(centos7.4)

zabbix客户端安装 (centos6.9)

注释:本次安装为官方推荐的yum安装方式,如果需要编译安装,请查看下边的博文:

博文地址:https://www.yuhuashi.info/post/75.html

包下载地址:https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/

 

1、系统环境

#系统版本:
[root@zabbix ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core) 
[root@zabbix ~]# uname -r
3.10.0-693.el7.x86_64

#关闭sellinux
[root@zabbix ~]# sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
[root@zabbix ~]# setenforce 0
[root@zabbix ~]# getenforce 
Permissive

#同步时间
yum -y install ntpdate ntpdate time.windows.com
#同步时间到硬件,防止系统重启时间不一致
hwclock --systohc
注释:如果时区为12小时制,需要操作如下
 scp -P  50000 122.114.200.186:/usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/ 拷贝本地正常的文件到对方服务器上覆盖

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#设置定时任务
[root@zabbix ~]# crontab -e
no crontab for root - using an empty one
59 23 * * * /usr/sbin/ntpdate time.windows.com && /usr/sbin/hwclock -w

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

#开放所需端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --reload

 

#查看

firewall-cmd --zone= public --query-port=80/tcp

#删除

firewall-cmd --zone= public --remove-port=80/tcp --permanent

 

 2、软件安装

yum install mariadb-server mariadb -y

mariadb数据库的相关命令是:
systemctl start mariadb  #启动MariaDB
systemctl stop mariadb  #停止MariaDB
systemctl restart mariadb  #重启MariaDB
systemctl enable mariadb  #设置开机启动

 

3、安装zabbix

https://www.zabbix.com/download

这里选择yum安装方式

1、安装阿里epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2、安装zabbix源
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
3、安装zabbix服务软件
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
注释:server和web链接数据库的文件

4、创建初始数据库:
 mysql -uroot -p


 mysql> create database zabbix character set utf8 collate utf8_bin;


 mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'yanqi';


 mysql> quit;

注释:如果数据库不在本地需要添加如下

 mysql> grant all on zabbix.* to zabbix@172.16.%.% identified by 'yanqi';

 

注释:mysql8.0的添加方式不一样,添加过程如下:

create database zabbix character set utf8 collate utf8_bin;

create user 'zabbix'@'localhost' identified by 'yanqi';

grant all privileges on zabbix.* to 'zabbix'@'localhost' with grant option;

 

5、导入模板和数据(密码为 yanqi )

 zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

 

6、为zabbix服务配置数据库

[root@zabbix ~]# grep -Ev -n '^$|#' /etc/zabbix/zabbix_server.conf 
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
101:DBName=zabbix
117:DBUser=zabbix
126:DBPassword=yanqi

或

sed -i.ori '126a DBPassword=yanqi' /etc/zabbix/zabbix_server.conf

 

7、为zabbix前端配置php

Zabbix前端的Apache配置文件位于/etc/httpd/conf.d/zabbix.conf中。一些PHP设置已经配置好。但有必要取消注释“date.timezone”设置并为您设置正确的时区。

php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai

或

sed -i.ori '19a php_value date.timezone  Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

 

8、解决中文乱码

yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

 

8、启动zabbix服务并开机自启

systemctl start zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd

 

 注:服务器重启后可以正常使用

 

4、配置zabbix前端

https://www.zabbix.com/documentation/3.4/manual/installation/install#installing_frontend

 

 好啦,安装到此结束!!!

 

 

zabbix客户端安装

 客户端的软件包可以单独下载:直接安装的包:http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.15-1.el7.x86_64.rpm

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
yum -y install zabbix-agent 
sed -i.ori "s#Server=127.0.0.1#Server=10.0.0.200#g" /etc/zabbix/zabbix_agentd.conf    #更换成server端的IP地址
/etc/init.d/zabbix-agent start
注释:
1、在客户端,如果有多个Servr可以使用逗号隔开
2、server端需要安装agent用于监控自己,Server和ServerActive参数必须是127.0.0.1,如果是多个IP可以使用逗号隔开; #写入开机启动 cat >>/etc/rc.d/rc.local<<EOF /etc/init.d/zabbix-agent start EOF

  

检查连通性

#服务器端安装zabbix-get检查工具
yum install zabbix-get -y
#只能在服务端测试
[root@zabbix ~]# zabbix_get -s 10.0.0.199 -p 10050 -k "system.cpu.load[all,avg1]"
0.300000

  

在server端添加监控

 

添加主机完成!

 

 

查看文章:

官网安装文档:https://www.zabbix.com/download

博主文章:https://www.cnblogs.com/clsn/p/7885990.html#auto_id_0

 

zabbix修改mariadb的数据存储位置

#创建
mkdir /公司缩写/mysql

#停止数据库服务
systemctl status mariadb.service
systemctl stop mariadb.service

#把数据库文件移动到新的存储位置
cp -rp /var/lib/mysql/ /公司缩写/mysql/


#修改后的数据库配置文件
[root@iZkdZ ~]# cat /etc/my.cnf
[mysqld]
datadir=/公司缩写/mysql
socket=/公司缩写/mysql/mysql.sock
lower_case_table_names         = 1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
 
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d


#启动数据库
systemctl start mariadb.service 
systemctl status mariadb.service


#新的登录数据库的命令,需要指定mysql.sock
mysql -uzabbix -p123456 -S /公司缩写/mysql/mysql.sock

#创建软链接,否则,zabbix页面无法打开
mkdir /var/lib/mysql
ln -s /公司缩写/mysql/mysql.sock /var/lib/mysql/mysql.sock
  在这一步之前,我是把原始的/var/lib/mysql目录改名为/var/lib/mysql_ori。所以,会有创建/var/lib/mysql的命令。在下面确认重启zabbix服务端没有问题,web界面可以正常打开。我才把原始的/var/lib/mysql目录移动到/tmp目录,后来又移动到公司默认的目录,作为备份存放。


#重启zabbix
systemctl restart zabbix-server.service

参考资料:
http://www.cnblogs.com/seasonsstory/archive/2013/07/24/3209785.html——zabbix连不上数据库
http://blog.chinaunix.net/uid-20749043-id-1878317.html——更换mysql存储路径

 

posted @ 2018-02-13 17:17  无敌仙人掌  阅读(395)  评论(0编辑  收藏  举报
AmazingCounters.com