zabbix学习笔记
Posted IT服务人员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix学习笔记相关的知识,希望对你有一定的参考价值。
系统环境:redhat 7
安装运行环境(LNMP)以下文档是我直接复制,懒得排版了,请大家见谅。
第一部分主要介绍LNMP环境搭建,分别参考网站如下:
1、http://www.linuxprobe.com/chapter-20.html
2、http://www.ttlsa.com/zabbix/install-zabbix-on-linux-5-ttlsa/
-、LNMP环境搭建
因为最近刚拾起LINUX练习环境一直用的是REDHAT 7,由于Redhat的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件。在这种情况下,想使用Redhat系统,还想用yum源来在线安装软件,我们就需要对其进行更换成CentOS的yum源。接下来我将给大家进行演示操作:
1、 删除当前YUM
[root@51hhy ~]# rpm -aq |grep yum
yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-rhn-plugin-2.0.1-4.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch
[root@51hhy ~]# rpm -aq |grep yum|xargs rpm -e –nodeps ##查看并删除yum
[root@51hhy ~]# rpm -aq |grep yum ##查看
[root@51hhy ~]#
2、 下载新的yum包,使用使用Centos7的yum包
这里需要安装的包我给大家列出来,大家可以去网上找
python-urlgrabber-3.10-8.el7.noarch.rpm
yum-3.4.3-132.el7.centos.0.1.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
yum-updateonboot-1.1.31-42.el7.noarch.rpm
安装相关rpm包
[root@51hhy src]# rpm -ihv yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-3.4.3-132.el7.centos.0.1.noarch.rpm yum-updateonboot-1.1.31-42.el7.noarch.rpm yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
warning: yum-metadata-parser-1.1.4-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
2:yum-plugin-fastestmirror-1.1.31-3################################# [ 50%]
3:yum-3.4.3-132.el7.centos.0.1 ################################# [ 75%]
4:yum-updateonboot-1.1.31-42.el7 ################################# [100%]
3、更换yum源。我这里用的阿里云的源
第一步:备份你的原镜像文件,以免出错后可以恢复。
[root@51hhy yum.repos.d]# mv /usr/local/src/Centos-7.repo /etc/yum.repos.d/
第二步:下载新的CentOS-Base.repo 到/etc/yum.repos.d/并编辑(文档内容附下,可直接用)
# CentOS-Base.repo文档开始
#CentOS-Base.repo
#
#The mirror system uses the connecting IP address of the client and the
#update status of each mirror to pick mirrors that are updated to and
#geographically close to the client. Youshould use this for CentOS updates
#unless you are manually picking other mirrors.
#
# Ifthe mirrorlist= does not work for you, as a fall back you can try the
#remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever- Base - vault.centos.org
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
#releasedupdates
[updates]
name=CentOS-$releasever- Updates - vault.centos.org
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
#additionalpackages that may be useful
[extras]
name=CentOS-$releasever- Extras - vault.centos.org
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
#additionalpackages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever- Plus - vault.centos.org
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
#contrib- packages by Centos Users
#[contrib]
#name=CentOS-$releasever- Contrib - mirrors.aliyun.com
#failovermethod=priority
#baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
# http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/release=$releasever&arch=$basearch&repo=contrib
#gpgcheck=1
#enabled=0
#gpgkey=http://vault.centos.org/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-7
# CentOS-Base.repo文档结束
3、 运行yum makecache生成缓存
这样我们的yum仓库就更新完成了
二、下来我们正式进入LNMP环境搭建
首先我们将需要的安装包下载到本地/usr/local/src目录下
安装软件前我们先安装各种依赖包,我整理出来供大家用(共计213个,完全满足各种需求)
[root@51hhy ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel db4-devel ntpdate php-mysql cyrus-sasl-md5 perl-GD perl-DBD-MySQL perl-GD perl-CPAN perl-CGI perl-CGI-Session cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel libicu-devel mail mysql-devel mysql-server net-snmp-devel libcurl-devel imake libevent libevent-devel
LNMP所需软件如下:
[root@51hhy src]# ls
cmake-2.8.11.2.tar.gz
freetype-2.5.3.tar.gz
jpegsrc.v9a.tar.gz
libgd-2.1.0.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.6.12.tar.gz
libvpx-v1.3.0.tar.bz2
mysql-5.6.19.tar.gz
nginx-1.6.0.tar.gz
openssl-1.0.1h.tar.gz
pcre-8.35.tar.gz
php-5.5.14.tar.gz
t1lib-5.1.2.tar.gz
tiff-4.0.3.tar.gz
yasm-1.2.0.tar.gz
zlib-1.2.8.tar.gz
1、 配置安装MYSQL
添加mysql用户
[root@51hhy ~]# useradd mysql -s /sbin/nologin
创建一个用于保存MySQL数据库程序和数据库文件的目录,并把该目录的所有者和所属组身份修改为mysql
[root@51hhy ~]# mkdir -p /usr/local/mysql/var
[root@51hhy ~]# chown -Rf mysql:mysql /usr/local/mysql/
[root@51hhy src]# tar -xzvf mysql-5.6.19.tar.gz
[root@51hhy src]# cd mysql-5.6.19/
[root@51hhy mysql-5.6.19]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/var \
-DSYSCONFDIR=/etc
[root@51hhy mysql-5.6.19]# make
[root@51hhy mysql-5.6.19]# make install
删除默认配置文件/etc/my.cnf然后在MySQL数据库程序的保存目录scripts内找到一个名为mysql_install_db的脚本程序,执行这个脚本程序并使用--user参数指定MySQL服务的对应账号名称(在前面步骤已经创建),使用--basedir参数指定MySQL服务程序的保存目录,使用--datadir参数指定MySQL真实数据库的文件保存目录,这样即可生成系统数据库文件,也会生成出新的MySQL服务配置文件。
[root@51hhy mysql]# ./scripts/mysql_install_db \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/var
[root@51hhy mysql]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf
把开机程序文件复制到/etc/rc.d/init.d目录中, 以便通过service命令来管理MySQL数据库服务程序,并把数据库脚本文件的权限修改成755以便于让用户有执行该脚本的权限
[root@51hhy mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@51hhy mysql]# chmod 755 /etc/rc.d/init.d/mysqld
编辑/etc/rc.d/init.d/mysqld 修改第46、47行的basedir与datadir参数分别修改为MySQL数据库程序的保存目录和真实数据库的文件内容。
chkconfig命令把mysqld服务程序加入到开机启动项中
[root@51hhy mysql]# service mysqld start
Starting MySQL. SUCCESS!
[root@51hhy mysql]# chkconfig mysqld on
修改环境变量/etc/profile
在文档74行左右添加:export PATH=$PATH:/usr/local/mysql/bin
立即生效
[root@51hhy mysql]# source /etc/profile
MySQL数据库服务程序还会调用到一些程序文件和函数库文件。由于当前是通过源码包方式安装MySQL数据库,因此现在也必须以手动方式把这些文件链接过来。
[root@51hhy mysql]# ln -s /usr/local/mysql/lib/ /usr/lib64/mysql/
[root@51hhy mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@51hhy mysql]# ln -s /usr/local/mysql/include/mysql/ /usr/include/mysql/
接下来对MySQL数据库进行初始化
[root@51hhy mysql]# mysql_secure_installation
2、 配置安装Nginx服务
l 安装pcre
[root@51hhy src]# tar xzvf pcre-8.35.tar.gz
[root@51hhy src]# cd pcre-8.35/
[root@51hhy pcre-8.35]# ./configure --prefix=/usr/local/pcre
[root@51hhy pcre-8.35]# make
[root@51hhy pcre-8.35]# make install
l 安装openssl
[root@51hhy src]# tar xzvf openssl-1.0.1h.tar.gz
[root@51hhy src]# cd openssl-1.0.1h/
[root@51hhy openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@51hhy openssl-1.0.1h]# make
[root@51hhy openssl-1.0.1h]# make install
修改环境变量/etc/profile
在文档74行左右添加:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
立即生效
[root@51hhy mysql]# source /etc/profile
l 安装zlib软件包
[root@51hhy src]# tar xzvf zlib-1.2.8.tar.gz
[root@51hhy src]# cd zlib-1.2.8/
[root@51hhy zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@51hhy zlib-1.2.8]# make
[root@51hhy zlib-1.2.8]# make install
l 安装Nginx
创建nginx用户
[root@51hhy nginx-1.6.0]# useradd www -s /sbin/nologin
在使用命令编译Nginx服务程序时,需要设置特别多的参数,其中,--prefix参数用于定义服务程序稍后安装到的位置,--user与--group参数用于指定执行Nginx服务程序的用户名和用户组。在使用参数调用openssl、zlib、pcre软件包时,请写出软件源码包的解压路径,而不是程序的安装路径
[root@51hhy nginx-1.6.0]#./configure \
--prefix=/usr/local/nginx \
--without-http_memcached_module \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-openssl=/usr/local/src/openssl-1.0.1h \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-pcre=/usr/local/src/pcre-8.35
[root@51hhy nginx-1.6.0]#make
[root@51hhy nginx-1.6.0]#make install
启动Nginx服务程序并将其加入到开机启动项中,编辑 vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@51hhy nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
[root@51hhy nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Reloading systemd: [ OK ]
Restarting nginx (via systemctl): [ OK ]
[root@51hhy nginx-1.6.0]# chkconfig nginx on
l 安装php服务
安装PHP依赖包
l 安装yasm
[root@51hhy src]# tar zxvf yasm-1.2.0.tar.gz
[root@51hhy src]# cd yasm-1.2.0/
[root@51hhy yasm-1.2.0]# ./configure
[root@51hhy yasm-1.2.0]# make
[root@51hhy yasm-1.2.0]# make install
l 安装libmcrypt
[root@51hhy src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@51hhy libmcrypt-2.5.8]# ./configure
[root@51hhy libmcrypt-2.5.8]# make
[root@51hhy libmcrypt-2.5.8]# make install
l 安装libvpx
[root@51hhy src]# tar xjvf libvpx-v1.3.0.tar.bz2
[root@51hhy src]# cd libvpx-v1.3.0/
[root@51hhy libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[root@51hhy libvpx-v1.3.0]# make
[root@51hhy libvpx-v1.3.0]# make install
l 安装tiff
[root@51hhy src]# tar zxvf tiff-4.0.3.tar.gz
[root@51hhy src]# cd tiff-4.0.3/
[root@51hhy tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[root@51hhy tiff-4.0.3]# make
[root@51hhy tiff-4.0.3]# make install
l 安装libpng
[root@51hhy src]# tar zxvf libpng-1.6.12.tar.gz
[root@51hhy src]# cd libpng-1.6.12/
[root@51hhy libpng-1.6.12]# ./configure --prefix=/usr/local/libpng --enable-shared
[root@51hhy libpng-1.6.12]# make
[root@51hhy libpng-1.6.12]# make install
l 安装freetype
[root@51hhy src]# tar zxvf freetype-2.5.3.tar.gz
[root@51hhy src]# cd freetype-2.5.3/
[root@51hhy freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared
[root@51hhy freetype-2.5.3]# make
[root@51hhy freetype-2.5.3]# make install
l 安装jpeg
[root@51hhy jpeg-9a]# tar zxvf jpegsrc.v9a.tar.gz
[root@51hhy src]# cd jpeg-9a/
[root@51hhy jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared
[root@51hhy jpeg-9a]# make
[root@51hhy jpeg-9a]# make install
l 安装libgd
[root@51hhy src]# cd libgd-2.1.0/
[root@51hhy libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
[root@51hhy libgd-2.1.0]# make
[root@51hhy libgd-2.1.0]# make install
l 安装t1lib
[root@51hhy src]# tar zxvf t1lib-5.1.2.tar.gz
[root@51hhy src]# cd t1lib-5.1.2/
[root@51hhy t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@51hhy t1lib-5.1.2]# make
[root@51hhy t1lib-5.1.2]# make install
[root@51hhy t1lib-5.1.2]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
[root@51hhy t1lib-5.1.2]# cp -frp /usr/lib64/libXpm.so* /usr/lib/
l 安装PHP
[root@51hhy src]# tar zxvf php-5.5.14.tar.gz
先定义一个名为LD_LIBRARY_PATH的全局环境变量
[root@51hhy php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@51hhy php-5.5.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --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 --enable-ctype -with-ldap
[root@51hhy php-5.5.14]# make
[root@51hhy php-5.5.14]# make install
[root@51hhy php-5.5.14]# cp /usr/local/src/php-5.5.14/php.ini-production /usr/local/php/etc/php.ini
[root@51hhy php-5.5.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@51hhy html]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
编辑php-fpm.conf 这里就不详细解说了
将PHP服务脚本写到开机启动项里
[root@51hhy php-5.5.14]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@51hhy php-5.5.14]# chmod 755 /etc/rc.d/init.d/php-fpm
[root@51hhy php-5.5.14]# chkconfig php-fpm on
修改/etc/php.ini 305左右
以上是关于zabbix学习笔记的主要内容,如果未能解决你的问题,请参考以下文章