因为zabbix web服务需要用到php7.2所以先安装php7.2
如果已经安装了更高的版本的php,安装 zabbix_web的时候就跳过依赖
安装依赖
yum install libmcrypt libmcrypt-devel mcrypt mhash
如果之前有用yum安装其他版本的php先卸载:
yum remove php70*
安装php7.2
yum -y install php72w php72w-common php72w-devel php72w-gd php72w-mysqlnd php72w-pecl-memcached php72w-pecl-redis php72w-opcache php72w-fpm php72w-mbstring php72w-bcmath php72w-cli php72w-pecl-igbinary php72w-mcrypt php72w-pdo php72w-xml php72w-pear php72w-process
因为php 7.1 之后不在默认安装mcrypt扩展,所以这里需要手动安装
get http://pecl.php.net/get/mcrypt-1.0.1.tgz
tar xf mcrypt-1.0.1.tgz
cd mcrypt-1.0.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config && make && make install (php-config位置可能会不一样)
在php.ini加上扩展即可
extension=mcrypt.so
查看是否安装成功:
php -m | grep -i mc
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install -y zabbix-server-mysql
安装 zabbix-server-mysql 有时候会报错:
No more mirrors to try
zabbix.repo里面的源换成清华源
vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
#baseurl=http://repo.zabbix.com/zabbix/4.0/rhel/7/\$basearch/
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/\$basearch/
#这里我们换成清华的yum源
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - \$basearch
#baseurl=http://repo.zabbix.com/zabbix/4.0/rhel/7/\$basearch/debuginfo/
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/\$basearch/debuginfo/
#换了上面Zabbix的安装源地址,其组件地址也要记得换!
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
#baseurl=http://repo.zabbix.com/non-supported/rhel/7/\$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\n
gpgcheck=1
或者一直运行:
yum install -y zabbix-server-mysql
其他两个 zabbix-web-mysql、zabbix-agent 以同样的方法安装
yum install -y zabbix-web-mysql
yum install -y zabbix-agent
create database zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT all ON zabbix.* TO ‘zabbix’@’%’ IDENTIFIED BY ‘1qaz2wsx’ with grant option;
grant all on zabbix.* to ‘zabbix’@‘localhost’ identified by ‘1qaz2wsx’ with grant option
flush privileges;
zcat /usr/share/doc/zabbix-server-mysql-4.0.22/create.sql.gz | mysql -uzabbix -p -h localhost zabbix #导入数据到数据库zabbix中(最后一个zabbix是数据库zabbix),且因为用户zabbix是%(任意主机),密码是用户zabbix登陆密码123456
vim /etc/zabbix/zabbix_server.conf
修改数据库密码:
DBPassword=123456
php.ini 时区修改:
date.timezone = PRC
直接运行 (默认配置文件地址 /etc/zabbix/zabbix_server.conf)
zabbix_server
server {
listen 8090;
server_name _;
root /usr/share/zabbix;
index index.php;
charset utf-8;
client_max_body_size 8m;
error_page 404 /404.html;
location = /404.html {
return 404 'Sorry, File not Found!';
}
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
通过ip地址访问
提示fail的php配置需要修改,并重启php-fpm
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TNdeK6P4-1593653899133)(http://note.youdao.com/yws/res/28082/8C8BBA9F5F1945E3AF526933F3EDE3DF)]
如果使用localhost配置失败,那么就用内网地址,因为用localhost需要使用 mysql.sock 的方式访问, 需要修改php配置
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8xE4IT5C-1593653899135)(http://note.youdao.com/yws/res/28093/B7B6515A151B48F680B50782769085B9)]
这里的host需要修改成与 /etc/zabbix/zabbix_server.conf 中监听的地址一致,外网的话就外网地址,内网的话就填内网地址
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-P46engRI-1593653899136)(http://note.youdao.com/yws/res/28103/20E530D08AE14E94AB4B27C4BA4B5B02)]
zabbix 默认的账号密码 :
Admin (账号,A要大写)
zabbix (密码)