zabbix 分布式安装源码安装 ubuntu14.04

1.前提安装好LAMP环境

教程地址:http://blog.csdn.net/qq_16095853/article/details/77946849

1.创建Zabbix运行的用户:

[root@Zabbix-server ~]# groupadd zabbix
[root@Zabbix-server ~]# useradd -g zabbix zabbix

2.安装依赖

apt-get install -y gcc make default-jdk libcurl4-openssl-dev  libsnmp-dev snmp zabbix-server-mysql zabbix-frontend-php mysql-server mysql-client libmysqlclient-dev  libevent-dev libpcre3-dev daemon

安装Fping:
[root@Zabbix-server ~]# cd /usr/local/src
[root@Zabbix-server src]# wget -c  http://fping.org/dist/fping-3.4.tar.gz
[root@Zabbix-server src]# tar zxvf fping-3.4.tar.gz
[root@Zabbix-server src]# cd fping-3.4
[root@Zabbix-server fping-3.4]# ./configure
[root@Zabbix-server fping-3.4]# make && make install
[root@Zabbix-server fping-3.4]# chown root:zabbix /usr/local/sbin/fping
[root@Zabbix-server fping-3.4]# chmod 4710 /usr/local/sbin/fping

3.如果安装不上更新源

更新源地址:http://blog.csdn.net/qq_16095853/article/details/77934760

之后:

apt-get update 

apt-get upgrade

4.安装zabbix

1.可以去官网下载:https://www.zabbix.com/download    ftp(ftp搭建网址)   将下载好的文件传到要用的远程目录。

2. 用wget方式下载到当前目录

具体方式如下:

 1)找到官网页面 根据自己需要选择版本



2)点download


我的是源码安装所以选择orig.tar.gz

wget  http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/     后面加上下载的文件

我的下载

wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/zabbix_3.4.1.orig.tar.gz

3)解压文件

cd /usr/local/src
tar -zxvf zabbix_3.4.1.orig.tar.gz
cd /zabbix-3.4.1

4)编译文件

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --enable-java --with-mysql --with-net-snmp --with-libcurl

编译时最好带上--enable-java这个参数,方便后续监控tomcat程序所用。

 make && make install

5)zabbix server配置与启动

[root@Zabbix-server ~]# mysql -uroot -p
........
mysql>create database zabbix default charset utf8;
Query OK, 1 row affected (0.05 sec)
mysql> create user 'zabbix'@'%' identified by '123456';
Query OK, 0 rows affected (0.16 sec)
mysql> grant all on zabbix.* to 'zabbix'@'%' identified by '123456';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)


6)导入zabbix初始数据

切换到zabbix的解压目录下,这里是/usr/local目录下

[root@Zabbix-server ~]# cd /usr/local
[root@Zabbix-server src]# cd zabbix-3.4.1
[root@Zabbix-server zabbix-3.4.1]#cd database/mysql/
[root@Zabbix-server mysql]# pwd
/usr/local/src/zabbix-3.0.3/database/mysql
[root@Zabbix-server mysql]# ls
data.sql images.sql schema.sql

导入数据

假想你安装好了MySQL,用户名为root,密码为bb

mysql -uroot -pbb  zabbix < schema.sql

mysql -uroot -pbb  zabbix < images.sql

mysql -uroot -pbb  zabbix < data.sql

7).编译/usr/local/zabbix/etc/zabbix_server.conf:

[root@Zabbix-server ~]#vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=192.168.1.30
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBPort=3306
FpingLocation=/usr/local/sbin/fping
DBSocket=/var/run/mysqld/mysqld.sock

8)从安装目录拷贝zabbix_server脚本,并编译:

[root@Zabbix-server ~]# cd /usr/local
[root@Zabbix-server src]# cd zabbix-3.4.1
[root@Zabbix-server zabbix-3.0.3]# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
[root@Zabbix-server zabbix-3.0.3]# mkdir -p /usr/local/zabbix/logs
[root@Zabbix-server zabbix-3.0.3]# chown -R www-data:www-data /var/www/html/zabbix/conf
[root@Zabbix-server zabbix-3.0.3]# vim /etc/init.d/zabbix_server
[root@Zabbix-server zabbix-3.0.3]# cat /etc/init.d/zabbix_server
# Source function library.
. /lib/lsb/init-functions  #ubuntu的functions的目录
#. /etc/init.d/functions  centos目录

RETVAL=0
prog="Zabbix Server"
#ZABBIX_BIN="/usr/local/sbin/zabbix_server"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
if [ ! -x ${ZABBIX_BIN} ] ; then
        echo -n "${ZABBIX_BIN} not installed! "
        # Tell the user this has skipped
        exit 5
fi

start() {
        echo -n $"Starting $prog: "
        daemon $ZABBIX_BIN 
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_server
        echo "[OK]"   #自己添加的【OK】
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server
        echo "[OK]"   #自己添加的【OK】
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_server ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL

9).调整防火墙规则(开放端口10051):

[root@Zabbix-server ~]# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT

[root@Zabbix-server ~]# /etc/init.d/iptables restart

或者直接卸载

apt-get remove iptables


启动Zabbix Server:

10) selinux是否关闭。一定要关闭这个,开启selinux会引起一连串问题,甚至zabbix的discovery功能也不能正常使用

 apt-get remove selenium

配置启动:



sudo vim /etc/default/zabbix-server

修改项:

START=yes

启动Zabbix Server:


[root@Zabbix-server ~]# service zabbix_server start                  #也可以直接/usr/local/zabbix/sbin/zabbix_server方式启动

Starting Zabbix Server: [ OK ]

     停止Zabbix Server:



[root@Zabbix-server ~]# service zabbix_server stop

Stopping Zabbix Server: [ OK ]


添加服务端口


#vim /etc/services添加

zabbix-agent 10050/tcp # Zabbix Agent

zabbix-agent 10050/udp # Zabbix Agent

zabbix-trapper 10051/tcp # Zabbix Trapper

zabbix-trapper 10051/udp # Zabbix Trapper



也可以使用输入重定向的方式


cat >>/etc/services <<EOF

zabbix-agent 10050/tcp #Zabbix Agent

zabbix-agent 10050/udp #Zabbix Agent

zabbix-trapper 10051/tcp #Zabbix Trapper

zabbix-trapper 10051/udp #Zabbix Trapper

EOF 


6.zabbixweb前端

    #mkdir -p /var/www/html/zabbix

    # cd /usr/local/src/zabbix-3.4.1 

     #cp -rf zabbix-3.4.1/frontends/php/* /var/www/html/zabbix

     #chown -R apache:apache /var/www/html/zabbix/conf

7.修改php相关参数

#vim /etc/php5/apache2/php.ini

max_execution_time = 300

max_input_time = 300

date.timezone = Asia/Shanghai

post_max_size = 32M 

session.auto_start = 0 ; 

mysql.default_socket = /var/run/mysqld/mysqld.sock   #ubuntu mysql.sock 的位置

    

/etc/init.d/apache2  restart


8.安装扩展



:PHP需要至少开启扩展:gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql

查看扩展方式:

root@ubuntu32:/etc# php -m 

[PHP Modules]

bcmath

bz2

calendar

Core

ctype

curl

date

dba

dom

ereg

exif

fileinfo

filter

ftp

gd

gettext

hash

iconv

json

ldap

libxml

mbstring

mhash

mysql

mysqli

openssl

pcntl

pcre

PDO

pdo_mysql

Phar

posix

readline

Reflection

session

shmop

SimpleXML

soap

sockets

SPL

standard

sysvmsg

sysvsem

sysvshm

tokenizer

wddx

xml

xmlreader

xmlwriter

Zend OPcache

zip

zlib


[Zend Modules]

Zend OPcache


9.访问Web界面

访问界面   IP/zabbix









看下面这张图配置



官网上有这样一段话

Download the configuration file and place it under conf/ in the webserver HTML documents subdirectory where you copied Zabbix PHP files to.

下载这个配置文件将其复制到相应的位置

上面的图片也提到了

#用上文提到的ftp,将这个文件复制到/var/www/html/zabbix/conf/zabbix.conf.php  这里

          

刷新页面就成功了:默认的登陆名Admin   密码zabbix

            





安装zabbix_server服务端脚本

# get network ip addr function  
apt-get update
apt-get  install -y apache2 php5  php5-mysql php5-gd curl libcurl3 libcurl3-dev php5-curl phpmyadmin mysql-server language-pack-zh-hans
sed -i '$a ServerName localhost:80' /etc/apache2/apache2.conf 
sudo ln -s /usr/share/phpmyadmin /var/www/html/pma
sed -i "/^bind-address/c#bind-address" /etc/mysql/my.cnf
groupadd zabbix
useradd -g zabbix zabbix
apt-get install -y gcc make default-jdk libcurl4-openssl-dev  libsnmp-dev snmp zabbix-server-mysql zabbix-frontend-php mysql-server mysql-client libmysqlclient-dev  libevent-dev libpcre3-dev daemon
cd /usr/local/src
wget -c  http://fping.org/dist/fping-3.4.tar.gz
tar zxvf fping-3.4.tar.gz
cd fping-3.4
./configure
make && make install
chown root:zabbix /usr/local/sbin/fping
chmod 4710 /usr/local/sbin/fping
cd /usr/local/src
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/zabbix_3.4.1.orig.tar.gz
tar -zxvf zabbix_3.4.1.orig.tar.gz
cd zabbix-3.4.1
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --enable-java --with-mysql --with-net-snmp --with-libcurl
make && make install
echo "create database zabbix default charset utf8;" >>/usr/local/createsql.sql
echo "create user 'zabbix'@'%' identified by '123456';">>/usr/local/createsql.sql
echo "grant all on zabbix.* to 'zabbix'@'%' identified by '123456';">>/usr/local/createsql.sql
echo "flush privileges;">>/usr/local/createsql.sql
cd /usr/local
mysql -uroot -pbb <createsql.sql
cd /usr/local/src
cd zabbix-3.4.1
cd database/mysql/
mysql -uroot -pbb  zabbix < schema.sql
mysql -uroot -pbb  zabbix < images.sql
mysql -uroot -pbb  zabbix < data.sql
function getIP()  
{  
    NET=$1  
    if [ "$NET" = "" ]; then  
        NET="eth0"  
    fi  
    IP=""  
    if [ $(ifconfig | grep "$NET" | wc -l) -gt 0 ]; then  
        IP=$(ifconfig $NET | grep 'inet addr:' | awk -F: '{print $2}' | awk '{print $1}')  
    fi  
    echo $IP  
} 
ETH0_IP=$(getIP eth0)
sed -i "s/^# DBHost=localhost/DBHost=$ETH0_IP/" /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/^# DBPassword=/DBPassword=123456/' /usr/local/zabbix/etc/zabbix_server.conf
sed -i 's/^# DBPort=3306/DBPort=3306/' /usr/local/zabbix/etc/zabbix_server.conf
sed -i '/^# FpingLocation=\/usr\/sbin\/fping/cFpingLocation=/usr/local/sbin/fping' /usr/local/zabbix/etc/zabbix_server.conf
sed -i "/^# DBSocket=\/tmp\/mysql.sock/cDBSocket=/var/run/mysqld/mysqld.sock" /usr/local/zabbix/etc/zabbix_server.conf
cd /usr/local/src
cd zabbix-3.4.1
cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
mkdir -p /usr/local/zabbix/logs
mkdir -p /var/lock/subsys
chown -R zabbix:zabbix /usr/local/zabbix
sed -i '17c . /lib/lsb/init-functions' /etc/init.d/zabbix_server
sed -i '21c ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server" '  /etc/init.d/zabbix_server
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables-save >/etc/iptables-script
apt-get remove selenium   
sed -i 's/^START=no/START=yes/' /etc/default/zabbix-server
sed -i '$a zabbix-agent 10050/tcp # Zabbix Agent' /etc/services 
sed -i '$a zabbix-agent 10050/udp # Zabbix Agent' /etc/services
sed -i '$a zabbix-trapper 10051/tcp #Zabbix Trapper' /etc/services
sed -i '$a zabbix-trapper 10051/udp #Zabbix Trapper' /etc/services
/etc/init.d/zabbix_server  start
mkdir -p /var/www/html/zabbix
cd /usr/local/src 
cp -rf zabbix-3.4.1/frontends/php/* /var/www/html/zabbix
chown -R www-data:www-data /var/www/html/zabbix/conf
sed -i 's/^max_execution_time = 30/max_execution_time = 300/' /etc/php5/apache2/php.ini
sed -i 's/^max_input_time = 60/max_input_time = 300/' /etc/php5/apache2/php.ini
sed -i '/^;date.timezone/cdate.timezone="Asia/Shanghai"' /etc/php5/apache2/php.ini
sed -i 's/^post_max_size = 8M/post_max_size = 32M/' /etc/php5/apache2/php.ini
self_hostname=$(cat /etc/hostname)
sed -i "2a $ETH0_IP     $self_hostname"  /etc/hosts
cd /usr/local/src/zabbix-3.4.1/
cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d
sed -i "s/^Server=127.0.0.1/Server=$ETH0_IP/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/ServerActive=$ETH0_IP/" /usr/local/zabbix/etc/zabbix_agentd.conf   
sed -i "s/^Hostname=Zabbix server/Hostname=$self_hostname/" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/^# Timeout=3/Timeout=15/' /usr/local/zabbix/etc/zabbix_agentd.conf  
sed -i '$a Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/' /usr/local/zabbix/etc/zabbix_agentd.conf 
sed -i '17c . /lib/lsb/init-functions' /etc/init.d/zabbix_agentd
sed -i '21c ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd" '  /etc/init.d/zabbix_agentd 
service mysql restart
service apache2 restart
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
sed -i "47c define('ZBX_GRAPH_FONT_NAME',           'simkai');" /var/www/html/zabbix/include/defines.inc.php 
echo '#!/bin/sh
mkdir /var/lock/subsys
/sbin/iptables-restore /etc/iptables-script
service mysql restart
service apache2 restart
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start'>>/etc/init.d/autoServer.sh
chmod 777 /etc/init.d/autoServer.sh
cd /etc/init.d
update-rc.d autoServer.sh  defaults
mkdir /swap
cd /swap/
free -m
sysctl vm.swappiness=10
echo 'vm.swappiness=10' >>/etc/sysctl.conf
reboot


安装zabbix_agent客户端脚本,将这段代码复制到自己创建的.sh文件里,赋予权限运行即可(记得根据提示输入zabbix_server的IP)

#!/bin/bash  
# get network ip addr function  
function getIP()  
{  
    NET=$1  
    if [ "$NET" = "" ]; then  
        NET="eth0"  
    fi  
    IP=""  
    if [ $(ifconfig | grep "$NET" | wc -l) -gt 0 ]; then  
        IP=$(ifconfig $NET | grep 'inet addr:' | awk -F: '{print $2}' | awk '{print $1}')  
    fi  
    echo $IP  i
}
read -p "please,Input your zabbix_server_ip:" youname
apt-get update
apt-get install -y gcc make libcurl4-openssl-dev  libsnmp-dev snmp  libevent-dev libpcre3-dev daemon
ETH0_IP=$(getIP eth0)  
SERVER_IP=$youname
self_hostname=$(cat /etc/hostname)
sed -i "2a $ETH0_IP     $self_hostname"  /etc/hosts
groupadd zabbix
useradd -g zabbix zabbix
cd /usr/local/src
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/zabbix_3.4.1.orig.tar.gz
tar -zxvf zabbix_3.4.1.orig.tar.gz
cd zabbix-3.4.1
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables-save >/etc/iptables-script
echo '#!/bin/sh
mkdir /var/lock/subsys
/sbin/iptables-restore /etc/iptables-script
service mysql restart
service apache2 restart
/etc/init.d/zabbix_agentd start'>>/etc/init.d/autoServer.sh
chmod 777 /etc/init.d/autoServer.sh
cd /etc/init.d
update-rc.d autoServer.sh  defaults
mkdir -p /var/lock/subsys
sed -i "s/^Server=127.0.0.1/Server=$SERVER_IP/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/ServerActive=$SERVER_IP/" /usr/local/zabbix/etc/zabbix_agentd.conf  
sed -i "s/^Hostname=Zabbix server/Hostname=$self_hostname/" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/^# Timeout=3/Timeout=15/" /usr/local/zabbix/etc/zabbix_agentd.conf  
sed -i '$a Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/' /usr/local/zabbix/etc/zabbix_agentd.conf 
sed -i '17c . /lib/lsb/init-functions' /etc/init.d/zabbix_agentd
sed -i '21c ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd" '  /etc/init.d/zabbix_agentd 
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
/etc/init.d/zabbix_agentd start



安装zabbix_proxy  单独的一台机子

apt-get install -y gcc  make default-jdk libcurl4-openssl-dev  libsnmp-dev snmp  mysql-server mysql-client libmysqlclient-dev  libevent-dev libpcre3-dev daemon libssh2-1-dev libssh2-php sqlite3  libsqlite3-dev  
cd /usr/local/src
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/zabbix_3.4.1.orig.tar.gz
tar -zxvf zabbix_3.4.1.orig.tar.gz 
cd  /usr/local/src/zabbix-3.4.1
./configure --prefix=/usr/local/zabbix --enable-proxy --with-net-snmp --with-sqlite3 --with-ssh2
make && make install
 cd zabbix-3.4.1/database/mysql
 mysql -uroot -pbb  zabbix < schema.sql
groupadd zabbix_proxy
useradd -g zabbix_proxy zabbix_proxy
 vi /usr/local/zabbix/etc/zabbix_proxy.conf
vim /usr/local/zabbix/etc/zabbix_proxy.conf

Server=IP                      #zabbix服务端IP
Hostname=Zabbix_proxy          #必须和WEB页面添加代理时设置的名称一致
LogFile=/tmp/zabbix_proxy.log    #日志文件路径
DBHost=IP                      #数据库IP
DBName=/tmp/zabbix_proxy.sqlite3.db   
DBUser=user                    #数据库用户名
DBPassword=password            #数据库密码
ConfigFrequency=60               #配置文件同步间隔
DataSenderFrequency=5            #数据同步间隔
原来proxy强制使用SQLite,所以必须指定一个数据库文件存放目录。

解决方案:
于是放开DBName参数并修改为:
DBName=/tmp/zabbix_proxy.sqlite3.db

/usr/local/zabbix/sbin/zabbix_proxy


 
 
 
 
 
 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值