码迷,mamicode.com
首页 > 其他好文 > 详细

安装zabbix1

时间:2018-01-30 21:18:30      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:use   input   json   分数   sql数据库   bmc   log   启动脚本   使用   

通过LNMP平台安装zabbix
zabbix 重要组件说明:
1) zabbix server:负责接收 agent 发送的报告信息的核心组件,所有配置、统计数据及操作数据都由它组织进行;
2) database storage:专用于存储所有配置信息,以及由 zabbix 收集的数据;
3) web interface: zabbix 的 GUI 接口;
4) proxy:可选组件,常用于监控节点很多的分布式环境中,代理 server 收集部分数据转发到 server,可以减轻 server 的压力;
5) agent:部署在被监控的主机上,负责收集主机本地数据如 cpu、内存、数据库等数据发往 server 端或 proxy 端;
Zabbix 部署前的 LNMP 环境的搭建过程:
安装编译工具及库文件
[root@localhost ~]# yum -y install make apr autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm freetype libjpeg libpng libtool libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel
安装MySQL数据库(我用的是二进制安装包)
先用yum安装依赖包
[root@localhost ~]# yum -y install cmake ncurses bison
脚本安装:[root@localhost ~]# vi installmy5.sh
#!/bin/bash
tar zxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql
rpm -e mariadb-libs --nodeps
groupadd mysql
useradd -g mysql -s /bin/false -M mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/
chmod 755 /usr/local/mysql/data/
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
echo "[client]" >> /etc/my.cnf
sed -i ‘1a socket=/tmp/mysql.sock \
[mysqld] \
user=mysql \
basedir=/usr/local/mysql \
datadir=/usr/local/mysql/data \
pid-file=/usr/local/mysql/data/mysql.pid \
socket=/tmp/mysql.sock \
log-error=/usr/local/mysql/data/mysql.err ‘ /etc/my.cnf
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
export defaultmysqlpwd=grep ‘A temporary password‘ /usr/local/mysql/data/mysql.err | awk -F"root@localhost: " ‘{ print $2}‘
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
systemctl stop firewalld.service
systemctl disable firewalld.service
/usr/local/mysql/bin/mysql -uroot -p${defaultmysqlpwd} -e "alter user root@‘localhost‘ identified by ‘123‘" --connect-expired-password
[root@localhost ~]#chmod +x installmy5.sh
[root@localhost ~]#./installmy5.sh
[root@localhost ~]#ln -s /usr/local/mysql/bin/ /usr/local/bin/
[root@localhost ~]# mysql -uroot -p123
如果没关防火墙需要添加端口
[root@localhost ~]#firewall-cmd --permanent --add-port=3306/tcp
[root@localhost ~]#firewall-cmd --reload
查看端口号
netstat -anpt | grep mysqld
安装nginx
先下载zlib、pcre包,只需解压即可。
[root@localhost ~]# tar zxf zlib-1.2.8.tar.gz
[root@localhost ~]# tar zxf pcre-8.39.tar.gz
创建用户和组
[root@localhost ~]#groupadd www
[root@localhost ~]#useradd -s /sbin/nologin -g www www
下载nginx包:http://www.nginx.org
解压包并进行编译:
[root@localhost ~]# tar zxf nginx-1.10.2.tar.gz
[root@localhost ~ ]# cd nginx-1.10.2/
[root@localhost nginx-1.10.2]# ./configure --prefix=/usr/local/nginx1.10 --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=/root/pcre-8.39 --with-zlib=/root/zlib-1.2.8 --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
[root@localhost nginx-1.10.2]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx1.10/sbin/
/usr/local/sbin/
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep nginx //查看端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18620/nginx: master
[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
[root@localhost ~]# firewall-cmd --reload
安装php
先安装依赖包libmcrypt
[root@localhost ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@localhost ~]# cd libmcrypt-2.5.7/
[root@localhost libmcrypt-2.5.7]# ./configure && make && make install
[root@localhost libmcrypt-2.5.7]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20.3.7 /usr/local/mysql/lib/libmysqlclient_r.so
[root@localhost ~]# tar zxf php-5.6.27.tar.gz
[root@localhost ~]#cd php-5.6.27/
[root@localhost php-5.6.27]#./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl
[root@localhost php-5.6.27]# make && make install
[root@localhost php-5.6.27]# cp php.ini-production /etc/php.ini
[root@localhost php-5.6.27]# vi /etc/php.ini
修改后的内容如下:
date.timezone = PRC //设置时区
expose_php = Off //禁止显示 php 版本的信息
short_open_tag = On //支持 php 短标签
post_max_size = 30M //上传文件大小
max_execution_time = 300 //php 脚本最大执行时间
max_input_time = 300 //以秒为单位对通过 POST、 GET 以及 PUT 方式接收数据时间进行限制
always_populate_raw_post_data = -1
mbstring.func_overload = 0
:wq
添加php服务:
[root@localhost php-5.6.27]#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.27]# chmod +x /etc/init.d/php-fpm
[root@localhost php-5.6.27]# chkconfig --add php-fpm
[root@localhost php-5.6.27]# chkconfig php-fpm on
提供 php-fpm 配置文件并编辑:
[root@localhost php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@localhost php-5.6.27]#vi /usr/local/php5.6/etc/php-fpm.conf
修改内容如下:
pid = run/php-fpm.pid
user = www
group = www
listen =127.0.0.1:9000
pm.max_children = 300
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers =80
启动 php-fpm 服务:
[root@localhost php-5.6.27]# service php-fpm start
[root@localhost php-5.6.27]#netstat -anpt | grep php-fpm
tcp 0 127.0.0.1:9000 0.0.0.0:* LISTEN 10937/php-fpm: mast
配置 nginx 支持 php
[root@localhost php-5.6.27]# vi /usr/local/nginx1.10/conf/nginx.conf
配置如下:
user www www;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" "$http_x_forwarded_for"‘;

#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#error_page 404 /404.html;

redirect server error pages to the static page /50x.html

#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /status {
stub_status on;
}
}
}
:wq
[root@localhost ~]# nginx -t
[root@localhost ~]#nginx -s reload
测试 LNMP 进入 nginx 默认的网页根目录,创建.php 的测试页
[root@localhost ~]# cd /usr/local/nginx1.10/html/
[root@localhost html]# vi qwe.php
<?php
phpinfo()
?>
[root@localhost html]#vi qwe1.php
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘123‘);
if($link) echo "ok";
mysql_close();
?>
成功就ok。至此, LNMP 部署完毕。
监控系统 Zabbix-3.2.1 的安装
zabbix 服务器端要提前安装好 LNMP 环境( mysql, nginx, php5 的安装目录均是/usr/local)
创建 Zabbix 运行的用户 :
[root@localhost ~]# groupadd zabbix
[root@localhost ~]# useradd -g zabbix zabbix
安装依赖包:
[root@localhost ~]# yum -y install net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel
注: OpenIPMI-devel 和 libssh2-devel 软件包使用 centos 在线 yum 软件源安装
安装 Fping:
[root@localhost ~]# tar zxf fping-3.12.tar.gz
[root@localhost ~]#cd fping-3.12/
[root@localhost fping-3.12]# ./configure && make && make install
[root@localhost fping-3.12]#chown root:zabbix /usr/local/sbin/fping
[root@localhost fping-3.12]# chmod 4710 /usr/local/sbin/fping
安装 Zabbix Server:
[root@localhost ~]# tar zxf zabbix-3.2.1.tar.gz
[root@localhost ~]# cd zabbix-3.2.1/
[root@localhost zabbix-3.2.1]#./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi
[root@localhost zabbix-3.2.1]#make && make install
[root@localhost zabbix-3.2.1]#ln -s /usr/local/zabbix/bin/ /usr/local/bin/
[root@localhost zabbix-3.2.1]#ln -s /usr/local/zabbix/sbin/
/usr/local/sbin/
创建 Zabbix 数据库和 MySQL 用户 :
[root@localhost ~]#mysql -uroot -p123
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix. to zabbix@localhost identified by ‘zabbix‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
导入 Zabbix 初始数据: 切换到 zabbix 的解压目录下
[root@localhost zabbix-3.2.1]#cd database/mysql/
[root@localhost mysql]# pwd
/root/zabbix-3.2.1/database/mysql
[root@localhost mysql]#ls
data.sql images.sql schema.sql
进行 zabbix 初始数据导入
[root@localhost mysql]#mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql
[root@localhost mysql]#mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql
[root@localhost mysql]#mysql -uzabbix -pzabbix -hlocalhost zabbix < data.sql
编辑/usr/local/zabbix/etc/zabbix_server.conf:
先创建logs目录
[root@localhost ~]# mkdir -p /usr/local/zabbix/logs
[root@localhost ~]# vi /usr/local/zabbix/etc/zabbix_server.conf
修改内容如下:
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
FpingLocation=/usr/local/sbin/fping
[root@localhost ~]# chown -R zabbix:zabbix /usr/local/zabbix/
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
报错:/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20:cannot open shared object file: No such file or directory
解决方法:
在 ld.so.conf 中加入/usr/local/mysql/lib
[root@localhost zabbix-3.2.1]#vi /etc/ld.so.conf
添加:
/usr/local/mysql/lib
/usr/local/lib
[root@localhost zabbix-3.2.1]#ldconfig
再次执行 zabbix_server 启动
[root@localhost zabbix-3.2.1]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# netstat -anpt|grep zabbix_server
tcp 0 0 0.0.0.0:10051 0.0.0.0:
LISTEN 658/zabbix_server
添加开机启动脚本
[root@localhost zabbix-3.2.1]#cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
[root@localhost zabbix-3.2.1]#cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
[root@localhost zabbix-3.2.1]#chmod +x /etc/rc.d/init.d/zabbix_server
[root@localhost zabbix-3.2.1]#chmod +x /etc/rc.d/init.d/zabbix_agentd
[root@localhost zabbix-3.2.1]# chkconfig --add zabbix_server
[root@localhost zabbix-3.2.1]#chkconfig --add zabbix_agentd
[root@localhost zabbix-3.2.1]#chkconfig zabbix_agentd on
[root@localhost zabbix-3.2.1]# chkconfig zabbix_server on
修改 zabbix 开机启动脚本中的 zabbix 安装目录
编辑服务端配置文件
[root@localhost zabbix-3.2.1]#vi /etc/rc.d/init.d/zabbix_server
修改内容如下:
BASEDIR=/usr/local/zabbix/ //zabbix 安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid //pid 文件路径
:wq! //保存退出
编辑客户端配置文件
[root@localhost zabbix-3.2.1]# vi /etc/rc.d/init.d/zabbix_agentd
修改内容如下:
BASEDIR=/usr/local/zabbix/ //zabbix 安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid //pid 文件路径
:wq! //保存退出
[root@localhost zabbix-3.2.1]# systemctl daemon-reload
[root@localhost zabbix-3.2.1]# /etc/init.d/zabbix_server stop
Stopping zabbix_server (via systemctl): [ OK ]
[root@localhost zabbix-3.2.1]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl): [ OK ]
[root@localhost zabbix-3.2.1]# netstat -anpt|grep zabbix_server
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1658/zabbix_server
设置防火墙规则
[root@localhost zabbix-3.2.1]# firewall-cmd --permanent --add-port=10051/tcp
[root@localhost zabbix-3.2.1]#firewall-cmd --reload
配置 zabbix web 页面
在安装目录将 frontends 拷贝到指定的 web root:
[root@localhost zabbix-3.2.1]#cp -r frontends/php/ /usr/local/nginx1.10/html/zabbix
[root@localhost zabbix-3.2.1]# chown -R www:www /usr/local/nginx1.10/html/zabbix/
注: /usr/local/nginx/html 为 Nginx 默认站点目录 www 为 Nginx 运行账户
注:PHP 需要至少开启扩展:
gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql
[root@localhost zabbix-3.2.1]#/usr/local/php5.6/bin/php -m
显示如下:
[PHP Modules]
bcmath
bz2
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib
访问 Web 界面 http://192.168.159.22/zabbix,进行相关 web 配置,配置完成后使用默认用户
admin(密码:zabbix)登陆即可 (基础安装完成)

安装zabbix1

标签:use   input   json   分数   sql数据库   bmc   log   启动脚本   使用   

原文地址:http://blog.51cto.com/12620785/2067017

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!