普通用户安装zabbix监控服务

2017-01-09 14:08:44来源:oschina作者:白驹鸣鹿人点击



### 【zabbix简介】
1.zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
2. zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
3. zabbix由2部分构成,zabbix server与可选组件zabbix agent。
4. zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上
###【zabbix安装】
* 系统:CentOS Linux release 7.1.1503 (Core)
* 用户:普通用户aspire
* 所用软件包:
apr-1.4.6.tar.gz
httpd-2.4.4.tar.gz
mariadb-5.5.30-linux-x86_64.tar.gzphp-5.4.14.tar.gz
apr-util-1.5.2.tar.gz
libmcrypt-2.5.7.tar.gz
pcre-8.32.tar.gz
zabbix.tar.gz
**编译安装lamp环境**
vim /etc/security/limits.conf
添加如下内容:
```shell
*soft nproc 65535
*hard nproc 65535
*soft nofile 65535
*hard nofile 65535
```
vim etcsysctl.conf
添加如下内容:
```shell
net.ipv4.tcp_max_tw_buckets = 6000
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 65535
```
使用root用户安装如下包:
```shell
yum-yinstallsetuptool ntsysv system-config-securitylevel-tui system-config-network-tui system-config-keyboard vimlibxslt-devel lua-devel libatomic_opsfontconfig-develmake gcc gcc-c++bzip2 bzip2-devel curl-devel perl freetypefreetype-devel gd gd-devel libpng libiconv libjpeglibpng-devellibjpeg-devellibxml2 zlib zlib-devellibxml2-devellibmcryptlibmcrypt-devel fontconfig libXpmlibXpm-devel libX11 libX11-devel openssl dstat libtool php-bcmathnet-snmp-devel
```
使用root账户按照如下次序安装
```shell
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7 && ./configure --prefix=/usr && make && make install
```
使用普通用户依次安装
```shell
tar zxvf apr-1.4.6.tar.gz
cd apr-1.4.6 && ./configure --prefix=$HOME/apps/apr && make && make install
tar zxvf apr-util-1.5.2.tar.gz
cd apr-util-1.5.2 && ./configure --prefix=$HOME/apps/apr-util --with-apr=$HOME/apps/apr && make && make install
tar zxvf pcre-8.32.tar.gz
cd pcre-8.32 && ./configure --prefix=$HOME/apps/pcre && make && make install
```
安装mariadb
* 解压
```shell
tar zxvf mariadb-5.5.30-linux-x86_64.tar.gz
mv mariadb-5.5.30-linux-x86_64 ~/apps/mysql
cd /home/aspire/apps/mysql
cp support-files/my-innodb-heavy-4G.cnf my.cnf
```
* 修改my.cnf配置
```shell
default-storage-engine = INNODB
datadir = /home/aspire/apps/mysql/data
log-bin=/home/aspire/apps/mysql/logs/mysql-bin
slow_query_log
slow_query_log_file=/home/aspire/apps/mysql/logs
```
* 安装数据库
```shell
./scripts/mysql_install_db --defaults-file=/home/aspire/apps/mysql/my.cnf
```
* 启动mysql ```shell
./bin/msyqld_safe &
```
* 设置mysql的密码
```shell
./bin/mysqladmin -u root password "123456"
```
* 连接测试
```shell
[aspire@BJ-YZ-103R-81-6 mysql]$ ./bin/mysql -uroot -p123456
Welcome to the MariaDB monitor.Commands end with ; or /g.
Your MariaDB connection id is 3
Server version: 5.5.30-MariaDB-log MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
MariaDB [(none)]>
```编译安装httpd
```shell
tar zxvf httpd-2.4.4.tar.gz
cd httpd-2.4.4
./configure --prefix=$HOME/apps/apache --with-mpm=prefork --with-ssl=/usr/local/apache/openssl --enable-ssl --enable-module=setenvif --enable-module=so--enable-rewrite --enable-dav --enable-dav-fs --enable-suexec --enable-headers --enable-deflate --enable-expires --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --with-apr=$HOME/apps/apr --with-apr-util=$HOME/apps/apr-util --with-pcre=$HOME/apps/pcre --enable-cgi --enable-cgid
make && make install
```
php前置配置
安装php过程中出现找不到libXpm.(ao)及libgd.(ao)的情况
```shel
ln -s /usr/lib64/libgd.so.2.0.0 /usr/lib/libgd.so
ln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/libXpm.so
```
编辑/usr/include/gd_io.h
```shell
typedef struct gdIOCtx
{
int (getC) (struct gdIOCtx );
int (getBuf) (struct gdIOCtx , void , int);
void (putC) (struct gdIOCtx , int);
int (putBuf) (struct gdIOCtx , const void , int);
seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek!
int (seek) (struct gdIOCtx , const int);
long (tell) (struct gdIOCtx );
void (gd_free) (struct gdIOCtx );
void (data * ); 添加这里
}
gdIOCtx;
```
安装支持apache的php安装目录为php5
```shell
tar php-5.4.14.tar.gz
cd php-5.4.14
./configure --prefix=$HOME/apps/php5 --with-config-file-path=$HOME/apps/php5/etc --with-apxs2=$HOME/apps/apache/bin/apxs --with-mysql=$HOME/apps/mysql --with-mysqli=$HOME/apps/mysql/bin/mysql_config --with-pdo-mysql=$HOME/apps/mysql --with-gd=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-openssl --with-bz2 --with-zlib --with-xmlrpc --with-curl --with-gettext --with-iconv-dir=/usr --with-curlwrappers --with-mcrypt=$HOME/apps/lib/mcrypt --with-kerberos --with-imap-ssl --with-mhash --enable-pdo --enable-mbstring --enable-mbregex --enable-ctype --enable-json --enable-gd-native-ttf --enable-sockets --enable-calendar --enable-soap --enable-ftp --enable-fileinfo --enable-exif --enable-zip --disable-debug --with-xpm-dir=/usr --with-libxml-dir --without-pdo-sqlite --disable-ipv6 --enable-simplexml--enable-bcmath#启用bcmatch(公元前风格精度数学)
```
设置apache及php
拷贝php源安装文件夹里的php.ini-development到$HOME/apps/php5/etc/php.ini
修改php.ini文件里的
```shell
post_max_size = 16M
max_execution_time = 300
date.timezone = Asia/Shanghai
include_path = /home/aspire/apps/php5/lib/php
```
建立连接
```shell
cd /bin
ln -s /home/aspire/apps/php5/bin/php php
```
修改httpd.conf文件添加
```shell
Listen 8080
LoadModule socache_shmcb_module modulesmod_socache_shmcb.so
LoadModule slotmem_shm_module modulesmod_slotmem_shm.so
LoadModule rewrite_module modulesmod_rewrite.so
AddType application/x-httpd-php .php
AddType applicaiton/x-httpd-php-source .phps
Include confvhosts.conf
```
添加/usr/lib及/usr/lib64到/etc/ld.so.conf文件中
```shell
#vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/lib
/usr/lib64
/lib
/lib64
#ldconfig
```
server,agent安装(服务端)
```shell
./configure --prefix=/home/aspire/apps/zabbix --enable-server --enable-agent --with-mysql=/home/aspire/apps/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install
```
```shell
tail -4 /etc/services(尾部追加)
zabbix-agent10050/tcp#Zabbix Agent
zabbix-agent10050/udp#Zabbix Agent
zabbix-server10051/tcp#zabbix Trapper
zabbix-server10051/udp#zabbix Trapper
```
导入数据库
```shell
# mysql -uroot -p
mysql> create database zabbix character set utf8;
mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
# mysql -uzabbix -pzabbix zabbix<./database/mysql/schema.sql
# mysql -uzabbix -pzabbix zabbix<./database/mysql/images.sql
# mysql -uzabbix -pzabbix zabbix<./database/mysql/data.sql
```
编辑服务端配置文件
```shell
[aspire@BJ-YZ-103R-81-6 ~]$ vim apps/zabbix/etc/zabbix_server.conf
LogFile=/home/aspire/logs/zabbix/zabbix_server.log #日志路径
PidFile=/home/aspire/apps/zabbix/run/zabbix_server.pid
DBName=zabbix #数据库名
DBUser=zabbix #数据库用户
DBPassword=zabbix #数据库密码
DBSocket=/home/aspire/apps/mysql/tmp/mysql.sock #连接数据库的socket
```
安装客户端
```shell
cd src
tar -zxvf zabbix-3.0.7.tar.gz
cd zabbix-3.0.7
./configure --prefix=/home/aspire/apps/zabbix --enable-agent make && make install
mkdir -p $HOME/apps/zabbix/run
mkdir -p $HOME/logs/zabbix && touch $HOME/logs/zabbix/zabbix_agentd.log
```
客户端的配置文件格式
```shell
PidFile=/home/aspire/apps/zabbix/run/zabbix_agentd.pid
LogFile=/home/aspire/logs/zabbix/zabbix_agentd.log
Server=192.168.81.6,192.168.81.204 #server端的地址,客户端处于被动模式时,只允许所列的IP访问客户端
ServerActive=192.168.81.6 #主动模式时客户端会向此server ip主动发送数据
Hostname=192.168.81.4
RefreshActiveChecks=60
UnsafeUserParameters=1
Include=/home/aspire/apps/zabbix/etc/zabbix_agentd.conf.d/
```
启动服务端
```shell
$HOME/apps/zabbix/sbin/zabbix_server -c $HOME/apps/zabbix/etc/zabbix_server.conf
```
现在登录服web界面进入zabbix的世界吧
修改zabbix server配置文件
http://192.168.81.6:9090/zabbix/setup.php
注意:设置是php可能会显示无法连接mysql,是因为php默认用/tmp/mysql.sock 连接数据库。只需要将/home/aspire/apps/mysql/tmp/mysql.sock连接过去即可
```shell
ln -s/home/aspire/apps/mysql/tmp/mysql.sock/tmp/mysql.sock
```

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台