安装与配置
查看环境
[root@zabbix-server ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
安装前先做简单优化,安装常用软件及关闭防火墙,配置epel源等,可写入脚本再执行
#!/bin/bash
#linux基础优化自动执行脚本
#作者:wsm
#时间:2019-7-10
#优化yum源,改为国内阿里源及配置epel源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup &&
\curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &&
\curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装常用工具及软件
yum install -y tree vim bash-completion* wget lsof nc nmap lrzsz telnet psmisc bind-utils net-tools
#关闭selinux和防火墙
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config && setenforce 0
systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager
#优化ssh
sed -i 's#GSSAPIAuthentication yes#GSSAPIAuthentication no#g' /etc/ssh/sshd_config
sed -i 's#UseDNS yes#UseDNS no#g' /etc/ssh/sshd_config
systemctl restart sshd
在这里选择安装zabbix4.0,使用清华源下载配置zabbix仓库
1.配置zabbix仓库
curl -o zabbix-release-4.0-1.el7.noarch.rpm https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
rpm -ivh zabbix-release-4.0-1.el7.noarch.rpm
2.修改zabbix的yum源为清华源,下载时可加速
[root@zabbix-server ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/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=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
可在vim中使用:%s#http://www.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#g
替换
或者使用sed -i 's#http://repo.zabbix.com#https://mirror.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo进行修改
3.执行安装命令开始安装zabbix服务端和web端
yum install zabbix-server-mysql zabbix-web-mysql -y
4.安装mariadb,创建zabbix库,授权zabbix用户
因为zabbix需要使用数据库,在C7上需要使用mariadb
注意:在这里发现tab不能自动补全,是因为在安装bash-completion*后没有source /etc/profile,在这里执行一下
yum install mariadb-server -y
systemctl start mariadb #启动数据库
systemctl enable mariadb.service #并设置为开机自启动
mysql_secure_installation #执行数据库的安全初始化
执行命令后出现一箱选项:
1.Enter current password for root (enter for none): (请输入当前的root密码)这里我没设置,直接回车
2.Set root password? [Y/n](要设置一下root密码吗)n
3.Remove anonymous users? Y/n y
4.Disallow root login remotely? Y/n y
5.Remove test database and access to it? Y/n y
6.Reload privilege tables now? [Y/n] (现在要重新加载权限列表吗) y
进入数据库中创建zabbix库修改字符集并授权
>:create database zabbix character set utf8 collate utf8_bin;
>:grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
导入zabbix表结构和初始数据
zcat /usr/share/doc/zabbix-server-mysql-4.0.*/create.sql.gz | mysql -uzabbix -p zabbix
并进入zabbix库查看
[root@zabbix-server ~]# mysql -uzabbix -p zabbix
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
.....
5.修改zabbix配置文件,使其能够连上数据库
vim /etc/zabbix/zabbix_server.conf
主要修改内容:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
启动zabbix-server并设置为开机自启动
systemctl start zabbix-server
systemctl enable zabbix-server
通过端口检查zabbix是否启动
[root@zabbix-server ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2417/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1495/master
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 17300/zabbix_server
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17019/mysqld
tcp6 0 0 :::22 :::* LISTEN 2417/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1495/master
tcp6 0 0 :::10051 :::* LISTEN 17300/zabbix_server
默认端口10051,已启动
6.修改Zabbix前端的PHP配置,并启动httpd
修改时区
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
systemctl start httpd 启动httpd
systemctl enable httpd 并设置开机自启动
使用浏览器访问我的ip,http://10.0.0.62/zabbix,发现访问不了,最后发现是防火墙没有关闭,这里执行systemctl stop firewalld NetworkManager;
image.png
并设置开机自关闭 systemctl disable firewalld NetworkManager,最后成功访问
根据网页引导只需要填写密码,以及zabbix监控的名字就可完成前端安装
image.png
默认登录zabbixweb的用户名:Admin,密码:zabbix
image.png
后期修改zabbix数据库密码的时候,需要修改的配置文件:
/etc/zabbix/web/zabbix.conf.php
网友评论