Centos7下安装部署Zabbix-server

Centos7下安装部署Zabbix-server

来源:CSDN
原文:https://blog.csdn.net/yuki5233/article/details/90078727

Zabbix简介

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent。

zabbix server可以通过SNMP,zabbix-agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,FreeBSD,Open BSD,OS X等平台上。

服务器准备

主机信息+IP地址

# 一台虚拟机
hostname:Zabbix-server
ip:server_ip_address

查看主机的系统版本信息

[yuki@Zabbix-server tools]$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

暂时关掉防火墙和Selinux

[yuki@Zabbix-server tools]$ sudo firewall-cmd --state
running
[yuki@Zabbix-server tools]$ cat /etc/sysconfig/selinux 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
---------------------------------------------------------------------------------------------------------------------------------------
[yuki@Zabbix-server tools]$ sudo systemctl stop firewalld.service
[yuki@Zabbix-server tools]$ sudo firewall-cmd --state                 
not running

[yuki@Zabbix-server tools]$ sudo setenforce 0  &&   sudo getenforce
[yuki@Zabbix-server tools]$ sudo sed -i  "s/SELINUX=enforcing/SELINUX=disabled/g"  /etc/sysconfig/selinux 

安装Zabbix-server需要的环境(LAMP: httpd服务+数据库服务+php)

LAMP介绍

LAMP:Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。

LNMP:LNMP指的是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。可以在VPS、独立主机上轻松的安装LNMP生产环境。

安装apache也就是httpd服务

直接yum安装

[yuki@Zabbix-server tools]$ sudo yum install -y httpd
[yuki@Zabbix-server tools]$ sudo  rpm -qa|grep httpd
httpd-2.4.6-89.el7.centos.x86_64
httpd-tools-2.4.6-89.el7.centos.x86_64

设置httpd服务开机自启动

[yuki@Zabbix-server tools]$ sudo systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[yuki@Zabbix-server tools]$ echo $?

启动httpd服务

[yuki@Zabbix-server tools]$ sudo systemctl start httpd && sudo echo $?
0

查看是否启动成功

[yuki@Zabbix-server tools]$ sudo systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2019-05-07 11:20:50 CST; 2min 24s ago   ###active (running)###
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 18729 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─18729 /usr/sbin/httpd -DFOREGROUND
           ├─18730 /usr/sbin/httpd -DFOREGROUND
           ├─18731 /usr/sbin/httpd -DFOREGROUND
           ├─18732 /usr/sbin/httpd -DFOREGROUND
           ├─18733 /usr/sbin/httpd -DFOREGROUND
           └─18734 /usr/sbin/httpd -DFOREGROUND

5月 07 11:20:50 Zabbix-server systemd[1]: Starting The Apache HTTP Server...
5月 07 11:20:50 Zabbix-server httpd[18729]: AH00557: httpd: apr_sockaddr_info_get() failed for Zabbix-server
5月 07 11:20:50 Zabbix-server httpd[18729]: AH00558: httpd: Could not reliably determine the server's fully qualified ...essage
5月 07 11:20:50 Zabbix-server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

通过端口号查看httpd服务是否启动成功

[yuki@Zabbix-server tools]$ sudo lsof -i:80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   18729   root    4u  IPv6  51904      0t0  TCP *:http (LISTEN)
httpd   18730 apache    4u  IPv6  51904      0t0  TCP *:http (LISTEN)
httpd   18731 apache    4u  IPv6  51904      0t0  TCP *:http (LISTEN)
httpd   18732 apache    4u  IPv6  51904      0t0  TCP *:http (LISTEN)
httpd   18733 apache    4u  IPv6  51904      0t0  TCP *:http (LISTEN)
httpd   18734 apache    4u  IPv6  51904      0t0  TCP *:http (LISTEN)

安装数据库—存储zabbix采集到的数据

直接yum安装

注意:因为7版本的mysql要收费,所以我们这里安装mariadb代替mysql

[yuki@Zabbix-server tools]$ sudo yum install -y mariadb mariadb-server
[yuki@Zabbix-server tools]$ sudo rpm -qa mariadb
mariadb-5.5.60-1.el7_5.x86_64
[yuki@Zabbix-server tools]$ sudo rpm -qa mariadb-server
mariadb-server-5.5.60-1.el7_5.x86_64

设置mysql服务开机自启动

[yuki@Zabbix-server tools]$  sudo systemctl enable mariadb.service  && sudo echo $?
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

启动mysql服务

[yuki@Zabbix-server tools]$ sudo systemctl start mariadb.service  && echo $?
0


### 检查数据库是否启动成功

[yuki@Zabbix-server tools]$ sudo lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  19065 mysql   13u  IPv4  54342      0t0  TCP *:mysql (LISTEN)

[yuki@Zabbix-server tools]$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]> select version();
+----------------+
| version()      |
+----------------+
| 5.5.60-MariaDB |
+----------------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit;
Bye

安装php环境

[yuki@Zabbix-server tools]$ sudo yum install -y php php-mysql
[yuki@Zabbix-server tools]$ echo $?
0
[yuki@Zabbix-server tools]$ sudo rpm -qa|grep php 缺少哪些包,直接yum install -y + 所有包(例:php-cli)
php-cli-5.4.16-46.el7.x86_64
php-bcmath-5.4.16-46.el7.x86_64
php-ldap-5.4.16-46.el7.x86_64
php-pdo-5.4.16-46.el7.x86_64
php-5.4.16-46.el7.x86_64
php-mbstring-5.4.16-46.el7.x86_64
php-xml-5.4.16-46.el7.x86_64
php-gd-5.4.16-46.el7.x86_64
php-common-5.4.16-46.el7.x86_64
php-mysql-5.4.16-46.el7.x86_64

正式安装Zabbix-server

注意:zabbix-server也要监控自身,所以也要同时安装zabbix-agent

下载zabbix的rpm安装包

[yuki@Zabbix-server tools]$ cd /home/tools/

### 第一种下载安装rpm包的方法 ####    
[yuki@Zabbix-server tools]$  sudo wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[yuki@Zabbix-server tools]$ ll
总用量 875952
-rw-r--r--. 1 root root     13572 8月  28 2017 zabbix-release-3.4-2.el7.noarch.rpm

[yuki@Zabbix-server tools]$ sudo yum install -y zabbix-release-3.4-2.el7.noarch.rpm 
[yuki@Zabbix-server tools]$ rpm -qa |grep  zabbix
zabbix-release-3.4-2.el7.noarch

### 第二种下载安装rpm包的方法 ####
[yuki@Zabbix-server tools]$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
获取http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.RJZaYd: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
        软件包 zabbix-release-3.4-2.el7.noarch 已经安装

安装zabbix*

[yuki@Zabbix-server tools]$ sudo yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
[yuki@Zabbix-server tools]$ sudo rpm -qa  zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
zabbix-web-mysql-3.4.15-1.el7.noarch
zabbix-get-3.4.15-1.el7.x86_64
zabbix-web-3.4.15-1.el7.noarch
zabbix-server-mysql-3.4.15-1.el7.x86_64
zabbix-agent-3.4.15-1.el7.x86_64
zabbix-sender-3.4.15-1.el7.x86_64

如果安装失败,如下面

zabbix-web-3.4.15-1.el7.noarch FAILED
http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-web-3.4.15-1.el7.noarch.rpm: [Errno 14] HTTP Error 416 - Requested Range Not Satisfiable- ETA
Trying other mirror.
zabbix-agent-3.4.15-1.el7.x86_ FAILED
http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.15-1.el7.x86_64.rpm: [Errno 14] HTTP Error 416 - Requested Range Not SatisfiableETA
Trying other mirror.

出现上面错误,可以修改zabbix.repo文件

[root@localhost conf.d]# vim /etc/yum.repos.d/zabbix.repo  将baseusrl改成阿里云源的地址,默认是zabbix官方源地址

[zabbix]
name=Zabbix Official Repository - $basearch
`baseurl`=http://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
`baseurl`=http://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1


在数据库中创建一个zabbix库并设置为utf8的字符编码格式

[yuki@Zabbix-server tools]$ mysql -uroot -p
Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-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)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye

向zabbix库导入表 — 初始化zabbix数据

[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ sudo rpm -qa zabbix-server-mysql
zabbix-server-mysql-3.4.15-1.el7.x86_64
[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ cd /usr/share/doc/zabbix-server-mysql-3.4.15
[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ ll
总用量 2120
-rw-r--r--. 1 root root      98 11月 12 18:50 AUTHORS
-rw-r--r--. 1 root root  866545 11月 12 18:50 ChangeLog
-rw-r--r--. 1 root root   17990 11月 12 18:50 COPYING
-rw-r--r--. 1 root root 1267039 11月 12 18:54 create.sql.gz    ### ###
-rw-r--r--. 1 root root      52 11月 12 18:50 NEWS
-rw-r--r--. 1 root root    1062 11月 12 18:50 README

解压sql文件

[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ sudo gunzip create.sql.gz  ###使用gunzip命令
[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ ll
总用量 5756
-rw-r--r--. 1 root root      98 11月 12 18:50 AUTHORS
-rw-r--r--. 1 root root  866545 11月 12 18:50 ChangeLog
-rw-r--r--. 1 root root   17990 11月 12 18:50 COPYING
-rw-r--r--. 1 root root 4990625 11月 12 18:54 create.sql
-rw-r--r--. 1 root root      52 11月 12 18:50 NEWS
-rw-r--r--. 1 root root    1062 11月 12 18:50 README

### 对表进行导入

[yuki@Zabbix-server zabbix-server-mysql-3.4.15]$ mysql -uzabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-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)]> use zabbix;
Database changed
MariaDB [zabbix]> source create.sql;
MariaDB [zabbix]> show tables;
MariaDB [zabbix]> exit;

配置zabbix server配置文件

[yuki@Zabbix-server ~]$ cd /etc/zabbix   
[yuki@Zabbix-server zabbix]$ ll
总用量 28
drwxr-x---. 2 apache apache    32 5月   7 11:52 web
-rw-r--r--. 1 root   root   10632 11月 12 18:55 zabbix_agentd.conf
drwxr-xr-x. 2 root   root      37 5月   7 11:52 zabbix_agentd.d
-rw-r-----. 1 root   zabbix 15527 11月 12 18:55 zabbix_server.conf    #####

[yuki@Zabbix-server zabbix]$ sudo vi zabbix_server.conf
### 编辑之后的配置文件内容如下:
[yuki@Zabbix-server zabbix]$ sudo egrep -v "^$|^#"  zabbix_server.conf 
# Include=/usr/local/etc/zabbix_server.general.conf
# Include=/usr/local/etc/zabbix_server.conf.d/
# Include=/usr/local/etc/zabbix_server.conf.d/*.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost   ####
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

设置zabbix-server服务开机自启动

[yuki@Zabbix-server zabbix]$ sudo systemctl enable zabbix-server.service  && echo $?     
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.

启动zabbix-server

[yuki@Zabbix-server zabbix]$ sudo systemctl start zabbix-server.service  && echo $?       
0
### 检查zabbix-server是否启动成功?注意:zabbix-server服务没有端口。
[yuki@Zabbix-server zabbix]$  sudo ps -ef |grep zabbix_server

注意:是过滤zabbix_server而不是zabbix-server

因为:在sudo systemctl start zabbix-server.service启动的时候,

实际上是调用的 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf 命令

设置zabbix-server服务开机自启动

[yuki@Zabbix-server zabbix]$ sudo systemctl enable zabbix-server.service  && echo $?     
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.

开始LAMP和Zabbix-server的关联配置

配置httpd相关联的zabbix配置文件

[yuki@Zabbix-server conf.d]$ ll
总用量 24
-rw-r--r--. 1 root root 2926 4月  24 21:45 autoindex.conf
-rw-r--r--. 1 root root  691 10月 31 2018 php.conf
-rw-r--r--. 1 root root  366 4月  24 21:46 README
-rw-r--r--. 1 root root 1252 4月  24 21:44 userdir.conf
-rw-r--r--. 1 root root  824 4月  24 21:44 welcome.conf
-rw-r--r--. 1 root root  870 7月  30 2018 zabbix.conf    ###修改这个文件配置###
[yuki@Zabbix-server conf.d]$ cat   /etc/httpd/conf.d/zabbix.conf        
#
# Zabbix monitoring system php web frontend
#

Alias /zabbix /usr/share/zabbix

<Directory "/usr/share/zabbix">   ###zabbix-server安装路径####
    Options FollowSymLinks
    AllowOverride None
    Require all granted

    <IfModule mod_php5.c>
        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 max_input_vars 10000
        php_value always_populate_raw_post_data -1
        # php_value date.timezone Europe/Riga
         php_value date.timezone Asia/Shanghai     ###配置时区###
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/app">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/include">
    Require all denied
</Directory>

<Directory "/usr/share/zabbix/local">
    Require all denied
</Directory>

重启httpd服务

[yuki@Zabbix-server conf.d]$ sudo systemctl restart httpd.service && echo $?

登录zabbix的web管理页面进行初始化配置

访问地址:http://server_ip_address/zabbix/setup.php

注意:Password是我们之前设置的数据库密码zabbix

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值