Ubuntu18安装zabbix
-
所需工具
- MySQL5.7
- PHP7.2
- apache2
-
准备工作
出于安全考虑, zabbix 只使用普通用户运行,假如你当前用户叫 dog,运行zabbix后,便以 dog 身份运行。但
是如果你在 root 环境下运行 zabbix,那么 zabbix 将会主动尝试以 zabbix 身份来运行。所以这里需要创建zabbix 的用户,如下:
groupadd zabbix
useradd -g zabbix zabbix
passwd zabbix
1、 安装apache、mysql、php
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php php-mbstring php-gd php-xml php-bcmath php-ldap php-mysql
2、 修改php时区
-
打开php配置文件
vim /etc/php/7.2/apache2/php.ini
-
修改内容
; http://php.net/date.timezone date.timezone = 'Asia/Shanghai'
3、 zabbix安装
```
sudo apt-get update
apt install zabbix-server-mysql zabbix-frontend-php
apt install zabbix-agent
apt install zabbix-get
```
-
此处可能会报错,需要安装依赖库,可以切换镜像源然后刷新再安装
- 打开镜像源配置文件:
vim /etc/apt/sources.list
-
替换为阿里镜像源:
# Aliyun deb-src http://archive.ubuntu.com/ubuntu bionic main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ bionic universe deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu bionic partner deb-src http://archive.canonical.com/ubuntu bionic partner deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse
-
重新打开命令提示符执行第三步
4、 数据库配置
shell> mysql -uroot -p<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
mysql> flush privileges;
mysql> quit;
5、 初始化zabbix数据库
cd /usr/share/doc/zabbix-server-mysql
zcat create.sql.gz | mysql -uroot zabbix
6、 配置和启动zabbix
-
打开zabbix配置文件
vim /etc/zabbix/zabbix_server.conf
-
修改如下配置
DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=password
- 参数说明:
DBHost 数据库地址,默认localhost,这里建议写为真实的IP地址或127.0.0.1。当然,如果用localhost自然是可以的,在虚拟机里,会产生一些报错如果出现了报错也没关系,可以通过本博客或者网上搜索找到解决方法。
DBName 数据库名称,在5.1中,已经zabbix配置了zabbix数据库,这里自然是zabbix
DBUser 数据库用户,这个也好理解,zabbix软件就用这个身份登录MySQL
DBPassword 数据库密码。注意,这里的密码并不是你的root密码,而是在5步骤中创建zabbix用户的密码。
- 参数说明:
-
重启zabbix进程
service zabbix-server start
7、 编辑Zabbix前端的PHP配置
-
打开PHP配置文件
vim etc/apache2/conf-enabled/zabbix.conf
-
修改文件(php5和php7两个配置)
php_value date.timezone Asia/Shanghai
-
重启apache服务器
service apache2 restart
-
参考文献
https://www.jianshu.com/p/5968c5a9b5d0
https://www.jianshu.com/p/4601b294fcc1