通过源代码编译安装,可以安装Zabbix最新及任何版本。
本示例以目前最新的版本4.4.7为例。
操作系统:CentOS Linux release 7.5.1804 (Core)
数据库类型:Mysql-8.0.19
1.配置Zabbix的yum源
安装阿里云Zabbixyum源:
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
查看yum源列表:
yum repolist
1.下载并解压源代码
获取源码包:
sudo wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.7/zabbix-4.4.7.tar.gz
解压源码包:
sudo tar -zxvf zabbix-4.4.7.tar.gz
2.添加zabbix用户组及用户
添加用户组zabbix:
sudo groupadd --system zabbix
添加用户zabbix:
sudo useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
3.安装Mysql数据库及创建Zabbix用户及初始化数据
获取Mysql免安装包:
sudo wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
解压Mysql免安装包:
sudo tar -xf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
移动解压后的Mysql安装包:
示例是安装到/usr/local下:
sudo mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/
建立Mysql的软连接:
sudo ln -s /usr/local/mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql
添加用于Mysql数据库所属的用户组:
sudo groupadd mysql
添加用于Mysql数据库所属的用户:
sudo useradd -r -g mysql -s /bin/false mysql
创建Mysql数据库的数据存放目录:
sudo mkdir /usr/local/mysql/data
修改Mysql数据库数据存放目录所属用户及用户组:
sudo chown -R mysql:mysql /usr/local/mysql/data
修改Mysql数据库数据存放目录的权限:
sudo chmod -R 750 /usr/local/mysql/data
修改Mysql的配置文件:
Mysql默认配置文件地址为:/etc/my.cnf(根据实际情况进行配置)
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=error.log
transaction_isolation = READ-COMMITTED
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1
如果没有/tmp/mysql目录,则需要创建并修改所属用户及用户组:
创建目录:
sudo mkdir /tmp/mysql
修改所属用户及用户组:
sudo chown mysql:mysql -R /tmp/mysql
Mysql初始化:
sudo /usr/local/mysql/bin/mysqld --initialize --user=mysql
如果执行此命令出现如下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
则安装对应的依赖包:
sudo yum install libaio-devel
查看初始化日志:
sudo cat /usr/local/mysql/data/error.log
mysql首次登录时,需要通过图片中初始化的密码进行登录。
开启ssl:
sudo /usr/local/mysql/bin/mysql_ssl_rsa_setup
启动mysqld,并查看是否可以正常启动:
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
通过以上执行可以判断mysql安装有没有问题,执行完成之后敲回车,然后查看日志:
sudo cat /usr/local/mysql/data/error.log
注册Mysql服务:
拷贝注册服务的文件:
sudo scp /usr/local/mysql/support-files/mysql.server /etc/init.d/
启用服务设置为开机启动:
sudo systemctl enable mysql.server
启动Mysql服务:
sudo systemctl start mysql.server
查看Mysql服务启动状态:
sudo systemctl status mysql.server
修改登录Mysql并修改root密码:
sudo /usr/local/mysql/bin/mysql -u root -p
输入初始化mysql时, /usr/local/mysql/data/error.log文件里面初始的root用户密码完成mysql链接登录。
登录成功之后,执行root密码修改:
alter user root@localhost identified by '用户用户密码';
flush privileges;
quit;
创建zabbix对应mysql的用户及数据库并授权:
mysql -uroot -p
password
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified with mysql_native_password by '用户密码';
grant all privileges on zabbix.* to zabbix@localhost;
quit;
初始化数据库数据:
/usr/local/mysql/bin/mysql -u zabbix -p zabbix < zabbix-4.4.7/database/mysql/schema.sql
/usr/local/mysql/bin/mysql -u zabbix -p zabbix < zabbix-4.4.7/database/mysql/images.sql
/usr/local/mysql/bin/mysql -u zabbix -p zabbix < zabbix-4.4.7/database/mysql/data.sql
登录并查看初始化的表结构:
/usr/local/mysql/bin/mysql -u zabbix -p
use zabbix;
show tables;
quit;
4.从源码配置安装Zabbix
进入解压后的zabbix目录。
查看Zabbix的版本:
./configure --version
通过帮助查看可以配置的参数内容:
./configure --help
4.1安装zabbix-server
安装对应的依赖软件包:
sudo yum install wget telnet net-tools python-paramiko gcc gcc-c++ dejavu-sans-fonts python-setuptools python-devel sendmail mailx net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC libevent-devel mysql-devel libxml2-devel libssh2-devel OpenIPMI-devel java-1.8.0-openjdk-devel openldap-devel curl-devel unixODBC-devel
创建安装目录,并修改该目录所属用户组用户;
sudo mkdir -p /soft/zabbix/
sudo chown -R zabbix:zabbix /soft/zabbix
进入源码包解压目录进行编译及安装:
./configure --prefix=/soft/zabbix --enable-server --enable-java --with-mysql --with-libxml2 --with-unixodbc --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv
make
make install
查看 zabbix-server安装的版本:
/soft/zabbix/sbin/zabbix_server --version
建立软连接:
sudo ln -s /soft/zabbix/sbin/zabbix_server /usr/local/sbin/
注册zabbix-server服务:
进入源码包解压目录,执行拷贝
sudo cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix.server
sudo systemctl enable zabbix.server
编辑zabbix-server的配置文件的数据库连接信息:
sudo vi /soft/zabbix/etc/zabbix_server.conf
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=创建时的密码
启动zabbix-server服务:
sudo systemctl start zabbix.server
开放对应的协议端口:
sudo firewall-cmd --zone=public --add-port=10051/tcp --permanent
sudo firewall-cmd --zone=public --add-port=10051/udp --permanent
4.2安装Zabbix-Web
4.2.1安装PHP环境:
下载php源码安装包:
sudo wget https://www.php.net/distributions/php-7.4.4.tar.xz
解压php源码安装包并进入解压的目录:
sudo tar -xf php-7.4.4.tar.xz
sudo cd php-7.4.4
安装依赖包:
sudo yum install -y php-mysql gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers sqlite-devel oniguruma oniguruma-devel
编译安装:
创建安装目录:
sudo mkdir /usr/local/php
sudo cd php-7.4.4
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-libdir=lib64 --enable-gd --enable-mbstring --enable-bcmath --with-mysqli --with-gettext --with-ldap --with-pdo-mysql=mysqlnd --without-pear --disable-phar --enable-sockets --with-zlib --with-xmlrpc --enable-fpm --enable-xml --enable-sockets --with-zlib --with-iconv --enable-soap --enable-pcntl --enable-cli --with-curl --with-jpeg --with-freetype
然后重新执行上面的命令
make
make install
复制配置文件:
sudo cp php.ini-production /usr/local/php/php.ini
注册服务开机启动:
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm
sudo systemctl enable php-fpm
修改php-fpm配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
去掉pid = run/php-fpm.pid前面的;
sudo cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
启动php的服务:
sudo systemctl start php-fpm
查看php服务启动的状态:
sudo systemctl status php-fpm
4.2.2安装Nginx环境:
下载Nginx的安装源码包:
sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压源码安装包并进入解压后的目录:
sudo tar -xf nginx-1.16.1.tar.gz
sudo cd nginx-1.16.1
添加用户组及用户:
sudo groupadd --system www
sudo useradd --system -g www -s /sbin/nologin -c "nginx www" www
进行编译安装:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_gzip_static_module --with-http_sub_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_mp4_module --with-http_flv_module --with-http_realip_module
make
make install
设置nginx开机启动:
sudo touch /usr/lib/systemd/system/nginx.service
sudo vi /usr/lib/systemd/system/nginx.service
放入如下内容:
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
设置开机启动:
sudo systemctl enable nginx.service
启动nginx 服务:
sudo systemctl start nginx.service
查看nginx服务状态:
sudo systemctl status nginx.service
4.2.3 zabbix-web安装:
创建zabbix web的文件目录:
sudo mkdir /soft/zabbix-web/
复制web的php文件到创建的目录:
sudo cp -r /root/zabbix-4.4.7/frontends/php/* /soft/zabbix-web/
在nginx配置zabbix web信息:
sudo vi /usr/loca/nginx/conf/nginx.conf
修改内容如下:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root /soft/zabbix-web;
index index.html index.php;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
测试一下配置文件是否正确:
/usr/local/nginx/sbin/nginx -t
重启ngixn 服务
sudo systemctl restart nginx.service
开放80端口:
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
然后访问zabbix-web 的应用地址:http://ip
然后点击Next step
根据检测结果配置对应的php配置,配置内容如下:
sudo vi /usr/local/php/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = "Asia/Shanghai"
重新php服务:
sudo systemctl restart php-fpm
然后再访问即可,然后点击Next step执行数据库连接信息配置。
配置完数据库继续一直点击“Next step”至到 Finish
然后登录即可:
然后输入默认账号信息进行登录。
账号:Admin 密码:zabbix
4.3安装Zabbix-Agent
创建安装目录,并修改该目录所属用户组用户;
sudo mkdir -p /soft/zabbix/
sudo chown -R zabbix:zabbix /soft/zabbix
进入源码包解压目录进行编译及安装:
./configure --prefix=/soft/zabbix --enable-agent
make
make install
查看 zabbix-agent安装的版本:
/soft/zabbix/sbin/zabbix_agentd --version
建立软连接:
sudo ln -s /soft/zabbix/sbin/zabbix_agentd /usr/local/sbin/
注册zabbix-agent服务:
进入源码包解压目录,执行拷贝
sudo cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix.agentd
sudo systemctl enable zabbix.agentd
编辑zabbix-agent的配置文件的数据库连接信息:
sudo vi /soft/zabbix/etc/zabbix_agentd.conf
根据实际情况修改对应的Hostname及Zabbix Server 所在服务器的ip地址:
Hostname=Zabbix server
Server=Zabbix Server的ip地址
ServerActive=Zabbix Server的ip地址
启动zabbix-agent服务:
sudo systemctl start zabbix.agentd
开放对应的协议端口:
sudo firewall-cmd --zone=public --add-port=10050/tcp --permanent
sudo firewall-cmd --zone=public --add-port=10050/udp --permanent
至此通过源码安装Zabbix相应的内容已全部完成。