Centos7源码安装zabbix4.4.6(单台)

一、源码安装LNMP

环境:
Nginx:1.18.0
Mariadb:10.4.6
Php-7.4.6
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
1、源码安装nginx

执行以下脚本

#!/bin/bash
#Centos7源码安装nginx-1.18.0
#2020年5月28日 20:04:24
#author Toyix
############################
repobase="/etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo"
repoepel="/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo"
soft1="vim wget lrzsz"
soft2="pcre-devel pcre gcc gcc-c++ openssl openssl-devel zlib-devel"
nginxversion="nginx-1.18.0"
nginxsoft="http://nginx.org/download/${nginxversion}.tar.gz"
nginxdir="/usr/local/nginx"
configuremoudule="--user=nginx \
--group=nginx \
--prefix=${nginxdir} \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_realip_module \
--with-pcre \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-stream"
netstat_nginx="netstat -tnlp |grep nginx"
selinuxconfigfile="/etc/selinux/config"
selinux_enforcing="SELINUX=enforcing"
selinux_disabled="SELINUX=disabled"
firewalld_open80="--zone=public --add-port=80/tcp --permanent"
firewalld_ports="--zone=public --list-ports"
yum install $soft1 -y
echo "安装国内base及epel源"
seleep 5
curl -o $repobase
wget -O $repoepel
yum clean all
yum makecache
echo "创建nginx用户nginx"
useradd -s /sbin/nologin -r nginx
echo "安装环境支持"
yum install $soft2 -y
echo "下载nginx"
cd /usr/src/
wget $nginxsoft
tar -xf ${nginxversion}.tar.gz
cd ${nginxversion}
echo "预编译"
./configure ${configuremoudule} 
echo "编译"
make
echo "安装"
make install
${nginxdir}/sbin/nginx
sed -i "s/${selinux_enforcing}/${selinux_disabled}/g" ${selinuxconfigfile}
setenforce 0
firewall-cmd ${firewalld_open80}
firewall-cmd --reload
firewall-cmd $firewalld_ports
echo "------------------end"

2、源码安装mariadb10.4.17

见我之前文档:
执行其中脚本即可
https://blog.csdn.net/oToyix/article/details/107082195

3、源码安装配置php

见我之前文档
https://blog.csdn.net/oToyix/article/details/106591673 第3章节

二、源码安装配置zabbix

1、下载zabbix源码包
[root@localhost src]# wget -c https://astuteinternet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.6/zabbix-4.4.6.tar.gz
[root@localhost src]# tar xf zabbix-4.4.6.tar.gz
[root@localhost src]# cd zabbix-4.4.6
[root@localhost zabbix-4.4.6]#

2、安装zabbix数据库及配置权限
[root@localhost ~]# echo "export PATH=/usr/local/mariadb/bin/:$PATH" >/etc/profile.d/mysql.sh 
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]#mysql
MariaDB [(none)]> create database zabbix charset utf8;
Query OK, 1 row affected (0.003 sec)
MariaDB [(none)]> grant all on zabbix.* to "zabbix"@"%" identified by "123456"; 
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.003 sec)

3、导入数据库
[root@localhost mysql]# pwd
/usr/src/zabbix-4.4.6/database/mysql
[root@localhost mysql]# mysql -uroot -p123456 zabbix <schema.sql 
[root@localhost mysql]# mysql -uroot -p123456 zabbix <images.sql 
[root@localhost mysql]# mysql -uroot -p123456 zabbix <data.sql
4、编译安装zabbix

安装依赖包

[root@localhost ~]# yum -y install gcc mysql-community-devel libxml2-devel unixODBC-devel net-snmp-devel libcurl-devel libssh2-devel OpenIPMI-devel openssl-devel openldap-devel libevent libevent-devel

预编译、编译、安装

[root@localhost zabbix-4.4.6]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --prefix=/usr/local/zabbix
[root@localhost zabbix-4.4.6]# make
[root@localhost zabbix-4.4.6]# make install
[root@localhost zabbix-4.4.6]# ls /usr/local/zabbix/
bin  etc  lib  sbin  share

5、配置nginx代码目录及配置文件
[root@localhost ~]# mkdir -p /usr/local/nginx/conf/vhost
[root@localhost ~]# vim /usr/local/nginx/conf/vhost/zabbix.yjy.com.conf
   server {
        listen 80;
        server_name zabbix.yjy.com;
        location / {
                root         /usr/local/nginx/html/zabbix;
                index   index.php;
        }
        location ~ \.php$ {
               root           /usr/local/nginx/html/zabbix;
               fastcgi_pass   127.0.0.1:9000;
               fastcgi_index  index.php;
               fastcgi_buffer_size 4k;
               fastcgi_buffers 32 4k;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include        fastcgi_params;
        }
}

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

21     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 22                       '$status $body_bytes_sent "$http_referer" '
 23                       '"$http_user_agent" "$http_x_forwarded_for"';
 24 
 25     access_log  logs/access.log  main;
 26 
 27     include     /usr/local/nginx/conf/vhost/*.conf;
 28     sendfile        on;
[root@localhost ~]# alias nginx="/usr/local/nginx/sbin/nginx"
[root@localhost ~]# nginx –t
[root@localhost php]# mkdir -p /usr/local/nginx/html/zabbix
[root@localhost php]# pwd
/usr/src/zabbix-4.4.6/frontends/php
[root@localhost php]# cp -a . /usr/local/nginx/html/zabbix/
[root@localhost php]# chown -R  nginx:nginx /usr/local/nginx/html/zabbix/
6、配置zabbix_server.conf文件
[root@localhost ~]# grep "^[a-Z ]" /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
LogFileSize=0
PidFile=/tmp/zabbix_server.pid
SocketDir=/tmp
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
Timeout=4
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
LogSlowQueries=3000
TmpDir=/tmp
SSLCertLocation=/usr/local/zabbix/share/zabbix/ssl/certs
SSLKeyLocation=/usr/local/zabbix/share/zabbix/ssl/keys
StatsAllowedIP=127.0.0.1

7、配置启动脚本
root@localhost core]# pwd
/usr/src/zabbix-4.4.6/misc/init.d/fedora/core
[root@localhost core]# cp zabbix_server /etc/init.d/zabbix_server
[root@localhost core]# cp zabbix_agentd /etc/init.d/zabbix_agentd
[root@localhost core]# vim /etc/init.d/zabbix_server
        BASEDIR=/usr/local/zabbix
[root@localhost core]# vim /etc/init.d/zabbix_agentd
        BASEDIR=/usr/local/zabbix
[root@localhost ~]# chkconfig --add /etc/init.d/zabbix_server
[root@localhost ~]# chkconfig --add /etc/init.d/zabbix_agentd 
[root@localhost ~]#  chkconfig zabbix_server on
[root@localhost ~]# chkconfig zabbix_agentd on

8、安装zabbix

在这里插入图片描述
在这里插入图片描述
上面报错了,配置PHP

[root@localhost zabbix]# vim /usr/local/php7/etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanhai
[root@localhost zabbix]# php-fpm restart 重启php
添加ldap模块
[root@localhost ldap]# pwd
/usr/src/php-7.4.6/ext/ldap
[root@localhost ldap]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
[root@localhost ldap]# ./configure  --with-php-config=/usr/local/php7/bin/php-config  --with-ldap
报错:
configure: error: Cannot find ldap libraries in /usr/lib.
添加lib库文件至/usr/lib/
[root@localhost ldap]# cp -a /usr/lib64/libldap* /usr/lib/
再次编译
[root@localhost ldap]# ./configure  --with-php-config=/usr/local/php7/bin/php-config  --with-ldap
[root@localhost ldap]# make
[root@localhost ldap]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/debug-non-zts-20190902/
[root@localhost ldap]# vim /usr/local/php7/etc/php.ini
extension=ldap.so
[root@localhost ~]# /usr/local/php7/bin/php -m|grep  ldap
ldap
[root@localhost ~]# /usr/local/php7/sbin/php-fpm -m|grep  ldap
ldap

在这里插入图片描述
在这里插入图片描述

删除数据库改符集新建
MariaDB [(none)]> drop database zabbix;
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all on zabbix.* to "zabbix"@"%" identified by "123456";
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.002 sec)
重新导库
[root@localhost mysql]# pwd
/usr/src/zabbix-4.4.6/database/mysql
[root@localhost mysql]# mysql -uroot -p123456 zabbix <schema.sql 
[root@localhost mysql]# mysql -uroot -p123456 zabbix <images.sql 
[root@localhost mysql]# mysql -uroot -p123456 zabbix <data.sql

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#vim /usr/local/php7/etc/php-fpm.d/default.conf
php_value[date.timezone] = UTC
[root@localhost mysql]# php-fpm restart

在这里插入图片描述
改中文
在这里插入图片描述
在这里插入图片描述
启动zabbix_server,报错了

[root@localhost ~]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl):                    [  OK  ]
[root@localhost ~]# ps -ef|grep zabbix
root      2125  2011  0 09:51 pts/0    00:00:00 grep --color=auto zabbix
报错了
[root@localhost ~]# /etc/init.d/zabbix_server status                              
● zabbix_server.service - SYSV: Starts and stops Zabbix Server using chkconfig
   Loaded: loaded (/etc/rc.d/init.d/zabbix_server; bad; vendor preset: disabled)
   Active: active (exited) since Fri 2020-06-19 09:03:59 CST; 44min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1988 ExecStart=/etc/rc.d/init.d/zabbix_server start (code=exited, status=0/SUCCESS)

Jun 19 09:03:59 localhost.localdomain systemd[1]: Starting SYSV: Starts and stops Zabbix Server using chkconfig...
Jun 19 09:03:59 localhost.localdomain zabbix_server[1988]: Starting zabbix_server:  /etc/init.d/functions: line 611: /usr/local/sbin/zabbix_server: No such ...irectory
Jun 19 09:03:59 localhost.localdomain zabbix_server[1988]: [FAILED]
Jun 19 09:03:59 localhost.localdomain systemd[1]: Started SYSV: Starts and stops Zabbix Server using chkconfig.
Hint: Some lines were ellipsized, use -l to show in full.

添加软链接

[root@localhost ~]# ln -s /usr/local/zabbix/sbin/zabbix_server /usr/local/sbin/zabbix_server
[root@localhost ~]#ln -s  /usr/local/mariadb/lib/libmariadb.so.3 /lib64/
[root@localhost ~]#ln -s  /usr/local/mariadb/lib/libmariadb.so.3 /lib/

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
注:
1、如果zabbix时钟时间与服务器系统时间不一致,改
[root@zabbix sh]# vim /usr/local/php7/etc/php-fpm.d/default.conf

php_value[date.timezone] = Asia/Shanghai

2、别忘记了创建zabbix用户
useradd zabbix
3、以下报错解决方法:
zabbix_server: /usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmariadb.so.3… directory

echo "/usr/local/mariadb/lib" >>/etc/ld.so.conf
ldconfig 

也可以使用下面编译项目(忽略)

yum install mysql-community-devel  mysql-devel openssl*  libpng libpng12 jpegsrc freetype libwebp libjpeg openjpeg openjpeg2 jpeg openlda openldap-devel mailx sendmail openssl-devel bzip2-devel expat-devel gdbm-devel readline- devel sqlite-devel gcc gcc-c++ openssl-devel libffi-devel python-devel mariadb-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel fping

./configure  --prefix=/usr/local/php7zabbix   --enable-fpm  --with-fpm-user=www-data  --with-fpm-group=www-data  --enable-debug  --with-gd  --enable-ldap  --with-jpeg-dir=/usr/lib64  --with-pgsql  --enable-inline-optimization  --with-bz2  --with-zlib-dir  --with-freetype-dir=/usr/include/freetype2/freetype  --enable-mbstring  --enable-soap  --with-openssl  --enable-calendar  --with-curl  --enable-ftp  --with-gettext  --with-xmlrpc  --with-xsl  --enable-opcache  --with-iconv  --with-pdo-mysql=mysqlnd  --with-mysqli=mysqlnd  --with-kerberos  --with-pdo-sqlite  --with-pear  --enable-shmop  --enable-xml  --with-zlib  --enable-sockets  --enable-sysvsem  --enable-pcntl  --enable-mbregex  --enable-exif  --enable-bcmath  --with-mhash  --with-zlib-dir  --with-pcre-jit  --with-config-file-path=/usr/local/php7zabbix/etc

----------------------end

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值