系统环境
OS: centos7.5
software: zabbix 4.0 LTS
DBSever: MariaDB-10.2.15
一、需要先把数据库装上,这里用到的是mariadb 二进制包安装
1、下载二进制包,
官网的下载路径:
wget http://mirrors.neusoft.edu.cn/mariadb//mariadb-10.2.15/bintar-linux-x86_64/mariadb-10.2.15-linux-x86_64.tar.gz
2、添加组和用户
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -g mysql -u 306 -r mysql
3、解压mariadb二进制包到/usr/local下去
[[email protected] ~]# tar xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local/
4、进入到/usr/local下面创建mysql的软连接
[[email protected] ~]# cd /usr/local/
[[email protected] /usr/local]# ln -s mariadb-10.2.15-linux-x86_64/ mysql
5、修改mysql的相对应的属主和属组权限
[[email protected] /usr/local]# chown -R root.mysql mysql/
6、创建数据文件的存放路径,并修改所属组的权限为mysql
[[email protected] ~]# cd /app/
[[email protected] /app]# mkdir mydata
[[email protected] ]# chown -R mysql.mysql /app
7、初始化数据库,指定好数据文件的存放路径和用户
[[email protected] ]# cd /usr/local/mysql/
[[email protected] /usr/local/mysql/]# scripts/mysql_install_db --datadir=/app/mydata --user=mysql
8、拷贝mariadb的启动脚本到/etc/rc.d/init.d下命名为mysqld
[[email protected] /usr/local/mysql/]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
9、把mysqld设置为开机启动
[[email protected] /usr/local/mysql/]# chkconfig --add mysqld
10、创建mariadb的配置文件存放路径,并拷贝模版文件到这个目录下命名为my.cnf
[[email protected] /usr/local/mysql/]# mkdir /etc/mysql
[[email protected] /usr/local/mysql/]#cp support-files/my-large.cnf /etc/mysql/my.cnf
11、配置系统环境变量,重读配置文件让它生效
[[email protected] /usr/local/mysql/]# vim /etc/profile.d/mysql.sh
[[email protected] /usr/local/mysql/]#export PATH=/usr/local/mysql/bin:$PATH
[[email protected] /usr/local/mysql/]# . /etc/profile.d/mysql.sh
12、修改mariadb的配置文件需要增加几条内容
[[email protected] /usr/local/mysql/]# vim /etc/mysql/my.cnf
lower_case_table_names = 1
character-set-server = utf8
datadir = /app/mydata
innodb_file_per_table = on
skip_name_resolve = o
13、启动数据库服务
[[email protected] /usr/local/mysql/]# service mysqld start
14、查看mariadb的服务端口是否正常监听
[[email protected] /app]#ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:52874 *:*
LISTEN 0 128 *:11211 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
15、数据库的安全初始操作,设置完之后就可以先创建zabbix相关的库和用户
[[email protected] /app]#mysql_secure_installation
[[email protected] /app]#mysql -uroot -p
16、创建zabbix库
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
17、给zabbix库授权并指定用户
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected]‘192.168.137.%‘ identified by ‘123456‘;
18、在另一台主机上测试用zabbix用是否能正常登陆数据库
[[email protected] ~]#mysql -uzabbix -p123456 -h192.168.137.54
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.2.15-MariaDB-log MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| zabbix |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]>
19、在zabbix server主机上导入zabbix自带的三个表,路径在/root/zabbix-4.0.1/database/mysql下后缀为.sql的三个文件
[[email protected] ~/zabbix-4.0.1]#ls -l database/mysql/
total 5816
-rw-r--r-- 1 1001 1001 3795433 Oct 30 01:36 data.sql
-rw-r--r-- 1 1001 1001 1978341 Oct 30 01:36 images.sql
-rw-r--r-- 1 root root 15323 Nov 26 22:44 Makefile
-rw-r--r-- 1 1001 1001 392 Oct 30 01:36 Makefile.am
-rw-r--r-- 1 1001 1001 15711 Oct 30 01:36 Makefile.in
-rw-r--r-- 1 1001 1001 140265 Oct 30 01:36 schema.sql
20、导入sql文件是有先后顺序的,先导schema.sql、images.sql、data.sql.
[[email protected] ~/zabbix-4.0.1/database/mysql]#mysql -uzabbix -h192.168.137.54 -p123456 zabbix < schema.sql
[[email protected] ~/zabbix-4.0.1/database/mysql]#mysql -uzabbix -h192.168.137.54 -p123456 zabbix < images.sql
[[email protected] ~/zabbix-4.0.1/database/mysql]#mysql -uzabbix -h192.168.137.54 -p123456 zabbix < data.sql
21、进到数据库里面查看zabbix库是否导入成功
[[email protected] ~/zabbix-4.0.1/database/mysql]#mysql -uzabbix -h192.168.137.54 -p123456
MariaDB [(none)]> use zabbix
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
.......
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
144 rows in set (0.00 sec)
二、编译zabbix
1、安装编译环境所需要的依赖包组
[[email protected] ~]#yum install gcc libxml2-devel libevent-devel net-snmp net-snmp-devel curl curl-devel php php-bcmath php-mbstring mariadb mariadb-devel –y
还需要安装一些php的依赖包后续在网页端安装zabbix时需要用到所以先提前安装好
[[email protected] ~]#yum install php-gettext php-session php-ctype php-xmlreader php-xmlwrer php-xml php-net-socket php-gd php-mysql -y
2、安装jdk环境,装的是jdk-8u191-linux-x64.rpm的包,要不后面编译时会报Java找不到。
[[email protected] ~]#yum -y install jdk-8u191-linux-x64.rpm
3、创建zabbix用户
[[email protected] ~]#useradd zabbix -s /sbin/nologin
4、下载zabbix的源码包
[[email protected] ~]#wget http://192.168.137.53/yum/zabbix/zabbix-4.0.1.tar.gz
5、解压源码包,并进入到解压后的目录里去
[[email protected] ~]#tar xf zabbix-4.0.1.tar.gz
[[email protected] ~]#cd zabbix-4.0.1/
[[email protected] ~/zabbix-4.0.1]#
6、开始编译安装zabbix
[[email protected] ~/zabbix-4.0.1./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
7、执行make install
[[email protected] ~/zabbix-4.0.1]#make -j 2 && make install
8、拷贝启动脚本文件到/etc/init.d目录下
[[email protected] ~/zabbix-4.0.1]#cp misc/init.d/fedora/core/* /etc/init.d/
9、拷贝过去的脚本需要修改下目录路径,server和agent都需要改
[[email protected] ~/zabbix-4.0.1]#vim /etc/init.d/zabbix_server
22 BASEDIR=/usr/local
改成:
22 BASEDIR=/usr/local/zabbix
agent启动脚本修改也是一样
[[email protected] ~/zabbix-4.0.1vim /etc/init.d/zabbix_agentd
22 BASEDIR=/usr/local
改成:
22 BASEDIR=/usr/local/zabbix
10、创建zabbix的日志存放路径和修改/usr/local/zabbix的所属主为zabbix
[[email protected] ~/zabbix-4.0.1]#mkdir /var/log/zabbix
[[email protected] ~/zabbix-4.0.1]#chown -R zabbix.zabbix /var/log/zabbix
[[email protected] ~/zabbix-4.0.1]#ll /var/log/zabbix/ -d
drwxr-xr-x 2 zabbix zabbix 6 Nov 27 09:17 /var/log/zabbix/
[[email protected] ~]#chown -R zabbix.zabbix /usr/local/zabbix/
[[email protected] ~]#ll -d /usr/local/zabbix/
drwxr-xr-x 7 zabbix zabbix 64 Nov 26 22:45 /usr/local/zabbix/
11、修改配置文件
[[email protected] ~/zabbix-4.0.1]#vim /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051 启用监听端口,不过默认也是启用的。
LogFile=/var/log/zabbix/zabbix_server.log 修改日志存放路径,默认是在/tmp下
LogFileSize=5 开启日志滚动,单位为MB、达到指定值之后就生成新的日志文件。
DebugLevel=4 日志级别等级,4为debug,利于排除错误,排错之后可以改成3级别的。
PidFile=/usr/local/zabbix/zabbix_server.pid zabbix pid文件路径默认为tmp下需要改成安装目录,并且安装目录的所属组要改成zabbix用户
# SocketDir=/tmp
User=zabbix 启动的用户默认也是zabbix,如果要改成root的话 还需要修改一项
# AllowRoot=0 需要改成1才能使用root来启动,默认0的话是被禁止用root启动,不过最好别用root
SocketDir=/usr/local/zabbix socket 文件存放路径默认在/tmp下
DBHost=192.168.137.54 数据库地址必须要填
DBName=zabbix 数据库名称
DBUser=zabbix 数据库连接用户
DBPassword=123456 数据库连接密码,建议在生产中密码不要太简单了。
DBPort=3306 数据库端口,其实也不用开默认就是3306
12、启动zabbix、并查看端口是否正常监听
[[email protected] ~/zabbix-4.0.1]#service zabbix_server start
Reloading systemd: [ OK ]
Starting zabbix_server (via systemctl): [ OK ]
[[email protected] ~/zabbix-4.0.1]#ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
13、装前端展示端
[[email protected] ~/zabbix-4.0.1]#yum -y install httpd
14、在httpd的默认工作目录下创建一个zabbix目录
[[email protected] ~/zabbix-4.0.1]#mkdir /var/www/html/zabbix
15、从zabbix解压包里面把php的所有文件拷贝到/var/www/html/zabbix目录下
[[email protected] ~/zabbix-4.0.1]#cp -a frontends/php/* /var/www/html/zabbix/
16、启动httpd、查看端口是否正常监听
[[email protected] ~]#systemctl start httpd
[[email protected] ~]#ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
17、通过网页来安装zabbix
修改php.ini 里面的值
[[email protected] ~]#vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
重启httpd服务
[[email protected] ~]#systemctl restart httpd
18、修改agent配置文档
[[email protected] ~]#vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=127.0.0.1 被动模式下的server地址、这里agent和server都在同一台上面 默认用127.0.0.1就行
ListenPort=10050 agent的监听地址为10050
StartAgents=1 开启多少个线程来采集数据,不过agent端的话默认就行,如果是server端那就要开大点
ServerActive=127.0.0.1 主动模式下的server地址
Hostname=Zabbix server 这块需要注意要跟主机上的hostname一致,而且在网页上添加监控主机时也需要添加这个要不然是找不到主机
Timeout=30 数据采集时的超时时长默认为3,需要改成最大值30
UnsafeUserParameters=1 允许做一些特殊符号的计算
# UserParameter= 自定义监控项参数时用到
19、启动zabbix server 端的agent,后续就可以采集到数据
[[email protected] ~]#service zabbix_agentd start
Starting zabbix_agentd (via systemctl): [ OK ]
[[email protected] ~]#ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
20、把zabbix_server、zabbix_agent、httpd设为开机启动
[[email protected] ~]#chkconfig zabbix_agentd on
[[email protected] ~]#chkconfig zabbix_server on
[[email protected] ~]#systemctl enable httpd
最后通过网页查看被监控的主机信息
原文地址:http://blog.51cto.com/dklwj/2322815
时间: 2024-10-07 07:18:50