都需要监控什么呢?
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
(我这里直接使用自己定制的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
搭建好了