本文共 12728 字,大约阅读时间需要 42 分钟。
通过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/bashtar zxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gzmv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysqlrpm -e mariadb-libs --nodepsgroupadd mysqluseradd -g mysql -s /bin/false -M mysqlmkdir /usr/local/mysql/datachown -R mysql:mysql /usr/local/mysql/chmod 755 /usr/local/mysql/data/echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profilesource /etc/profileecho "[client]" >> /etc/my.cnfsed -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/dataexport 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/mysqldservice mysqld startsystemctl stop firewalld.servicesystemctl 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包:解压包并进行编译:[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 = -1mbstring.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.piduser = wwwgroup = wwwlisten =127.0.0.1:9000pm.max_children = 300pm.start_servers = 20pm.min_spare_servers = 20pm.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-fpmtcp 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" ' #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;#
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<?phpphpinfo()?>[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 -p123mysql> 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]#lsdata.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.logPidFile=/usr/local/zabbix/logs/zabbix_server.pidDBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=zabbixDBPort=3306FpingLocation=/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_servertcp 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 stopStopping zabbix_server (via systemctl): [ OK ][root@localhost zabbix-3.2.1]# /etc/init.d/zabbix_server startStarting zabbix_server (via systemctl): [ OK ][root@localhost zabbix-3.2.1]# netstat -anpt|grep zabbix_servertcp 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]bcmathbz2CorectypecurldatedomeregfileinfofilterftpgdgettexthashiconvjsonlibxmlmbstringmcryptmhashmysqlmysqliopensslpcntlpcrePDOpdo_sqlitePharposixReflectionsessionshmopSimpleXMLsoapsocketsSPLsqlite3standardsysvsemtokenizerxmlxmlreaderxmlrpcxmlwriterzipzlib访问 Web 界面 web 配置,配置完成后使用默认用户admin(密码:zabbix)登陆即可 (基础安装完成)转载于:https://blog.51cto.com/12620785/2067017