米鼠商城

多快好省,买软件就上米鼠网

最新项目

人才服务

靠谱的IT人才垂直招聘平台

Linux下从源代码安装zabbix

  • lxd01
  • 7
  • 2019-08-30 20:17
[官方安装链接](https://www.zabbix.com/documentation/4.0/zh/manual/installation/install)
//系统(需要关闭SELinux/iptables打开对应端口或关闭)
CentOS release 6.10 (Final)	2.6.32-754.el6.x86_64
//服务器规划
//zabbix-server		192.168.203.13
//zabbix-agent		192.168.203.17
//zabbix-mysql		192.168.203.15
//client		任意(能够访问zabbix服务器即可,需要有浏览器,图形界面)
//所需包的百度云盘链接
链接:https://pan.baidu.com/s/17ewVp3gz9nTMpb6HCe6Tlw 
提取码:pbs2 
//zabbix-mysql操作(安装MySQL导入zabbix库等)

//查看本机是否已经安装mysql
# rpm -qa|grep -i mysql

//如果已经安装则卸载
# rpm -e --nodeps mysql-devel-5.1.73-8.el6_8.x86_64	//示例

//安装MySQL
# rpm -ivh MySQL-devel-5.5.25a-1.linux2.6.x86_64.rpm
# rpm -ivh MySQL-server-5.5.25a-1.linux2.6.x86_64.rpm
# rpm -ivh MySQL-client-5.5.25a-1.linux2.6.x86_64.rpm

//设置密码
# /usr/bin/mysqladmin -u root password 'tbBilc48vlATyc7G'

//启动MySQL 登录/导入zabbix库等
# /etc/init.d/mysql start
# mysql -uroot -p 'tbBilc48vlATyc7G'
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'tbBilc48vlATyc7G';
mysql> flush privileges;
mysql> use zabbix;
mysql> source ../zabbix/zabbix-4.0.10/database/mysql/schema.sql
mysql> source ../zabbix/zabbix-4.0.10/database/mysql/images.sql
mysql> source ../zabbix/zabbix-4.0.10/database/mysql/data.sql
mysql> exit;
/zabbix-server操作(所有需要的包放在../zabbix/目录下,另使用CentOS release 6.10 (Final) 的yum本地源,便于解决依赖)
# yum -y install libtool* zlib* openssl* wget gcc gcc-c++ cmake pcre* libxml2* curl* libcurl* libjpeg* libpng libpng-devel freetype freetype-devel libxslt* net-snmp-devel libevent-devel openldap openldap-devel mysql-devel

//编译libmcrypt解决依赖
# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz 
# tar zxvf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7
# ./configure && make && make install

//Nginx版本1.11.3 && 编译安装
# wget http://nginx.org/download/nginx-1.11.3.tar.gz
//需要指定Nginx运行用户时创建
# groupadd nginx
# useradd -M -d /home -g nginx nginx -s /sbin/nologin
# tar zxvf nginx-1.11.3.tar.gz && cd nginx-1.11.3
# ./configure --prefix=/usr/local/nginx
# make && make install

# cat /usr/local/nginx/conf/nginx.conf //在最后一行添加以下内容(最后一个 } 之前)
include vhost/*.conf;

# mkdir /usr/local/nginx/conf/vhost && cd /usr/local/nginx/conf/vhost
# cat /usr/local/nginx/conf/vhost/zabbix.conf //创建zabbix.conf文件,内容如下
server {
    listen 80;
    server_name localhost;

    root   html;
    index index.html index.php;

    error_log logs/zabbix_error.log;

    location / {
        #try_files $uri $uri/ /index.php$args;
        location ~ \.php$ {
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass   127.0.0.1:9000;
            include fastcgi.conf;

            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }

    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
        access_log off;                 
        expires 3d;                     
        add_header Cache-Control public;
     }   

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
}

# /usr/local/nginx/sbin/nginx -t		//检查conf语法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx //启动nginx
# ps aux|grep nginx		//检查是否启动成功
root       5148  0.0  0.0  19988   692 ?        Ss   19:41   0:00 nginx: master process /usr/local/nginx/
sbin/nginxnobody     5149  0.0  0.1  20460  1292 ?        S    19:41   0:00 nginx: worker process      
root       5151  0.0  0.0 103336   900 pts/1    S+   19:41   0:00 grep nginx

# /usr/local/nginx/sbin/nginx -s stop   //停止nginx
# /usr/locat/nginx/sbin/nginx -s reload //重新加载配置文件

//编译安装PHP(版本7.1.7)
# wget  http://cn2.php.net/distributions/php-7.1.7.tar.gz
# tar zxvf php-7.1.7.tar.gz -C /usr/local/src/ && cd /usr/local/src/php-7.1.7
# ./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-pdo-mysql=mysqlnd \
--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-xmlrpc \
--with-xsl \
--with-zlib \
--with-zlib-dir \
--with-mhash \
--with-mcrypt \
--with-openssl-dir \
--with-jpeg-dir \
--with-ldap \
--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-xml \
--enable-maintainer-zts \
--enable-zip \
--enable-mysqlnd \
--enable-opcache=no

//如./configure中报错
configure: error: Cannot find ldap libraries in /usr/lib
//解决办法:
# cp -frp /usr/lib64/libldap* /usr/lib/
//如./configure中报错
configure: error: off_t undefined; check your library configuration
//解决办法:
# vim /etc/ld.so.conf 
//添加以下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
//使之生效
# ldconfig -v

//解决问题后重新 configure 继续
# make && make install

//编译PHP中如make后报错
在包含自 /usr/local/src/php-7.1.7/ext/zip/lib/zip_add.c:36 的文件中:
/usr/local/src/php-7.1.7/ext/zip/lib/zipint.h:126:2: 错误:#error unsupported size of off_t
make: *** [ext/zip/lib/zip_add.lo] 错误 1
//解决方法:
# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf && ldconfig -v
# make clean //解决错误后clean,重新执行 configure 后继续 make && make install

//编译完成php后,设置配置文件
# cp php.ini-production /usr/local/php7/etc/php.ini
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# /etc/init.d/php-fpm start
Starting php-fpm  done

//client操作
//测试Nginx与php
# cat /usr/local/nginx/html/phpinfo.php
<?php
phpinfo();
?>
//在浏览器中输入 localhost/phpinfo.php 出现PHP页面即成功

//编译安装zabbix-server 与zabbix-agent
# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.10/zabbix-4.0.10.tar.gz
# tar zxvf zabbix-4.0.10.tar.gz && cd zabbix-4.0.10
# groupadd zabbix
# useradd -M -d /home/user/ -g zabbix zabbix -s /sbin/nologin
# useradd -M -d /home/user/ -g zabbix zabbix-agent -s /sbin/nologin
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-mysql
# make install

//修改zabbix_server配置文件(查找以下项修改)
# vi /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DBHost=192.168.203.15
DBName=zabbix
DBUser=zabbix
DBPassword=tbBilc48vlATyc7G
DBPort=3306
StartPollers=1
StartPreprocessors=1
StartTrappers=1
StartAlerters=1
ListenIP=0.0.0.0
StartDBSyncers=1
Timeout=4
LogSlowQueries=3000
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf		//按照实际路径修改

//修改zabbix_agentd配置文件(查找以下项修改)
# vi  /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.203.13
ListenPort=10050
ServerActive=1192.168.203.13
Hostname=		//根据实际情况修改,填写本机主机名
Include=/usr/local/zabbix/zabbix-agent/etc/zabbix_agentd.conf.d/*.conf	//根据实际路径修改

//若没有启动脚本,可用以下命令启动server和agentd服务
# /usr/local/zabbix/sbin/zabbix_server
# /usr/local/zabbix/sbin/zabbix_agentd
//停止server和agentd服务
# killall -TERM zabbix_server
# killall -TERM zabbix_agentd

//设置启动脚本
# cp ../zabbix/zabbix-4.0.10/misc/init.d/fedora/core5/zabbix_server /etc/rc.d/init.d/
# chmod +x /etc/rc.d/init.d/zabbix_server
# vi /etc/rc.d/init.d/zabbix_server	//修改ZABBIX_BIN中的值为实际安装路径
# /etc/init.d/zabbix_server 
Usage: /etc/init.d/zabbix_server {condrestart|start|stop|restart|reload|status}

# cp ../zabbix/zabbix-4.0.10/misc/init.d/fedora/core5/zabbix_agentd /etc/rc.d/init.d/
# chmod +x /etc/rc.d/init.d/zabbix_agentd
# vi /etc/rc.d/init.d/zabbix_agentd	//修改ZABBIX_BIN中的值为实际安装路径
# /etc/init.d/zabbix_agentd 
Usage: /etc/init.d/zabbix_agentd {condrestart|start|stop|restart|reload|status}

//复制WEB管理页面到nginx
# cp -r ../zabbix/zabbix-4.0.10/frontends/php/ /usr/local/nginx/html/zabbix

//修改php配置文件
# vi /usr/local/php7/etc/php.ini 
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
cgi.fix_pathinfo=1

//重启php
# /etc/init.d/php-fpm 
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status|configtest}

//修改部分目录权限
# chown -R nginx:nginx /var/lib/php/
# chmod 777 /usr/local/nginx/html/zabbix/conf/
# chown -R nginx:nginx /usr/local/nginx/html/zabbix/

//client端操作
//浏览器输入 localhost/zabbix 开始安装zabbix(过程略)

//zabbix-agent操作
//其他节点编译zabbix-agentd
# yum -y install pcre-devel gcc
# tar zxvf zabbix-4.0.10.tar.gz
# groupadd zabbix
# useradd -M -d /home/user/ -g zabbix zabbix -s /sbin/nologin
# ./configure --prefix=/usr/local/zabbix/zabbix-agent --enable-agent
# make install

//设置启动脚本
# cp ../zabbix/zabbix-4.0.10/misc/init.d/fedora/core5/zabbix_agentd /etc/rc.d/init.d/
# chmod +x /etc/rc.d/init.d/zabbix_agentd
# vi /etc/rc.d/init.d/zabbix_agentd	//修改ZABBIX_BIN中的值为实际安装路径
# /etc/init.d/zabbix_agentd 
Usage: /etc/init.d/zabbix_agentd {condrestart|start|stop|restart|reload|status}

//修改zabbix_agentd配置文件(查找以下项修改)
# vi /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.203.13
ListenPort=10050
ServerActive=1192.168.203.13
Hostname=		//根据实际情况修改,填写本机主机名
Include=/usr/local/zabbix/zabbix-agent/etc/zabbix_agentd.conf.d/*.conf	//根据实际路径修改

//启动zabbix-agent
# /etc/init.d/zabbix_agentd 
Usage: /etc/init.d/zabbix_agentd {condrestart|start|stop|restart|reload|status}

//client 操作
//登录zabbix监控管理页面,进行添加主机等操作(过程略)

补充一下搭建完毕之后的收获: 1、源码安装过分锻炼人,不熟悉的谨慎选择。

//附 Windows Server 2012 R2 Standard 部署zabbix-agent方法
//msi下载地址
https://assets.zabbix.com/downloads/4.0.10/zabbix_agent-4.0.10-win-amd64-openssl.msi
//安装即可,配置同其他zabbix-agent
//官方安装文档 https://www.zabbix.com/documentation/4.0/zh/manual/appendix/install/windows_agent
//启动zabbix-agent方法
>zabbix_agentd.exe --start

//后记
//zabbix_server.log 显示 At least one of '/usr/sbin/fping', '/usr/sbin/fping6' must exist. Both are missing in the system.
//需要fping支持,解决方法如下
# wget http://www.fping.org/dist/fping-4.2.tar.gz
# tar zxvf fping-4.2.tar.gz
# cd fping-4.2
# ./configure --prefix=/usr/local/fping && make && make install
//安装完毕,进行如下修改
# vim /usr/local/zabbix/etc/zabbix_server.conf	//编辑zabbix_server.conf去掉注释
523 FpingLocation=/usr/sbin/fping
//保存退出
# ln -s /usr/local/fping/sbin/fping /usr/sbin/fping
# chown root:zabbix /usr/sbin/fping
# chmod 6755 /usr/sbin/fping
# chmod +s /usr/sbin/fping
//切换到zabbix用户,进行测试
$ fping 192.168.203.***
192.168.203.*** is alive
//成功后重启zabbix-server即可。
//最后
//Zabbix图表出现中文乱码解决方案 https://www.linuxidc.com/Linux/2017-12/149284.htm


这里给大家推荐一个在线软件复杂项交易平台:米鼠网 https://www.misuland.com

米鼠网自成立以来一直专注于从事软件项目人才招聘软件商城等,始终秉承“专业的服务,易用的产品”的经营理念,以“提供高品质的服务、满足客户的需求、携手共创双赢”为企业目标,为中国境内企业提供国际化、专业化、个性化、的软件项目解决方案,我司拥有一流的项目经理团队,具备过硬的软件项目设计和实施能力,为全国不同行业客户提供优质的产品和服务,得到了客户的广泛赞誉。



如有侵权请联系邮箱(service@misuland.com)

猜你喜欢

评论留言