zabbix分布式监控环境完全编译安装部署

很多文档使用的是yum安装mysql、http、php等工具。这里采用源码安装的形式,实现从LNMP-zabbix的全程记录。

一、LNMP平台搭建

参考:http://www.ttlsa.com/nginx/nginx-install-on-linux/

http://swht1278.blog.51cto.com/7138082/1623886

1.nginx的安装

1.1 依赖环境的部署

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel pcre-static gd-*

1.2 建立nginx用户及用户组

groupadd -r nginx && useradd -s /sbin/nologin -g nginx -r nginx

1.3 下载最新nginx安装包

wget -P /usr/local/src/ http://nginx.org/download/nginx-1.9.1.tar.gz

1.4 编译安装nginx

cd /usr/local/src/ && tar xf nginx-1.9.1.tar.gz

./configure --prefix=/usr/local/nginx --lock-path=/usr/local/nginx/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre --with-file-aio --with-http_image_filter_module && make && make install

1.5 nginx启动脚本

==============================

vim /etc/init.d/nginx   chmod +x /etc/init.d/nginx

#!/bin/bash

#

# Startup script for Nginx - this script starts and stops the nginx daemon

#

# chkconfig:   - 85 15

# description:  Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /usr/local/nginx/conf/nginx.conf

# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

sleep 1

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|

try-restart|reload|force-reload|configtest}"

exit 2

esac

==================================================

1.6 nginx的启动和关闭

service nginx start|reload|restart|stop

chkcofnig nginx on

或者:

启动 /usr/local/nginx-1.5.1/sbin/nginx

关闭 /usr/local/nginx-1.5.1/sbin/nginx -s stop

重启 /usr/local/nginx-1.5.1/sbin/nginx -s reload

2.mysql的安装

参考:二进制源码包安装mysql连接 http://www.ttlsa.com/mysql/install-mysql5_6/

自定义编译源码包安装mysql连接:http://swht1278.blog.51cto.com/7138082/1658992

2.1 编译环境安装(适用于最小化安装的Linux系统)

yum -y install wget gcc* make openssl openssl-devel openssl-clients ncurses-devel -y && yum groupinstall " Development tools"

2.2 mysql源码下载

wget -P /usr/local/src/ http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz

#wget -P /usr/local/src/ http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.25.tar.gz

wget -P /usr/local/src/ http://down1.chinaunix.net/distfiles/cmake-2.8.10.2.tar.gz

2.3 源码安装cmake编译环境

cd /usr/local/src/ && tar xf cmake-2.8.10.2.tar.gz

cd cmake-2.8.10.2 && ./configure --prefix=/usr/local/cmake && make && make install

vim /etc/profile

#set cmake

export PATH==$PATH:/usr/local/cmake/bin

source /etc/profile

2.4 源码安装mysql-5.6

groupadd mysql && useradd -r -g mysql -s /etc/nologin mysql  #(创建mysql用户不需要密码和登录系统)

mkdir -p /home/mysql/data && mkdir /home/mysql/var

cd /usr/local/src/ && tar xf mysql-5.6.20.tar.gz && cd mysql-5.6.20

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/home/mysql/var/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && make && make install

编译报错解决参考:http://blog.163.com/sz2273_pr/blog/static/41264296201361354426670/

环境变量配置

vim /etc/profile

在末行添加export PATH=$PATH:/usr/sbin/:/usr/local/mysql/bin

保存退出执行:source /etc/profile

2.5 初始化数据库

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql --default-storage-engine=MyISAM

2.6 修改配置文件my.cnf

============================================

vim /etc/my.cnf

[client]

default-character-set=utf8

#auto-rehash

socket = /home/mysql/var/mysql.sock

[mysqld]

# GENERAL #

user = mysql

slave-skip-errors=1022,1032,1062

basedir = /usr/local/mysql

default-storage-engine = MyISAM

socket = /home/mysql/var/mysql.sock

pid-file = /home/mysql/var/mysql.pid

port = 3306

# MyISAM #

key_buffer_size = 1344M

myisam_recover = FORCE,BACKUP

# SAFETY #

max_allowed_packet = 16M

max_connect_errors = 1000000

skip_name_resolve

# DATA STORAGE #

datadir = /home/mysql/data

long_query_time = 1

# BINARY LOGGING #

log-bin = /home/mysql/data/mysql-bin.log

expire-logs-days = 14

sync-binlog = 1

server-id = 1

max_binlog_size = 500M

# REPLICATION #

relay-log = /home/mysql/data/relay-bin.log

slave-net-timeout = 60

# CACHES AND LIMITS #

tmp_table_size = 32M

max_heap_table_size = 32M

max_connections = 500

thread_cache_size = 50

open_files_limit = 65535

table_definition_cache = 4096

table_open_cache = 4096

# INNODB #

innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend

innodb_flush_method = O_DIRECT

innodb_log_files_in_group = 2

innodb_lock_wait_timeout = 50

innodb_log_file_size = 256M

innodb_flush_log_at_trx_commit = 1

innodb_file_per_table = 1

innodb_thread_concurrency = 8

innodb_buffer_pool_size = 8G

# LOGGING #

log-error = /home/mysql/data/mysql-error.log

log-queries-not-using-indexes = 1

slow-query-log = 1

long_query_time = 1

slow-query-log-file = /home/mysql/data/mysql-slow.log

# FOR SLAVE #

#binlog-format = ROW

#log-slave-updates = true

#gtid-mode = on

#enforce-gtid-consistency = true

#master-info-repository = TABLE

#relay-log-info-repository = TABLE

#sync-master-info = 1

#slave-parallel-workers = 2

#binlog-checksum = CRC32

#master-verify-checksum = 1

#slave-sql-verify-checksum = 1

#binlog-rows-query-log_events = 1

#report-port = 3306

#report-host = 10.1.1.10

============================================

2.7 mysql的启动与关闭

cp support-files/mysql.server /etc/init.d/mysql && chmod +x /etc/init.d/mysql

service mysql start|stop|relaod|restart

chkconfig mysql on

3. PHP编译安装

参考:nginx连接PHP 5.5 http://www.ttlsa.com/nginx/nginx-php-5_5/

3.1 编译环境安装

yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y

3.2 源码包下载

wget -P /usr/local/src/ http://cn2.php.net/distributions/php-5.6.9.tar.gz

3.3 编译安装php5.6.9

cd /usr/local/src/ && tar xf  php-5.6.9.tar.gz && cd php-5.6.9

./configure  --prefix=/usr/local/php-5.6.9 --with-config-file-path=/usr/local/php-5.6.9/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath && make && make install

3.4 配置PHP

cp php.ini-production /usr/local/php-5.6.9/etc/php.ini

cp /usr/local/php-5.6.9/etc/php-fpm.conf.default /usr/local/php-5.6.9/etc/php-fpm.conf

=================================

打开php.ini配置文件,修改如下参数为如下值,否则zabbix安装不了。

max_execution_time = 300

memory_limit = 128M

post_max_size = 16M

upload_max_filesize = 2M

max_input_time = 300 #这个参数修改是在文档的第383行,相关信息在本文档下面有介绍

date.timezone PRC

==============================

3.5 启动PHP-fpm

/usr/local/php-5.6.9/sbin/php-fpm

3.6 nginx配置

===============================

location /

{

try_files $uri $uri/ /index.php?$args;

}

location ~ .*\.(php)?$

{

expires -1s;

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

#fastcgi_pass 127.0.0.1:9000;

fastcgi_pass unix:/var/run/phpfpm.sock;

}

=================================

二、编译安装zabbix

2.1 依赖环境安装

yum install net-snmp-devel libxml2-devel libcurl-devel -y

2.2 下载zabbix源码包

wget -p /usr/local/src/ http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.5/zabbix-2.4.5.tar.gz

2.3 编译安装zabbix

cd /usr/local/src/ && tar xf zabbix-2.4.5.tar.gz && cd zabbix-2.4.5

./configure --prefix=/usr/local/zabbix-2.4.5/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 && make && make install

2.4 创建用户

groupadd -r zabbix && useradd -s /sbin/nologin -g zabbix -r zabbix

2.5 初始化数据库

mysql -uroot -pPasswd

mysql>create database zabbix default charset utf8;

mysql>quit;

mysql -uroot -pPasswd zabbix < database/mysql/schema.sql #初始化proxy库

#初始化server库

mysql -uroot -p zabbix < database/mysql/images.sql

mysql -uroot -p zabbix < database/mysql/data.sql

mysql设置密码

$mysql

mysql>use mysql;

mysql>update  user set password=password(‘yzkj2015‘) where user=‘root‘;

mysql> flush privileges;

2.6 配置zabbix

mkdir /etc/zabbix && cp conf/zabbix_server.conf /etc/zabbix/ && vim /etc/zabbix/zabbix_server.conf

==============

DBName=zabbix

DBUser=root

DBPassword=yzkj2015

DBPort=3306

==============

2.7 zabbix_server启动

/usr/local/zabbix-2.4.5/sbin/zabbix_server

2.8 zabbix客户端配置

创建用户

groupadd -r zabbix && useradd -s /sbin/nologin -g zabbix -r zabbix

编译安装

cd /usr/local/src/ && tar xf zabbix-2.4.5.tar.gz && cd zabbix-2.4.5

./configure --prefix=/usr/local/zabbix-2.4.5/ --enable-agent && make && make install

修改配置文件

vim /usr/local/zabbix-2.2.2/etc/zabbix_agentd.conf

Server=127.0.0.1  #被动接受某个IP地址的检查

ServerActive=127.0.0.1 #主动将数据发送给该IP地址

Hostname=Zabbix server

客户端启动

/usr/local/zabbix-2.4.5/sbin/zabbix_agentd

2.9 浏览器安装

网站文件拷贝

mkdir /home/zabbix && cp -rp /usr/local/src/zabbix-2.4.5/frontends/php/* /home/zabbix && cp /home/zabbix/conf/zabbix.conf.php.example /home/zabbix/conf/zabbix.conf.php

报错PHP option max_input_time 60 300 Fail

解决:原因是php.ini文件里面有两个参数,第一个max_input_time默认是-1,第二个则是默认为60,需要修改成300

121 ; max_input_time

122 ;   Default Value: -1 (Unlimited)

123 ;   Development Value: 60 (60 seconds)

124 ;   Production Value: 60 (60 seconds)

125 max_input_time = 300

383 max_input_time = 300

报错:Error connecting to database: No such file or directory

原因是:Database host写成了localhost

解决:Database type  MySQL

Database host  127.0.0.1

Database port  3306

Database name  zabbix

User           root #可以是zabbix,这样安全,但要记得密码要对应

Password       *****

备注:这个地方的配置可以在/home/zabbix/conf/zabbix.conf.php中进行修改。路径根据自己的实际情况进行设置查找

2.10 使用默认账号登录首页

admin

zabbix

至此,zabbix的源码安装实验完成,接下来的将是对zabbix的配置进行学习,请参照另外文档。

参考文章:http://www.ttlsa.com/zabbix/install-zabbix-on-linux-5-ttlsa/

声明:该文档仅供学习使用,对于参考文章作者表示衷心感谢,我这篇文档仅仅是对整个搭建过程进行细致的参数调节,以及符合我们自身的生产情况。各位看官只关注学习就好~

时间: 2024-11-05 18:46:40

zabbix分布式监控环境完全编译安装部署的相关文章

zabbix分布式监控环境搭建

本次测试主要是在 centos 系统环境实践,测试内容:集群多台服务器资源监控做后续铺垫.zabbix的简介和自身的特点.在这就不阐述了 查询防火墙状态service iptables status停止防火墙:service iptables stop 防火墙配置状态查询:http://www.linuxidc.com/Linux/2012-06/63111.htm 环境准备: 1.需要确认防火墙是否关闭 2.Linux下安装zabbix需要有LAMP或者LNMP运行环境 一.安装LAMP环境

zabbix分布式监控部署proxy安装

之前写过一篇源码安装zabbix2.2.9版本,server端安装文档: http://mofansheng.blog.51cto.com/8792265/1679728 下面分享一下zabbix分布式监控proxy安装过程: 环境说明:centos6.6 64位系统:LAMP环境: 前提是zabbix server端已经安装完毕,server IP为192.168.20.10,proxy本机 IP 为192.168.20.11 :agent IP为192.168.20.12: 1.编译安装za

LNMP+zabbix分布式监控搭建及版本升级

LNMP+zabbix分布式监控搭建需要组件:gcc gcc-c++ openssl* pcre pcre-devel gd gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel autoconf automake imake expat-devel cmake libaio libaio-devel bzr bison libtool ncurses5-devel ncurses-devel ne

自动化运维工具之Zabbix分布式监控应用(五)

分布式监控概述proxy and nodeZabbix常用3种架构-->Server-agent-->Server-Node-agent-->Server-Proxy-agent Zabbix能高效地监控分布式IT架构在大型环境中Zabbix提供两种解决方案-->使用代理(proxy)-->使用节点(node)Proxy or Node?-->代理(proxy)用于本区域数据收集,并将数据发送给server-->节点(node)提供完整的Zabbix server

Zabbix分布式监控系统的初步搭建

昨天搞了整整一天,各种问题.搭建环境为LAMP,我天真的用LNMP去搭建,结果死活运行不起来zabbix的前台页面. 还有PHP的时区问题.mysql的连接问题.今天从开始安装,尽量整理重现碰到的所有问题,以及后续的解决办法 1.linux系统安装,用的是6.0minimal,安装过程就不写了. 2.环境搭建 LAMP apache我直接使用的yum安装 yum -y install httpd PHP同样也是yum 安装,也可以用源码. yum安装 yum install php php-fp

Zabbix分布式监控(zabbix-proxy)的配置关键点

Zabbix Proxy简介 Zabbix Proxy是实现Zabbix分布式监控的重要组成部分,是连接Zabbix Agent和Zabbix Server的"中间人"."连接器"."路由器"等.Zabbix Proxy将来自Agent的数据推送(push)到Zabbix Server或者由Zabbix Server来拿取(fetch). 与Zabbix Server相比Zabbix Proxy不需要使用或安装GUI(Graphical User

libCURL开源库在VS2010环境下编译安装,配置详解

libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 CURL开源库VS2010环境下编译安装,配置详解 一 准备 1.1 CURL官网下载地址:http://curl.haxx.se/download.html 1.2 找到源码包,我这里下载的是7.32.0版:http://curl.haxx.se/download/curl-7.32.0.zip 二 步骤 2.1 打开curl-7.32.0\

Zabbix分布式监控平台安装部署

Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. Zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位.解决存在的各种问题. Zabbix监控平台部署 安装zabbix之前需要LAMP架构,为了快速上手,我们这里采用yum安装LAMP,如果你想尝试,也可以使用源码版LAMP,效果是一样,都是为了解析zabbix php代码.执行如下命令安装LAMP环境: yum install httpd httpd-d

Zabbix,Nagios,OneAPM Servers 安装部署

如何快速实现对 Linux 服务器的监控? 做过服务器监控的开发者几乎都知道 Zabbix 和 Nagios ,他们都是提供系统监控以及网络监控功能的开源解决方案,资历比较老.在不久前,这个市场迎来了一位新成员OneAPM Servers--本土服务器监控领域的后起之秀. OneAPM Servers 虽然是一个商业级的解决方案,但是跟两位老牌玩家一样,都是完全免费的.今天,我们针对如何快速实现对 Linux 服务器监控,来对比一下这3种监控软件的安装部署过程: 一.Nagios 监控 Linu