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

zabbix4.0搭建(基于CentOS6.8)

程序员文章站 2023-11-11 18:37:10
环境 服务端:188.188.3.241,系统:centos6.8,mysql:5.7.3,php:5.4.9,nginx:1.12.0 分割线 一、nginx编译安装 NGINX_VERSION=1.12.0 yum -y install pcre-devel openssl-devel cd / ......
环境
服务端:188.188.3.241,系统:centos6.8,mysql:5.7.3,php:5.4.9,nginx:1.12.0
=================================================分割线==============================================
一、nginx编译安装
nginx_version=1.12.0
yum -y install pcre-devel openssl-devel
cd /usr/src
tar -zxf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
useradd -m -s /sbin/nologin nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-pcre
make && make install
===============================================分割线==================================================
二、mysql编译安装
#mysql5.7.13下载地址
wget http://dev.mysql.com/get/downloads/mysql-5.7/mysql-5.7.13.tar.gz
#安装mysql之前必须安装boost库,mysql5.7.13要求的boost版本是boost1.59.0或以上版本。
#下载地址
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -xzvf boost_1_59_0.tar.gz 
cd boost_1_59_0 
./bootstrap.sh --with-libraries=system,filesystem,log,thread --with-toolset=gcc 
./b2 toolset=gcc
./b2 install --prefix=/usr/local/boost
mysql_version=5.7.13
yum -y install cmake ncurses-devel readline-devel bison libaio-devel openssl-devel gcc-c++
cd /usr/src
useradd -m -s /sbin/nologin mysql
tar -zxf mysql-${mysql_version}.tar.gz
cd mysql-${mysql_version}
#注意,6.8版本cmake不成功的话把lamp(yum)里面的东西除了开头两个都卸载试试
cmake \
-dcmake_install_prefix=/usr/local/mysql \
-dsysconfdir=/etc \
-dmysql_datadir=/usr/local/mysql/data \
-dmysql_tcp_port=3306 \
-dmysql_unix_addr=/usr/local/mysql/tmp/mysql.sock \
-dmysql_user=mysql \
-dextra_charsets=all \
-dwith_readline=1 \
-dwith_ssl=system \
-dwith_embedded_server=1 \
-denabled_local_infile=1 \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_memory_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_partition_storage_engine=1 \
-ddefault_charset=utf8 \
-ddownload_boost=1 \
-ddefault_collation=utf8_general_ci \
-dwith_boost=/usr/local/boost
make && make install
make clean
rm cmakecache.txt
chown -r mysql:mysql /usr/local/mysql
cd /usr/local/mysql/bin
#数据库初始化
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 
#这条命令执行后会产生一个初始密码
#a temporary password is generated for root@localhost: su,g6rppfghv (要记下来)
mv /etc/my.cnf /etc/my.cnf.old
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
echo '/usr/local/mysql/lib/' >> /etc/ld.so.conf  #指定mysql库文件位置
ldconfig
echo 'export path=$path:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
#修改root密码
mysql -uroot -p
#密码为之前随机生成的初始密码,使用alter语句修改默认密码
mysql>alter user 'root'@'localhost' identified by 'root';
=================================================分割线================================================
三、php编译安装
cd /usr/src
tar -zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
cd /usr/src
tar -zxf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure
make && make install
cd /usr/src
tar -zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
ldconfig -v
cd libltdl/
./configure --with-gmetad --enable-gexec --enable-ltdl-install
make && make install
ln -sv /usr/local/lib/libmcrypt* /usr/lib
ln -sv /usr/local/lib/libmhash* /usr/lib
ln -sv /usr/local/lib/libiconv* /usr/lib
ldconfig -v
=================================================分割线================================================
php_version=5.4.9
yum -y install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel openldap-devel
cp -frp /usr/lib64/libldap* /usr/lib/
cd /usr/src
tar -zxf php-${php_version}.tar.gz
cd php-${php_version}
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-iconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr/local \
--enable-xml \
--enable-dom \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-gettext \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap
make zend_extra_libs='-liconv' && make install
cp php.ini-production /usr/local/php/etc/php.ini
echo 'export path=$path:/usr/local/php/bin' >> /etc/profile
source /etc/profile
==================================================分割线===============================================
四、zabbix编译安装
groupadd zabbix
useradd -g zabbix -m -s /sbin/nologin zabbix
cd /usr/src
tar -zxf zabbix-4.0.0.tar.gz
cd zabbix-4.0.0
./configure --prefix=/usr/local/zabbix \
--sysconfdir=/etc/zabbix/ \
--enable-server \
--enable-agent \
--with-net-snmp \
--with-libcurl \
--with-mysql=/usr/local/mysql/bin/mysql_config \
--with-libxml2 \
 --enable-bcmath --with-gd
make && make install
#导入zabbix数据库
cd  /usr/src/zabbix-4.0.0/database/mysql
mysql -uzabbix -pzabbix zabbix < schema.sql
mysql -uzabbix -pzabbix zabbix < images.sql
mysql -uzabbix -pzabbix zabbix < data.sql
#配置zabbix_server
#vim /etc/zabbix/zabbix_server.conf
dbhost=188.188.3.241
dbname=zabbix
dbuser=zabbix
dbpassword=zabbix
listenip=188.188.3.241
startipmipollers=10
startpollersunreachable=10
starttrappers=10
startpingers=10
startdiscoverers=10
cachesize=256m
startdbsyncers=40
historycachesize=128m
trendcachesize=128m
valuecachesize=128m
timeout=30
alertscriptspath=/etc/zabbix/alertscripts      
externalscripts=/etc/zabbix/externalscripts    
logslowqueries=10000
startproxypollers=50
logfile=/tmp/zabbix_server.log
#创建zabbix所需要的脚本目录
mkdir /etc/zabbix/alertscripts 
mkdir /etc/zabbix/externalscripts
ln -s /usr/local/zabbix/sbin/*    /usr/sbin/
cp /usr/src/zabbix-4.0.0/misc/init.d/fedora/core/zabbix_*    /etc/init.d/   #复制服务启动脚本
chmod +x /etc/init.d/zabbix_*
sed -i "s@basedir=/usr/local@basedir=/usr/local/zabbix@g" /etc/init.d/zabbix_server
#配置web
#cd /usr/local/nginx/conf/vhost
#vim zabbix.conf
server {
        listen       80;
        server_name zabbix.com;
        access_log  /data/logs/nginx/zabbix/access.log  main;
 error_log  /data/logs/nginx/zabbix/error.log;
        index index.html index.php index.html;
        root /data/web/zabbix;
 
        location /
        {
                try_files $uri $uri/ /index.php?$args;
        }
 
        location ~ ^(.+.php)(.*)$ {
                fastcgi_split_path_info ^(.+.php)(.*)$;
                include fastcgi.conf;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param  path_info  $fastcgi_path_info;
        }
}
#mkdir -p /data/web/zabbix
cp -r /usr/src/zabbix-4.0.0/frontends/php/* /data/web/zabbix/
#chown -r nginx:nginx /data/web/zabbix/
启动zabbix_server 、nginx服务
#service nginx start
#server  zabbix_server  start
#浏览器访问
http://188.188.3.241/zabbix/setup.php
默认用户名 admin 密码 zabbix
================================================分割线=====================================================
五、zabbix客户端
1 下载安装客户端
所有版本下载地址:http://www.zabbix.com/download.php,可以直接下载已经编译好的二进制文件,或者也可以源码安装。
# cd /usr/local/src
# wget "http://downloads.sourceforge.net/project/zabbix/zabbix%20latest%20stable/4.0.0/zabbix-4.0.0.tar.gz?r=http%3a%2f%2fwww.zabbix.com%2fdownload.php&ts=1395066528&use_mirror=jaist"
# tar -xzvf zabbix-4.0.0.tar.gz
# cd zabbix-4.0.0
# ./configure --prefix=/usr/local/zabbix/ --enable-agent
# make
# make install
3.2 zabbix客户端配置
配置zabbix_server配置文件,zabbix源码目录下
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
server=127.0.0.1
serveractive=127.0.0.1
hostname=zabbix server
其中server和serveractive都指定zabbixserver的ip地址,不同的是,前者是被动后者是主动。也就是说server这个配置是用来允许127.0.0.1这个ip来我这取数据。而serveractive的127.0.0.1的意思是,客户端主动提交数据给他。明白了吗?为什么要分主动和被动?后续再来讨论这个问题!
其他主机安装客户端记得添加zabbix用户。
3.3 zabbix客户端启动
# /usr/local/zabbix-4.0.0/sbin/zabbix_agentd