centos7源码安装、部署Zabbix4监控平台

1.安装Nginx

1.1卸载自带openssl并源码手动编译安装openssl

关闭selinux
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可

永久关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

#1.安装依赖包
yum remove -y openssl openssl-devel 
yum -y install zlib pcre pcre-devel gcc
#2.下载源码包
wget -c https://www.openssl.org/source/openssl-1.0.2n.tar.gz
#3.解压并安装
tar zxvf openssl-1.0.2n.tar.gz
cd openssl-1.0.2n
./config -fPIC --prefix=/app/openssl-1.0.2n/ enable-shared && make && make install
#4.写入环境变量
echo "export PATH=\$PATH:/app/openssl-1.0.2n/bin"  >>/etc/profile
source /etc/profile
echo "include /app/openssl-1.0.2n/lib" >> /etc/ld.so.conf
ldconfig
#5.查看路径和版本
which openssl;openssl version -a

1.2源码手动编译安装nginx

#1.新增用户
useradd -s /sbin/nologin www
#2.源码手动编译安装nginx
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar zxvf nginx-1.14.1.tar.gz
cd nginx-1.14.1

./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--with-openssl=/app/openssl-1.0.2n \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre
make && make install

#3.如果在linux环境下nignx安装出现 make[1]: *** [/usr/local/wotrus_ssl/.openssl/include/openssl/ssl.h] Error 127错误,则需要进入 nginx-1.18.0/auto/lib/openssl 目录下
编辑 conf 文件需修改如下内容:
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
修改为:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
保存文件后,需先执行 make clean 清除编译配置
再重新进入 nginx-1.18.0 文件夹执行编译和make命令

1.3MySQL的安装

mysql安装-参考链接

systemctl start mysqld
grep "password" /var/log/mysqld.log
mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=6;
set password=password('123456');

1.4 源码手动编译安装php7

#1.安装依赖包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel  openldap openldap-devel
#2.下载源码包
wget http://cn2.php.net/distributions/php-7.2.3.tar.gz
#3.解压并安装
tar zxvf php-7.2.3.tar.gz
cd php-7.2.3
cp -frp /usr/lib64/libldap* /usr/lib/
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd  --disable-fileinfo
make && make install
cp php.ini-production /usr/local/php/lib/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

#4.在编译PHP的时候,可能会出现如下错误:/usr/bin/ld:ext/ldap/.libs/ldap.o:undefined reference to symbol'ber_scanf'
执行./configure后,编辑MakeFile文件,找到以'EXTRA_LIBS'开头的这一行,然后在此行结尾加上'-llber',最后再执行make&&make install即可

#5.PHP配置优化
vi /usr/local/php/lib/php.ini
post_max_size = 16M
max_execution_time = 300
memory_limit = 128M
max_input_time = 300
date.timezone = Asia/Shanghai
mysqli.default_socket = /var/lib/mysql/mysql.sock

#6.配置nginx环境
vi nginx.conf
location ~ \.php${
	root	html;
	fastcgi_pass	127.0.0.1:9000;
	fastcgi_index	index.php;
	fastcgi_param	SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
	include			fastcgi_params;
}
#7.PHP-FPM配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#8.启动php及nginx服务
systemctl start php-fpm
/usr/local/nginx/sbin/nginx

1.5 源码编译安装Zabbix server

#1.安装依赖包
yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libevent libevent-devel mysql-devel
#2.新建用户
groupadd zabbix
useradd -g zabbix zabbix
#3.源码手动编译安装zabbix
rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.7-1.el7.x86_64.rpm
tar zxvf zabbix-4.2.7.tar.gz
cd zabbix-4.2.7
./configure --prefix=/usr/local/zabbix \
--with-mysql --with-net-snmp \
--with-libcurl --enable-server \
--enable-agent --enable-proxy \
--with-libxml2  
make && make install
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/sbin/* /usr/local/bin/
#4.创建数据库和初始化表
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
cd zabbix-4.2.7/database/mysql/
use zabbix;
source schema.sql
source images.sql
source data.sql
5.配置Zabbix server端
vi /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=0.0.0.0
StartPollers=5
StartTrappers=10
StartDiscoverers=10
AlertScriptsPath=/usr/local/zabbix/alertscripts

cp /root/zabbix-4.2.7/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
cp /root/zabbix-4.2.7/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
vi /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix/
/etc/init.d/zabbix_server start
#Zabbix server可能会启动失败,抛出如下错误
vi /etc/ld.so.conf 
/usr/local/mysql/lib
#执行如下操作,即可正常启动Zabbix server:
ldconfig
/etc/init.d/zabbix_server start

1.6 安装Zabbix GUI

#Zabbix Web的代码在Zabbix源码包中的frontends/php目录下将这个PHP目录复制到/usr/loca/nginx/html目录下并改名为Zabbix即可完成Zabbix Web端的安装。然后做个简单授权,将Zabbix的Web目录授权给系统的www用户
/root/zabbix-4.2.7
cp -r frontends/php /usr/local/nginx/html
cd  /usr/local/nginx/html
mv php/ zabbix/
chown -R www:www /usr/local/nginx/html/zabbix
在浏览器输入http://ip/zabbix/zabbix.php
cd /usr/local/nginx/html/zabbix/conf
cp zabbix.conf.php.example zabbix.conf.php
默认的Zabbix平台登录用户名为Admin,密码为zabbix
#然后按照提示一步步操作 数据库选择刚刚创建的

最终截图如下
在这里插入图片描述

1.7 源码编译安装Zabbix agent

#1.源码下载并解压安装
wget http://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.7-1.el7.x86_64.rpm
rpm -ivh zabbix-agent-4.2.7-1.el7.x86_64.rpm
vi /etc/zabbix/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
#2.指定Zabbix server端的IP地址
Server=192.0.1.3
StartAgents=3
ServerActive=192.0.1.3
#3.需要监控服务器的主机名或者IP地址。此选择的设置一定要和Zabbix Web端主机配置中对应的主机名一致
Hostname=192.0.1.2
Include=/etc/zabbix/zabbix_agentd.d
UnsafeUserParameters=1
#4.启动
systemctl start   zabbix-agent
测试Zabbix server监控
/usr/local/zabbix/bin/zabbix_get -s 192.0.1.3 -p 10050 -k 

1.8 日志文件查看

zabbix_agentd.log 客户端日志
zabbix_server.log 服务端日志

Guess you like

Origin blog.csdn.net/chushudu/article/details/112814392