Zabbix安裝搭建
都需要監控什麽呢?
CPU,內存,硬盤,服務等等等,你想監控什麽就監控什麽,用自己的腳本寫出來
- 硬件監控:智能平臺管理接口 ipmitools(查看物理服務器信息),Megacli(查看raid磁盤信息)
yum install ipmitool -y
- 系統監控:CPU(lscpu,uptime,top,vmstat 1,mpstat 1,htop) 內存(free -m) 硬盤(df -h,iotop) 網絡(iftop,netstat,ss)
htop需要安裝,epel源(很強大)
yum install htop -y
沒有的都yum install一下
- 應用監控:nfs,mysql,nginx,apache,php,rsync等
- 日誌監控:系統日誌(安全日誌secure message sudo日誌)服務日誌(錯誤日誌error)
- 業務監控:網站是否能訪問
zabbix有兩個部分構成,zabbix server和zabbix agent 可選組件zabbix proxy
zabbix的官網 :https://www.zabbix.com/
搭建LNMP環境
配置環境
yum install pcre pcre-devel openssl-devel zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mcrypt -y
Nginx安裝方法
PHP安裝方法
Mysql安裝方法
(我這裏直接使用自己定制的RPM包安裝了)
編譯安裝zabbix
安裝依賴包(數據庫如果是二進制安裝的 需要加上 mysql-devel)
yum install fping net-snmp-devel unixODBC-devel openssl-devel OpenIPMI-devel java-devel -y
創建zabbix用戶
useradd zabbix -s /sbin/nologin
mkdir - p /application/tools
cd /application/tools/
下載zabbix
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.15/zabbix-3.0.15.tar.gz
tar xf zabbix-3.0.15.tar.gz
cd zabbix-3.0.15
./configure --prefix=/application/zabbix-3.0.15 --enable-server --enable-agent --enable-java --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-openssl
make && make install
ln -s /application/zabbix-3.0.15/ /application/zabbix
對數據庫操作
創建zabbix數據庫,並制定字符集
create database zabbix character set utf8 collate utf8_bin;
創建用戶
grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘zabbix‘;
刷新權限
flush privileges;
找到路徑*(在zabbix壓縮包裏),下面有三個SQL文件
/application/tools/zabbix-3.0.15/database/mysql
導入數據文件(數據庫裏操作,確定路徑,順序不要錯)
use zabbix
source /application/tools/zabbix-3.0.15/database/mysql/schema.sql #表結構,首先導入
source /application/tools/zabbix-3.0.15/database/mysql/images.sql #圖形,其次導入
source /application/tools/zabbix-3.0.15/database/mysql/data.sql #數據,最後導入
創建站點目錄
mkdir -p /application/nginx/html/zabbix
拷貝源碼包裏的PHP文件到 站點(tar解壓出來的包)
cp -a /application/tools/zabbix-3.0.15/frontends/php/* /application/nginx/html/zabbix/
chown -R www.www /application/nginx/html/zabbix/
修改配置PHP文件(修改後的)
egrep -n "^post_max_size|^max_execution|^max_input_time|^date.timezone" /application/php/lib/php.ini
372:max_execution_time = 300
382:max_input_time = 300
660:post_max_size = 16M
910:date.timezone = Asia/Shanghai
重啟
pkill php
/application/php/sbin/php-fpm
配置nginx文件
cat >/application/nginx/conf/nginx.conf<<EOF
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log logs/zabbix.log;
}
}
EOF
重啟
/application/nginx/sbin/nginx -s reload
配置zabbix文件
vim /application/zabbix/etc/zabbix_server.conf
修改77行,指定數據庫的IP地址
77 DBHost=127.0.0.1
111行指定數據庫密碼
111 DBPassword=zabbix
拷貝啟動腳本
cp /application/tools/zabbix-3.0.15/misc/init.d/fedora/core/zabbix_{server,agentd} /etc/init.d/
ls /etc/init.d/zabbix_*
/etc/init.d/zabbix_agentd /etc/init.d/zabbix_server
修改啟動腳本
sed -i "s#BASEDIR=/usr/local#BASEDIR=/application/zabbix#g" /etc/init.d/zabbix_{server,agentd}
啟動
/etc/init.d/zabbix_server start
Starting zabbix_server: /application/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[失敗]
沒有libmysqlclient.so.18庫文件
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
/etc/init.d/zabbix_server start
Starting zabbix_server: [確定]
可以訪問
http://192.168.70.134/zabbix/
要裝這個模塊,要不然用不了中文
找到PHP源碼包(tar.gz的包)
在裏面找到
cd /home/daxian/tools/php-5.5.32/ext
cd gettext/
(一定要在這個目錄下執行)
/application/php/bin/phpize
./configure --with-php-config=/application/php/bin/php-config
make && make install
echo "extension = gettext.so" >>/application/php/lib/php.ini
查看是否加入進去
/application/php/bin/php -m
重啟PHP
pkill php
/application/php/sbin/php-fpm
提示:如果之前是二進制安裝數據庫,最好把mysqli也裝一下
cd mysqli/
/application/php/bin/phpize
./configure --with-php-config=/application/php/bin/php-config
make && make install
echo "extension = mysqli.so" >>/application/php/lib/php.ini
/application/php/bin/php -m|grep mysqli
mysqli
搭建好了
Zabbix安裝搭建