欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Centos7编译安装zabbix-4.0.1

程序员文章站 2023-01-29 17:15:15
架构组合:nginx1.9.10+php7.0.32+mysql5.7.22+zabbix4.0.1 nginx1.9.10 先装依赖 openssl-1.1.0f pcre-8.40 zlib-1.2.11 nginx-1.9.10 编译 安装 php7.0.32 php使用yum方式安装 更新y ......

架构组合:nginx1.9.10+php7.0.32+mysql5.7.22+zabbix4.0.1

Centos7编译安装zabbix-4.0.1

nginx1.9.10

 先装依赖

openssl-1.1.0f

tar zxvf openssl-1.1.0f.tar.gz
cd openssl-1.1.0f
./config --prefix=/usr/local/lib/openssl-1.1.0f
make && make install

pcre-8.40

tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure --prefix=/usr/local/lib/pcre-8.40
make && make install

zlib-1.2.11

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/lib/zlib-1.2.11
make && make install

nginx-1.9.10

tar -zxvf nginx-1.9.10.tar.gz
cd nginx-1.9.10

编译

./configure --prefix=/usr/local/nginx-1.9.10/ --with-pcre=/usr/local/lib/pcre-8.40/ --with-openssl=/usr/local/lib/openssl-1.1.0f/ --with-zlib=/usr/local/lib/zlib-1.2.11/

安装

make && make install

Centos7编译安装zabbix-4.0.1

php7.0.32

php使用yum方式安装

更新yum源

centos/rhel 7:

rpm -uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
url:https://centos.pkgs.org/7/webtatic-x86_64/webtatic-release-7-3.noarch.rpm.html

yum

yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel php70w-xml -y

验证

php -v

Centos7编译安装zabbix-4.0.1

查看所有已安装的模块

php -m 

配置文件详解

php.ini
php-fpm.conf

测试

mkdir -p /usr/local/zabbix-4.0.1/php
vim index.php

index.php

<?php
phpinfo();
?> 

Centos7编译安装zabbix-4.0.1

nginx+php配置

cd /usr/local/nginx-1.9.10/conf
vim zabbix.conf

zabbix.conf

server{
	listen 9088;
	server_name localhost;
	access_log logs/zabbix.log;
	error_log  logs/error.log;
	location / {
		proxy_http_version 1.1;
		root /usr/local/zabbix-4.0.1/php;
		index index.html index.htm index.php;
	}
	location ~* \.php$ {
		root /usr/local/zabbix-4.0.1/php;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param script_filename /usr/local/zabbix-4.0.1/php$fastcgi_script_name;
		include fastcgi_params;
	}
}

在nginx.conf htpp选项中加入zabbix.conf

include	  zabbix.conf;

浏览器访问:ip+9088

mysql5.7.22

解压

tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

新建data,logs目录用来存放数据和日志

cd /opt/mysql
mkdir data logs

my.cnf

[mysqld]
federated
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# settings user and group are ignored when systemd is used.
# if you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/systemd
skip-grant-tables
server-id=148
log-bin=mysql-bin
lower_case_table_names=1
sql_mode = 'strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution'
[mysqld_safe]
log-error=/opt/mysql/logs/error.log
pid-file=/opt/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

初始化

/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --initialize

启动命令

/opt/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

登陆后重新设置root密码

修改授权远程zabbix密码
alter user 'zabbix'@'%' identified by 'zabbix';

创建zabbix远程%用户
create user 'zabbix'@'%' identified with mysql_native_password by 'zabbix';

授权
grant all privileges on *.* to 'zabbix'@'%';

刷新
flush privileges;

Centos7编译安装zabbix-4.0.1

zabbix4.0.1

https://nchc.dl.sourceforge.net/project/zabbix/zabbix%20latest%20stable/4.0.1/zabbix-4.0.1.tar.gz

依赖

yum install libevent libevent-devel libaio gcc libxml* unixodbc-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel pcre* -y

ld.so.conf

vim /etc/ld.so.conf

include ld.so.conf.d/*.conf
/opt/mysql/lib

编译

./configure --prefix=/usr/local/zabbix-4.0.1/ --enable-server --enable-agent --with-mysql=/opt/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2l

目录展示

[root@localhost etc]# cd /usr/local/zabbix-4.0.1/
[root@localhost zabbix-4.0.1]# cd sbin/
[root@localhost sbin]# ls
zabbix_agentd  zabbix_server
[root@localhost sbin]# cd ../etc/
[root@localhost etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@localhost etc]#

php站点转移

cd /usr/local/zabbix/zabbix-4.0.1/frontends
cp -r php /usr/local/zabbix-4.0.1

zabbix_agentd.conf

zabbix_server.conf

重启nginx!

浏览器访问:ip+9088

前面还有配置图, 我当时没有截图,页面配置好进入登录界面,默认账号密码是admin/zabbix

Centos7编译安装zabbix-4.0.1

Centos7编译安装zabbix-4.0.1

下面就是配置添加主机分配监控之类的事了。

自家脚本一键操作

客户端启动

zagentstartall.sh

#/bin/bash
/usr/local/nginx-1.9.10/sbin/nginx
/usr/local/php/bin/php-fpm
/opt/mysql/start.sh
/usr/local/zabbix-4.0.1/sbin/zabbix_agentd

 

服务器启动

zserverstartall.sh

#/bin/bash
sudo -u chenglee /usr/local/nginx-1.9.10/sbin/nginx
/usr/local/php/bin/php-fpm
/opt/mysql/start.sh
/usr/local/zabbix-4.0.1/sbin/zabbix_serverl

效果

Centos7编译安装zabbix-4.0.1

查看状态

status.sh

#/bin/bash
echo "***************************************"
echo "nginx status ..."
ps aux | grep nginx
echo "php status ..."
ps aux | grep php
echo "mysql status ..."
ps aux | grep mysql
echo "zabbix status ..."
ps aux | grep zabbix
echo "***************************************"l

效果

Centos7编译安装zabbix-4.0.1

一键kill

stopall.sh

#/bin/bash
chengkill nginx
chengkill php
chengkill mysql
chengkill zabbix

效果

Centos7编译安装zabbix-4.0.1

chengkill

#!/bin/sh
#pid kill thread for chenglee
#if fileformat=dos, update fileformat=unix
#code:set fileformat=unix
#check:set ff ?
if [ $# -lt 1 ]
then
  echo "not procedure_name"
  exit 1
fi

process=`ps -ef|grep $1|grep -v grep|grep -v ppid|awk '{ print $2}'`
for i in $process
do
  echo "kill the $1 process [ $i ]"
  kill -9 $i
done

把chengkill扔进/usr/bin

Centos7编译安装zabbix-4.0.1