zabbix4.4.4源码编译安装

Posted imscz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix4.4.4源码编译安装相关的知识,希望对你有一定的参考价值。

zabbix4.4.4 源码编译安装

mysql 8.0.17 二进制包安装

php72 yum源安装

nginx 1.16.1 yum源安装

0.基础环境

zabbix_server 172.16.1.71
zabbix_agent 172.16.1.51

1.安装MySQL 8.0.17

(1)安装依赖包
yum install bison-devel ncurses-devel libaio-devel
(2)下载二进制包
wget -c https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
(3)解压并移动至安装目录
tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.17-linux-glibc2.12-x86_64 /usr/local/mysql
(4)创建数据库初始化目录和mysql用户,并给MySQL根目录授权
mkdir /usr/local/mysql/data
useradd -s /sbin/login -M mysql
chown mysql.mysql /usr/local/mysql -R
(5)软连接mysql库文件至系统库
ln -s /usr/local/mysql/lib/* /usr/lib/
sudo ldconfig
(6)编辑MySQL配置文件
echo '
[mysqld]
port=3306
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/mysql-err.log
user=mysql
default_authentication_plugin=mysql_native_password
socket=/usr/local/mysql/data/mysql.sock

[client]
socket=/usr/local/mysql/data/mysql.sock

[mysql]
socket=/usr/local/mysql/data/mysql.sock
' > /etc/my.cnf
(7)初始化数据库,不安全的初始化,可以不用生成初始化密码
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
(8)将MySQL数据库初始化库目录软连接至系统库默认目录
ln -s /usr/local/mysql/data  /var/lib/mysql
(7)修改环境变量
echo '
export PATH=/usr/local/mysql/bin:$PATH
' > /etc/profile

source /etc/profile
(8)创建启动文件
echo '
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
' > /usr/lib/systemd/system/mysqld.service
(9)启动服务并加入开机自启动
systemctl daemon-reload
systemctl start mysqld
systemctl enable mysqld
(10)创建zabbix库
# MySQL8.0后版本,创建用户并授权命令和MySQL5.7之前的版本有所不同,需要先创建用户再授权;
create database zabbix character set=utf8;

create user 'zabbix'@'localhost' identified by '123456';

grant all privileges on zabbix.* to 'zabbix'@'localhost' with grant option;

flush privileges;  

2.安装php7.2

(1)安装源
yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
(2)安装php和php依赖库文件
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-opcache php72w-pdo  php72w-xml  php72w-mysqlnd  php72w-pecl-memcached php72w-pecl-mongodb   php72w-pecl-redis     php72w-pecl-zip       php72w-bcmath php72w-ladp php72w-mysqli
(3)修改php配置文件
sed -i '/post_max_size/s/8/16/g' /etc/php.ini
sed -i '/max_execution_time/s/30/300/g' /etc/php.ini
sed -i '/max_input_time/s/60/300/g' /etc/php.ini
sed -i '/date.timezone/a date.timezone=PRC' /etc/php.ini
# 指定MySQL的sock文件,经过测试必须是系统默认库文件目录才可以;所以安装MySQL时做了软连接
sed -i '/mysqli.default_socket/cmysqli.default_socket = /var/lib/mysql/mysql.sock' /etc/php.ini

sed -i '/always_populate_raw_post_data/a always_populate_raw_post_data=-1' /etc/php.ini
(4)启动服务,加入开机自启
systemctl start php-fpm
systemctl enable php-fpm

3.安装Nginx/1.16.1

(1)配置yum源
echo '
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
' > /etc/yum.repos.d/nginx.repo
(2)安装并修改启动用户
yum -y install nginx

# php的默认启动用户apache,经过测试nginx最好也使用apache用户,所以在此处修改
sed -i '/user nginx/cuser apache' /etc/nginx/nginx.conf
(3)创建zabbix虚拟主机配置文件
echo 'server {
        listen 80;
        server_name localhost;
        root /usr/share/nginx/html;
        location / {
             index   index.php setup.php;
        }
        location ~ .php    {
             fastcgi_pass    127.0.0.1:9000;
             fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include         fastcgi_params;
        }
} ' > /etc/nginx/conf.d/zabbix.conf
(4)启动nginx并加入开机自启
systemctl start nginx
systemctl enable nginx

4.源码安装zabbix4.4.4服务端

(1)安装依赖
yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI libven-devel
(2)下载源码
cd /root
wget -c https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.4/zabbix-4.4.4.tar.gz
(3)解压并预编译安装
tar -xzvf zabbix-4.4.4.tar.gz
cd zabbix-4.4.4
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config  --with-net-snmp --with-libcurl
make && make install
(4)软连接zabbix启动文件至系统默认启动文件目录
ln -s /usr/local/zabbix/sbin/* /usr/sbin/
(5)拷贝zabbix服务端环境文件至系统默认目录
cp /root/zabbix-4.4.4/misc/init.d/gentoo/zabbix-server /etc/sysconfig/
(6)拷贝zabbix的前端源码至nginx站点目录,并授权
cp -r /root/zabbix-4.4.4/frontends/php/* /usr/share/nginx/html/
chown apache.apache /usr/share/nginx/html -R
(7)将zabbix数据库文件导入数据库
mysql -uzabbix -p123456 zabbix < /root/zabbix-4.4.4/database/mysql/schema.sql 
mysql -uzabbix -p123456 zabbix < /root/zabbix-4.4.4/database/mysql/images.sql 
mysql -uzabbix -p123456 zabbix < /root/zabbix-4.4.4/database/mysql/data.sql 
(8)配置zabbix服务端配置文件
echo '
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
' > /usr/local/zabbix/etc/zabbix_server.conf
(9)创建zabbix服务端启动文件
echo '
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/zabbix.service
(10)创建启动用户,启动服务并加入开机自启动
useradd -M -s /sbin/nologin zabbix
systemctl daemon-reload
systemctl start zabbix.service
systemctl enable zabbix.service

5.源码安装zabbix4.4.4客户端

(1)安装依赖
yum -y install epel-release pcre-devel
(2)下载源码包
cd /root
wget -c https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.4/zabbix-4.4.4.tar.gz
(3)解压编译并安装
tar -xzvf zabbix-4.4.4.tar.gz
cd zabbix-4.4.4
./configure  --prefix=/usr/local/zabbix  --enable-agent
make
make install
(4)软连接zabbix客户端启动文件至系统默认启动目录
ln  -s  /usr/local/zabbix/sbin/zabbix_*  /usr/sbin/
(5)拷贝zabbix客户端环境文件至系统默认目录
cp /root/zabbix-4.4.4/misc/init.d/debian/zabbix-agent /etc/sysconfig/
(6)编辑zabbix客户端配置文件
echo '
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
LogFileSize=0
Server=172.16.1.71
ServerActive=172.16.1.71
Hostname=Zabbix server
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
' >  /usr/local/zabbix/etc/zabbix_agentd.conf
(7)创建zabbix客户端启动文件
echo '
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/zabbix_agnet.service
(8)创建启动用户,启动服务并加入开机自启动
useradd -M -s /sbin/nologin zabbix
systemctl daemon-reload
systemctl start zabbix_agent.service
systemctl enable zabbix_agent.service

以上是关于zabbix4.4.4源码编译安装的主要内容,如果未能解决你的问题,请参考以下文章

源码编译安装

源码编译安装

源码包编译

linux下如何编译源码包或者说是安装

httpd源码编译安装

18Linux源码包安装详解