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.6

見我之前文檔:
centos7源碼安裝配置Mariadb10.4.6
https://blog.csdn.net/oToyix/article/details/106507614

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
[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/

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章