如何迁移zabbix?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何迁移zabbix?相关的知识,希望对你有一定的参考价值。

一、到原zabbix服务器,把zabbix的mysql数据库备份出来,传到新zabbix服务器上:

# mysqldump -uroot -p123456 --opt  zabbix > zabbix.sql

# scp zabbix.sql [email protected]:/tmp 

如果遇到没有scp命令的话,请yum install openssh-clients -y

二、新zabbix服务器上安装lnmp环境和zabbix服务,以及还原zabbix数据库:

1、新zabbix服务器上安装lnmp环境:

#yum groupinstall "Development Tools" "Development Libraries" -y

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

#cd  /root

#tar xf pcre-8.37.tar.bz2 -C /usr/local/src/

#tar xf nginx-1.8.0.tar.gz -C /usr/local/src/ 

#cd /usr/local/src/nginx-1.8.0 

# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.37 

#make -j 4 && make install

#useradd -M -s /sbin/nologin nginx

#sed -i '/nobody/a \user nginx nginx;' /usr/local/nginx/conf/nginx.conf

#sed -i 's/index  index.html/index index.php index.html/' /usr/local/nginx/conf/nginx.conf

#sed -i '73 i\location ~ \.php$ {' /usr/local/nginx/conf/nginx.conf

#sed -i '74 i\root    html;' /usr/local/nginx/conf/nginx.conf

#sed -i '75 i\fastcgi_pass   127.0.0.1:9000;' /usr/local/nginx/conf/nginx.conf

#sed -i '76 i\fastcgi_index    index.php;' /usr/local/nginx/conf/nginx.conf

#sed -i '77 i\fastcgi_param    SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;' /usr/local/nginx/conf/nginx.conf

#sed -i '78 i\include    fastcgi_params;' /usr/local/nginx/conf/nginx.conf

#sed -i '79 i\}' /usr/local/nginx/conf/nginx.conf


#/usr/local/nginx/sbin/nginx

#echo /usr/local/nginx/sbin/nginx >> /etc/rc.local


#yum -y install cmake


#yum -y install ncurses-devel

#rpm -qa | grep mysql

#mysql-libs-5.1.71-1.el6.x86_64

#rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64


#cd  /root

#tar xf mysql-5.6.26.tar.gz -C /usr/local/src 

 #cd /usr/local/src/mysql-5.6.26 

 #useradd -M -s /sbin/nologin mysql 

#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql 

#make -j 4 && make install


#cd /root

 #chown -R mysql:mysql /usr/local/mysql/

#cp /etc/my.cnf /etc/my.cnf.bak

#rm -rf /etc/my.cnf 

#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#chmod +x /etc/init.d/mysqld

#chkconfig --add mysqld 

#chkconfig mysqld on

#ln -s /usr/local/mysql/bin/* /bin/


#/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

#/etc/init.d/mysqld start

#mysql_secure_installation  

#yum install php-pear -y 


#tar xf libmcrypt-2.5.8.tar.bz2 -C /usr/local/src 

#cd /usr/local/src/libmcrypt-2.5.8/ 

#./configure --prefix=/usr/local/libmcrypt && make -j 4 && make install


#yum -y install libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel


#echo '/usr/local/libmcrypt/lib'>>/etc/ld.so.conf

#echo '/usr/local/mysql/lib'>>/etc/ld.so.conf

#ldconfig 

#echo 'ldconfig' >> /etc/rc.local

#cd  /root

#tar xf php-5.6.13.tar.bz2 -C /usr/local/src/ 

#cd /usr/local/src/php-5.6.13

#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-mcrypt=/usr/local/libmcrypt 

# make -j 4 && make install

#cp php.ini-production /usr/local/php/php.ini

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

#sed -i 's/user = nobody/user = nginx/' /usr/local/php/etc/php-fpm.conf

#sed -i 's/group = nobody/group = nginx/' /usr/local/php/etc/php-fpm.conf

#cp /usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

#chmod +x /etc/init.d/php-fpm

#chkconfig --add php-fpm

#chkconfig php-fpm on

#/etc/init.d/php-fpm start

#echo "hello php" >> /usr/local/nginx/html/index.php

2、新zabbix安装zabbix服务器:


#mysql -uroot -p 123456

mysql> create database zabbix;

mysql> grant all on zabbix.* to [email protected]  identified by '123456';

mysql> flush privileges;

#cd /tmp

# mysql -uroot -p123456 zabbix < zabbix.sql 

配置 zabbix Server:

yum install -y net-snmp-devel

tar xvf zabbix-3.0.5.tar.gz -C /usr/local/src/ 

#cd !$

#cd zabbix-3.0.5/

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

#cd

#ls /usr/local/zabbix/

vim /usr/local/zabbix/etc/zabbix_server.conf

DBHost=localhost  #取消注释

DBName=zabbix #授权用户是zabbix

DBUser=zabbix #授权用户是zabbix

DBPassword=123456#密码是123456

useradd -u 8005 -M -s /sbin/nologin zabbix

/usr/local/zabbix/sbin/zabbix_server  

echo /usr/local/zabbix/sbin/zabbix_server >> /etc/rc.local  #开机启动

cd /usr/local/src/zabbix-3.0.5/misc/init.d/

cp fedora/core/zabbix_server /etc/init.d/ 

cp fedora/core/zabbix_agentd /etc/init.d/ 

vim /etc/init.d/zabbix_server

BASEDIR=/usr/local/zabbix  #找到此行,并修改

vim /etc/init.d/zabbix_agentd 

BASEDIR=/usr/local/zabbix  #找到此行,并修改

2、编辑 php 页面控制文件:

cp -r /usr/local/src/zabbix-3.0.5/frontends/php/*   /usr/local/nginx/html/ 

vim /usr/local/nginx/conf/nginx.conf

添加  index.php

/usr/local/nginx/sbin/nginx -s reload ;

/etc/init.d/php-fpm restart

网页进行配置zabbix

vim /usr/local/php/php.ini

post_max_size = 16M #修改

max_execution_time = 300 #修改

max_input_time = 300 #修改

date.timezone = Asia/Shanghai #此行有注释,去注释并修改

always_populate_raw_post_data = -1 #此行取消注释即可

/etc/init.d/php-fpm restart

cd /usr/local/src/php-5.6.13/ext/

cd gettext/

ls

config.m4   CREDITS    gettext.dsp    tests

config.w32  gettext.c  php_gettext.h

 /usr/local/php/bin/phpize 

./configure --with-php-config=/usr/local/php/bin/php-config && make -j 4 && make install;

vim /usr/local/php/php.ini

添加:extension = "gettext.so"

/etc/init.d/php-fpm restart

访问 http://ip/index.php

下载zabbix.conf.php

上传zabbix.conf.php

mv zabbix.conf.php  /usr/local/nginx/html/conf/ 

3、配置agent端:

1、安装 Agent

# yum install  curl curl-devel net-snmp net-snmp-devel perl-DBI  gcc -y // 解决 依赖

# useradd -u 8001 -M -s /sbin/nologin zabbix

# tar xvf zabbix-3.0.5.tar.gz -C /usr/local/src/ 

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

# ./configure --prefix=/usr/local/zabbix --enable-agent

//被监控端只需要部署 agnet

# make install ; cd

# cat /etc/services|grep zabbix

zabbix-agent    10050/tcp               # Zabbix Agent

zabbix-agent    10050/udp               # Zabbix Agent

zabbix-trapper  10051/tcp               # Zabbix Trapper

zabbix-trapper  10051/udp               # Zabbix Trapper

2、启动agent:

#grep "chkconfig" /usr/local/src/zabbix-3.0.5/ -R –color

//查看有 chkconfig 的 文件

/usr/local/src/zabbix-3.0.5/misc/init.d/fedora/core5/zabbix_agentd

/usr/local/src/zabbix-3.0.5/misc/init.d/fedora/core5/zabbix_server

/usr/local/src/zabbix-3.0.5/misc/init.d/fedora/core/zabbix_agentd

/usr/local/src/zabbix-3.0.5/misc/init.d/fedora/core/zabbix_server

3、配置 Agentd 的启动脚本

# cp /usr/local/src/zabbix-3.0.5/misc/init.d/fedora/core5/zabbix_agentd  /etc/init.d/

# vim /etc/init.d/zabbix_agentd //上一步生成了启动脚本,然后现在编辑脚 本

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd" #修改此行

#chmod +x  /etc/init.d/zabbix_agentd

#chmod +x  /etc/init.d/zabbix_server

# chkconfig --add zabbix_agentd 

# chkconfig zabbix_agentd on

#/etc/init.d/zabbix_agentd restart

拓展:core 和 core5 里面的文件都可以实现 zabbix 代理启动,core 里面是测试版本,core5 是稳定版本

4、配置 Agentd 的配置文件

#vim /usr/local/zabbix/etc/zabbix_agentd.conf //客户端操作

Server=127.0.0.1,192.168.146.99   #zabbix server 地址,可以多个ip,用,隔开

ServerActive=192.168.146.99 #主动检查的意思,主动检查手机的数据的数据发送给 Zabbix Server

Hostname=zabbix

UnsafeUserParameters=1

5、启动服务

# /etc/init.d/zabbix_agentd restart 





以上是关于如何迁移zabbix?的主要内容,如果未能解决你的问题,请参考以下文章

zabbix监控之迁移zabbix监控

zabbix2.4.5迁移到zabbix3.0

如何在不破坏 Zabbix 服务器的情况下从 php 5.4 迁移到 7.3?

zabbix-mysql迁移分离

zabbix 数据库迁移变更

zabbix server 数据库迁移