有道雲筆記連接http://note.youdao.com/noteshare?id=e8c71bdd66395ad373d94a782df8dfba&sub=12F495B54D03492D8A9FC1BC2C3D2AA9
鏈接:https://pan.baidu.com/s/1acq0eSonxUvyciaICYNghg
提取碼:k3ut
zabbix安裝
1、配置基礎環境
安裝zabbix服務端
安裝LAMP (linux Apache mysql php)
源碼安裝zabbix server
配置zabbix web頁面
在zabbix服務端安裝agent端
在另一台Linux上安裝agent端
規划好IP地址
zabbix-server:
僅主機:192.168.120.23
zabbix-agent:
僅主機:192.168.120.13
配置hosts文件
關閉防火牆iptables和selinux
配置好本地yum
2、安裝zabbix 服務端
需要軟件:
zabbix-3.4.3編譯源碼包
Mysql-5.7.17-glibc
系統自帶Apache(1.3.12或以上)
php-5.6.30(要求5.4.0或以上)
libmcrypt-2.5.8
libevent-2.1.8
pcre-8.01
1、LAMP的安裝
什么叫LAMP: Linux apache mysql php/perl/
還有LNMP nginx
安裝Apache:
yum -y install httpd httpd-devel
安裝mysql-5.7.17-glibc:
useradd mysql
tar xf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql
chown -R mysql:mysql mysql/
./mysqld --initialize --datadir=/data
PATH=$PATH:/usr/local/mysql/bin
vim /root/.bash_profile
mysqld_safe --skip-grant-tables &
mysql>flush privileges;
mysql>alter user root@localhost identified by ‘123’;
mysql>flush privileges;
my.cnf內容
[root@mysql-tar ~]# cat /etc/my.cnf
[mysqld]
datadir=/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
log-error=/data/mysqld.log
pid-file=/data/mysqld.pid
lower_case_table_names=1
[mysql]
socket=/tmp/mysql.sock
[root@mysql-tar ~]#
編譯安裝PHP-5.6.30
添加依賴包:
# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel db4-devel libXpm-devel libX11-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c libcurl libcurl-devel
安裝加密擴展庫:libmcrypt
[root@zabbix-server ~]# tar xf libmcrypt-2.5.8.tar.gz
[root@zabbix-server ~]# cd libmcrypt-2.5.8
[root@zabbix-server libmcrypt-2.5.8]# ./configure && make && make install
安裝php:
tar -xf php-5.6.30.tar.gz -C /usr/loca
[root@zabbix-server php-5.6.30]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-apxs2=/usr/sbin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-inline-optimization --enable-fpm --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
[root@zabbix-server php-5.6.30]# make ; make install
配置PHP
拷貝php.ini和php-fpm.conf:
[root@zabbix-server ~]# cd php-5.6.30
[root@zabbix-server php-5.6.30]# cp php.ini-production /etc/php.ini
[root@zabbix-server php-5.6.30]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@zabbix-server php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@zabbix-server php-5.6.30]# chmod +x /etc/init.d/php-fpm
fpm測試php配置:
[root@zabbix-server php-5.6.30]# /usr/local/php/sbin/php-fpm -t
[25-Dec-2017 12:47:10] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@zabbix-server php-5.6.30]#
添加到server里管理啟動:
[root@zabbix-server php-5.6.30]# chkconfig --add php-fpm
[root@zabbix-server php-5.6.30]# chkconfig php-fpm on
[root@zabbix-server php-5.6.30]# service php-fpm start
Starting php-fpm done
修改PHP默認端口:
[root@zabbix-server php-5.6.30]# vim /usr/local/php/etc/php-fpm.conf
listen = 127.0.0.1:8000
重啟生效:
[root@zabbix-server zabbix-3.4.3]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@zabbix-server zabbix-3.4.3]# netstat -tnulp|grep fpm
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 73066/php-fpm
[root@zabbix-server zabbix-3.4.3]#
配置Apache訪問PHP
配置httpd.conf讓Apache支持PHP:
# vim /etc/httpd/conf/httpd.conf
在AddType application/x-gzip .gz .tgz下面添加如下內容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改主頁位置:
DirectoryIndex index.php index.html index.html.var
添加加載模塊:(執行完上面后,該行已經存在在配置文件中,無需重復加載)
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
安裝zabbix server源碼包
安裝zabbix server所需的包:
[root@zabbix-server ~]# yum -y install curl libcurl-devel net-snmp net-snmp-devel perl-DBI libdbi-dbd-mysql mysql-devel gcc gcc-c++ make libxml2 libxml2-devel
創建zabbix用戶組和用戶:
[root@zabbix-server ~]# groupadd zabbix
[root@zabbix-server ~]# useradd -g zabbix zabbix
先安裝libevent:
# tar xf libevent-2.1.8-stable.tar.gz
# cd libevent-2.1.8-stable
[root@zabbix-server libevent-2.1.8-stable]# ./configure && make && make install
再安裝pcre:
[root@zabbix-server ~]# tar xf pcre-8.01.tar.gz
[root@zabbix-server ~]# cd pcre-8.01
[root@zabbix-server pcre-8.01]#
[root@zabbix-server pcre-8.01]# ./configure && make && make install
再安裝net-snmp:
[root@zabbix-server ~]# yum install net-snmp -y
再安裝odbc支持組件:
[root@zabbix-server ~]# yum -y install unixODBC unixODBC-devel
[root@zabbix-server ~]# yum install mysql-connector-odbc -y
再安裝libssh2支持組件:
[root@management_platform zabbix_soft]# tar xf libssh2-1.8.0.tar.gz
[root@management_platform zabbix_soft]# cd libssh2-1.8.0
[root@management_platform libssh2-1.8.0]# ./configure && make && make install
安裝zabbix-server:不要忘了加snmp和odbc和ssh2支持選項
[root@zabbix-server ~]# tar xf zabbix-3.4.3.tar.gz
[root@zabbix-server ~]# cd zabbix-3.4.3
[root@zabbix-server zabbix-3.4.3]# ./configure --prefix=/usr/local/zabbix-server --enable-server --with-mysql --with-net-snmp --with-unixodbc --with-libcurl --with-libxml2 --enable-agent --enable-ipv6 --enable-proxy --with-ssh2 && make install
[root@zabbix-server zabbix-3.4.3]#
配置zabbix server數據庫
創建數據庫和zabbix用戶並授權:
mysql> create database zabbix charset utf8;
mysql> grant all on zabbix.* to zabbix@localhost identified by '123';
mysql> flush privileges;
導入zabbix數據:
[root@zabbix-server zabbix-3.4.3]# mysql -uzabbix -p123 zabbix < database/mysql/schema.sql
[root@zabbix-server zabbix-3.4.3]# mysql -uzabbix -p123 zabbix < database/mysql/images.sql
[root@zabbix-server zabbix-3.4.3]# mysql -uzabbix -p123 zabbix < database/mysql/data.sql
配置zabbix server
復制web目錄:
[root@zabbix-server zabbix-3.4.3]# cp -R frontends/php /var/www/zabbix/
[root@zabbix-server zabbix-3.4.3]# chmod 777 /var/www/zabbix/php/conf
創建zabbix日志目錄並給目錄授權:
[root@zabbix-server ~]# mkdir /var/log/zabbix
[root@zabbix-server ~]# chown -R zabbix:zabbix /var/log/zabbix/
修改zabbix server配置文件:
[root@zabbix-server etc]# vim /usr/local/zabbix-server/etc/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123
DBSocket= /data/mysql.sock
DBPort = 3306
Timeout=4
LogSlowQueries=3000
啟動zabbix服務並配置環境變量
添加服務以及服務自啟動:
[root@zabbix-server zabbix-3.4.3]# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
[root@zabbix-server zabbix-3.4.3]# chkconfig --add zabbix_server
[root@zabbix-server zabbix-3.4.3]# chkconfig zabbix_server on
[root@zabbix-server zabbix-3.4.3]# ln -s /usr/local/zabbix-server/bin /usr/bin/
[root@zabbix-server zabbix-3.4.3]# cp /usr/local/zabbix-server/sbin/zabbix_server /usr/local/sbin/
[root@zabbix-server zabbix-3.4.3]# ln -s /usr/local/lib/libevent-2.1.so.6 /usr/lib64/
[root@zabbix-server zabbix-3.4.3]# service zabbix_server start
Starting zabbix_server: [ OK ]
[root@zabbix-server zabbix-3.4.3]#
配置zabbix環境變量:
#Vim /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/zabbix-server/bin
# source /root/.bash_profile
配置zabbix web頁面
編輯zabbix前端的配置文件:/etc/httpd/conf.d/zabbix.conf
# Zabbix monitoring system php web frontend
Alias /zabbix /var/www/zabbix/php
<Directory "/var/www/zabbix/php">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
#Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>
配置zabbix web頁面
修改httpd配置文件中servername:
# vim /etc/httpd/conf/httpd.conf
ServerName localhost:80
重啟httpd服務並添加服務及開機自啟:
[root@zabbix-server conf]# service httpd start
Starting httpd: [ OK ]
[root@zabbix-server ~]# chkconfig --add httpd
[root@zabbix-server ~]# chkconfig httpd on
重啟zabbix_server:
[root@zabbix-server conf]# service zabbix_server restart
Shutting down zabbix_server: [ OK ]
Starting zabbix_server: [ OK ]
[root@zabbix-server conf]#
網頁訪問進行安裝
在瀏覽器中訪問zabbix server:http://192.168.120.23/zabbix
登錄zabbix web:
默認web用戶及密碼:admin ,zabbix
Zabbix服務器端也開啟agent代理
添加agentd服務及自啟動:
[root@zabbix-server etc]# cp /root/zabbix-3.4.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@zabbix-server etc]# chkconfig --add zabbix_agentd
[root@zabbix-server etc]# chkconfig zabbix_agentd on
編輯agentd配置文件:
[root@zabbix-server etc]# cat /usr/local/zabbix-server/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=172.16.120.23
ServerActive=172.16.120.23
Hostname=mysql-tar
UnsafeUserParameters=1
[root@zabbix-server etc]
啟動agentd:
[root@zabbix-server etc]# ln -s /usr/local/zabbix-server/sbin/zabbix_agentd /usr/local/sbin/
[root@zabbix-server etc]# service zabbix_agentd start
Starting zabbix_agentd: [ OK ]
[root@zabbix-server etc]#
Linux端安裝及配置zabbix agent
所需軟件:
Zabbix-3.4.3編譯源碼包
Pcre-8.01
創建zabbix用戶組和用戶:
[root@rhat-6-zabbix-agent ~]# groupadd zabbix
[root@rhat-6-zabbix-agent ~]# useradd -g zabbix ==zabbix==
安裝依賴包pcre:
先安裝好編譯工具:
[root@rhat-6-zabbix-agent ~]# yum install gcc-c++ -y
安裝pcre:
[root@rhat-6-zabbix-agent ~]# tar xf pcre-8.01.tar.gz
[root@rhat-6-zabbix-agent ~]# cd pcre-8.01
[root@rhat-6-zabbix-agent pcre-8.01]# ./configure && make && make install
編譯安裝zabbix agent:
[root@rhat-6-zabbix-agent ~]# tar xf zabbix-3.4.3.tar.gz
[root@rhat-6-zabbix-agent ~]# cd zabbix-3.4.3
[root@rhat-6-zabbix-agent zabbix-3.4.3]# ./configure --prefix=/usr/local/zabbix-agent --enable-agent && make install
創建日志目錄並授權:
[root@rhat-6-zabbix-agent fedora]# mkdir /var/log/zabbix
[root@rhat-6-zabbix-agent fedora]# chown -R zabbix:zabbix /var/log/zabbix/
修改agent配置文件:
[root@rhat-6-zabbix-agent zabbix-agent]# vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=192.168.120.23
ServerActive=192.168.120.23
Hostname=mysql-rpm
UnsafeUserParameters=1
Timeout=8
添加服務方式啟動以及開機自啟動:
[root@rhat-6-zabbix-agent fedora]# cp /root/zabbix-3.4.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@rhat-6-zabbix-agent fedora]# chkconfig --add zabbix_agentd
[root@rhat-6-zabbix-agent fedora]# chkconfig zabbix_agentd on
[root@rhat-6-zabbix-agent fedora]# ln -s /usr/local/zabbix-agent/sbin/zabbix_agentd /usr/local/sbin/
[root@rhat-6-zabbix-agent fedora]# service zabbix_agentd start
Starting zabbix_agentd: [ OK ]
[root@rhat-6-zabbix-agent fedora]#
將軟件中默認配置文件拷貝到agent下:
# cp /root/zabbix-3.4.3/conf/zabbix_agentd/userparameter_examples.conf /usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/
# cp /root/zabbix-3.4.3/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/ ##監控MySQL
添加zabbix環境變量:/root/.bash_profile
在PATH后面添加zabbix bin位置:
PATH=$PATH:$HOME/bin:/usr/local/zabbix-agent/bin
執行生效:
# source /root/.bash_profile