zabbix安装配置扫雷记

操作系统:

Linux version 2.6.32-431.el6.x86_64([email protected]) (gcc version 4.4.7 20120313 (RedHat 4.4.7-4) (GCC) ) #1 SMP Sun Nov 10 22:19:54 EST 2013

IP地址:10.45.10.122

Web环境:Nginx+MySQL+PHP

zabbix版本:Zabbix2.2 LTS

备注:Linux下安装zabbix需要有LAMP或者LNMP运行环境


1、关闭firewall:

<span style="font-family:Microsoft YaHei;">#systemctlstop firewalld.service <span style="color:#3333ff;">#停止firewall</span>
#systemctldisable firewalld.service <span style="color:#3333ff;">#禁止firewall开机启动</span></span>


可以使用cat /proc/version命令查看当前需要配置服务器的版本,firewall是在7.0版本取代iptables。

Firewall的常用配置可以参考:http://www.2cto.com/Article/201503/384368.html

systemctl命令也是Linux新版本才出现的,这边用service命令。

chkconfig 命令可以查看所有服务状态。

 

2、iptables防火墙

# yuminstall iptables-services #公司的服务器一般都安装好了,可以跳过这个地方

# vi/etc/sysconfig/iptables-config #编辑防火墙配置文件,具体的内容根据自己需要配置

#Firewall configuration written by system-config-firewall

#Manual customization of this file is not recommended.

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

:wq! #保存退出

# systemctlrestart iptables.service #最后重启防火墙使配置生效

# systemctlenable iptables.service #设置防火墙开机启动

标准步骤是如上述所示,然并x,我们已经安装好了。所以应该是如下所示的样子。

1) 查看iptables当前的状态

#iptables -L -n  #首先查看iptables当前的状态

ChainINPUT (policy ACCEPT)
target       prot optsource                destination         

ChainFORWARD (policy ACCEPT)
target       prot optsource                destination         

ChainOUTPUT (policy ACCEPT)
target       prot optsource                destination         

ChainRH-Firewall-1-INPUT (0 references)
target       prot optsource                destination         

ACCEPT      all    --   0.0.0.0/0             0.0.0.0/0           
ACCEPT       icmp --   0.0.0.0/0             0.0.0.0/0            icmp type 255 
ACCEPT       esp   --    0.0.0.0/0             0.0.0.0/0           
ACCEPT       ah    --   0.0.0.0/0             0.0.0.0/0           
ACCEPT       udp   --   0.0.0.0/0             224.0.0.251           udpdpt:5353 
ACCEPT       udp   --   0.0.0.0/0             0.0.0.0/0            udp dpt:631 
ACCEPT       all   --   0.0.0.0/0             0.0.0.0/0            state RELATED,ESTABLISHED 
ACCEPT       tcp   --   0.0.0.0/0             0.0.0.0/0            state NEW tcp dpt:22 
ACCEPT       tcp   --   0.0.0.0/0             0.0.0.0/0            state NEW tcp dpt:80 
ACCEPT       tcp   --   0.0.0.0/0             0.0.0.0/0            state NEW tcp dpt:25 
REJECT       all   --   0.0.0.0/0             0.0.0.0/0            reject-with icmp-host-prohibited 

可以看出在安装的时候选择了有防火墙并且开房了22, 80, 25端口。

如果没有选择启用防火墙应该是这样的:

[root@hightest1~]# iptables -L -n

ChainINPUT (policy ACCEPT)
target     prot opt source               destination        

ChainFORWARD (policy ACCEPT)
target     prot opt source               destination        

ChainOUTPUT (policy ACCEPT)
target     prot opt source               destination   

2) 对没有规则的服务设定预设规则

这边都只是例子而已,根据自己实际情况进行配置。

采用命令的方式,只在当时生效,如果想要重起后也起作用,那就要保存!!!写入到/etc/sysconfig/iptables文件里。

# iptables-P INPUT DROP #注意是大写P

#iptables -P OUTPUT ACCEPT

# iptables-P FORWARD DROP

当超出了IPTABLES里filter表里的两个链规则(INPUT,FORWARD)时,不在这两个规则里的数据包怎么处理呢,那就是DROP(放弃)。应该说这样配置是很安全的,要控制流入数据包,而对于OUTPUT链,也就是流出的包不用做太多限制,采取ACCEPT。

3) 添加规则

首先添加INPUT链,INPUT链的默认规则是DROP,所以需要ACCETP的链。

#iptables -A INPUT -p tcp --dport 22 -j ACCEPT #为了能采用远程SSH登陆,开启22端口.

# iptables -A OUTPUT -ptcp --sport 22 -j ACCEPT #如果你把OUTPUT设置成DROP的就要写上

#其他的端口也一样,如果开启了web服务器,OUTPUT设置成DROP的话,同样也要添加一条链
# iptables -A OUTPUT -p tcp --sport 80 -jACCEPT

#如果做了WEB服务器,开启80端口
# iptables -A INPUT -p tcp --dport 80 -jACCEPT

#如果做了邮件服务器,开启25,110端口
# iptables -A INPUT -p tcp --dport 110 -j ACCEPT
# iptables -A INPUT -p tcp --dport 25 -j ACCEPT

#如果做了FTP服务器,开启21端口
# iptables -A INPUT -p tcp --dport 21 -jACCEPT

# iptables-A INPUT -p tcp --dport 20 -j ACCEPT

#如果做了DNS服务器,开启53端口

#iptables -A INPUT -p tcp --dport 53 -j ACCEPT

如果你还做了其他的服务器,需要开启哪个端口都按照上面的方式书写即可。

上面主要写的都是INPUT链,凡是不在上面的规则里的,都会DROP。

#允许icmp包通过,也就是允许ping
# iptables -A OUTPUT -p icmp -j ACCEPT #OUTPUT设置成DROP
# iptables -A INPUT -p icmp -jACCEPT   #INPUT设置成DROP的话

#允许loopback,不然会导致DNS无法正常关闭等问题
# iptables -A INPUT -i lo -p all -j ACCEPT  #INPUT DROP
# iptables -A OUTPUT -o lo -p all -j ACCEPT #OUTPUTDROP

下面写OUTPUT链,OUTPUT链默认规则是ACCEPT,所以需要DROP的链,减少不安全的端口连接。

# iptables-A OUTPUT -p tcp --sport 31337 -j DROP

#iptables -A OUTPUT -p tcp --dport 31337 -j DROP

有些特洛伊木马会扫描端口31337到31340(即黑客语言中的 elite 端口)上的服务。既然合法服务都不使用这些非标准端口来通信,阻塞这些端口能够有效地减少网络可能被感染的机器和它们的远程主服务器进行独立通信的机会。

还有其他端口也一样:31335、27444、27665、20034 NetBus、9704、137-139(smb),2049(NFS)端口也应被禁止,相应的写法。

4) 另外查了一下资料关于这个dport和sport的含义。

① 先来翻译一下dport和sport的意思: dport:目的端口 ;sport:来源端口 

dport 和sport字面意思来说很好理解,一个是数据要到达的目的端口,一个是数据来源的端口。 

② 但是在使用的时候要分具体情况来对待,这个具体情况就是数据包的流动行为方式.

e.g.:/sbin/iptables-A INPUT -p tcp --dport 80 -j ACCEPT 

l  这是一条从外部进入内部本地服务器的数据。 

l  数据包的目的(dport)地址是80,就是要访问本地的80端口。 

l  允许以上的数据行为通过。 

综上所述:允许外部数据访问本地服务器80端口。 

 

e.g.:/sbin/iptables-A INPUT -p tcp --sport 80 -j ACCEPT 

l  这是一条从外部进入内部本地服务器的数据。 

l  数据包的来源端口是(sport)80,就是对方的数据包是80端口发送过来的。 

l  允许以上数据行为。 

综上所述:允许外部的来自80端口的数据访问本地服务器。 

input方式总结: dport指本地,sport指外部。 

 

如果数据包是OUTPUT行为,那么就是另外一种理解方式: 

e.g.:/sbin/iptables-A OUTPUT -p tcp --dport 80 -j ACCEPT 

l  这是一条从内部出去的数据。 

l  出去的目的(dport)端口是80。 

l  允许以上数据行为。 

综上所述:允许内部数据访问外部服务器80端口。

output行为总结:dport指外部,sport指本地。 

iptables 所在目录/etc/sysconfig/iptables

5)其他命令

# serviceiptables status #查看iptables状态

# serviceiptables restart #iptables服务重启

# serviceiptables stop iptables #服务停止

再强调一遍:采用命令的方式,只在当时生效,如果想要重起后也起作用,那就要保存!!!写入到/etc/sysconfig/iptables文件里。

命令输完之后查看状态,它长这个样子。

重启之后它长这个样子。

也可以输入完上述命令之后敲如下命令

# /etc/rc.d/init.d/iptables save

千万不要干一件鱼唇的事情,好奇心害死猫:

# iptables-P INPUT DROP

# /etc/rc.d/init.d/iptables save

 

3、关闭SELINUX

# vi/etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

# setenforce0 #使配置立即生效

 

4、安装准备

① 源码编译安装下载包

根据自己当前服务器选择合适的包

Mysql(5.7.10): http://dev.mysql.com/downloads/mysql/

Nginx: http://nginx.org/download/nginx-1.8.0.tar.gz

php: http://php.net/get/php-5.6.16.tar.gz/from/a/mirror

pcre (支持nginx伪静态):
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz

openssl(nginx扩展): http://www.openssl.org/source/openssl-1.0.2e.tar.gz

zlib(nginx扩展):http://zlib.net/zlib-1.2.8.tar.gz

cmake(MySQL编译工具): https://cmake.org/files/v3.4/cmake-3.4.1-Linux-x86_64.tar.gz

libmcrypt(php扩展):
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

yasm(php扩展):http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

t1lib(php扩展): 使用wgetftp://sunsite.unc.edu/pub/linux/libs/graphics/t1lib-5.1.2.tar.gz

(ftp连接不上,下载了如下连接的rpm)

http://rpm.pbone.net/index.php3/stat/4/idpl/5786767/dir/centos_5/com/t1lib-5.1.0-9.el5.kb.x86_64.rpm.html

gd库安装包: https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

libvpx(gd库需要):
http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.5.0.tar.bz2(这个版本和1.4.0版本都需要打补丁)

补丁:

tiff(gd库需要): http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

libpng(gd库需要):
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.20.tar.g

freetype(gd库需要):
http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.3.tar.gz

jpegsrc(gd库需要): http://www.ijg.org/files/jpegsrc.v9a.tar.gz

以上软件包使用lrzsz工具上传到/usr/local/src目录

lrzsz安装:yum install lrzsz

② 安装编译工具及库文件(使用yum命令安装)

yum install -y apr* autoconf automake bisonbzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-develfreetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettextgettext-devel glibc kernel kernel-headers keyutils keyutils-libs-develkrb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devellibselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm*libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-develperl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wgetzlib-devel

③ 约定:

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字

 

5、安装MySQL

1)rpm包安装

# yum list mysql  #默认可能不是新版

Loaded plugins: product-id, security, subscription-manager

This system is not registered to Red Hat SubscriptionManagement. You can use subscription-manager to register.

Available Packages

mysql.x86_64                                                               5.1.71-1.el6

#mysql官网上下载的rpm包三种安装

# yum install mysql-server 

# apt-get install mysql-server

# rpm -ivh --prefix=/usr/local/mysql mysql-community-server-5.7.10-1.el6.x86_64.rpm--nodeps --root=/usr/local/mysql
#-i :安装的意思
#-v 
:可视化
#-h :显示安装进度
#--force 强制安装,即使覆盖属于其他包的文件也要安装
#--nodeps 当要安装的rpm包依赖其他包时,即使其他包没有安装,也要安装这个包

#服务器已经安装过mysql,可能会报错

error: Failed dependencies: MySQL conflicts withmysql-version

#说明系统中原本装有mysql,需要先删除。

#通过以下命令查找已经安装的mysql

# rpm -qa|grep -i mysql

 #在列出的包中,用以下命令删除mysql-server-version和mysql-client-version等,重新安装即可

 # rpm -e --nodeps mysql-server-version

# 安装的时候不允许指定路径安装,使用--prefix参数指定目录,会报错:package MySQL-server is not relocatable。

# rpm安装的时候要提前安装
# mysql-community-devel-5.7.10-1.el6.x86_64.rpm
# mysql-community-common-5.7.10-1.el6.x86_64.rpm
# mysql-community-client-5.7.10-1.el6.x86_64.rpm

#安装好了,查看安装的路径

[root@hightest1 bin]# rpm -qa|grep -i mysql

mysql-community-client-5.7.10-1.el6.x86_64
mysql-community-common-5.7.10-1.el6.x86_64
mysql-community-server-5.7.10-1.el6.x86_64
mysql-community-devel-5.7.10-1.el6.x86_64

# rpm -ql mysql-community-client-5.7.10-1.el6.x86_64 #查找安装位置

/usr/bin/mysql
/usr/bin/mysql_config
/usr/bin/mysql_config-64
/usr/bin/mysql_config_editor
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlpump

/usr/bin/mysqlshow
/usr/bin/mysqlslap
/usr/share/doc/mysql-community-client-5.7.10
/usr/share/doc/mysql-community-client-5.7.10/COPYING
/usr/share/doc/mysql-community-client-5.7.10/README
/usr/share/man/man1/mysql.1.gz
/usr/share/man/man1/mysql_config_editor.1.gz
/usr/share/man/man1/mysqladmin.1.gz
/usr/share/man/man1/mysqlbinlog.1.gz
/usr/share/man/man1/mysqlcheck.1.gz
/usr/share/man/man1/mysqldump.1.gz
/usr/share/man/man1/mysqlimport.1.gz
/usr/share/man/man1/mysqlpump.1.gz
/usr/share/man/man1/mysqlshow.1.gz
/usr/share/man/man1/mysqlslap.1.gz

关于yuminstall可以安装位置可以查看其配置

# whereis yum

yum: /usr/bin/yum /etc/yum /etc/yum.conf/usr/share/man/man8/yum.8.gz

# cat /etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever

keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

#  This is the default, if you make thisbigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of nothaving to
# download the new metadata and "pay" for it by yum not havingcorrect
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

# cd /var/cache/yum/

# ll -a

total 36
drwxr-xr-x.  9 root root 4096 Dec 1022:18 .
drwxr-xr-x. 11 root root 4096 Jan  610:50 ..
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-1
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-2
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-3
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-4
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-5
drwxr-xr-x.  3 root root 4096 Dec 1022:17 source-6
drwxr-xr-x.  3 root root 4096 Dec 10 22:18x86_64

# cd x86_64/

# ll

total 4
drwxr-xr-x. 11 root root 4096 Jan  610:10 6Server

# cd 6Server/

# ll -a

total 44
drwxr-xr-x. 11 root root 4096 Jan  610:10 .
drwxr-xr-x.  3 root root 4096 Dec 1022:18 ..
drwxr-xr-x   3root root 4096 Jan 12 14:13 mysql-community-client-5.7.10-2.el6.x86_64.rpm                                                                                       
drwxr-xr-x   3 root root 4096 Jan 1214:13 mysql-community-server-5.7.10-2.el6.x86_64.rpm

2)源码安装

① 安装cmake

# cd /usr/local/src #公司服务器已经安装了cmake,跳过

# tar zxvf cmake-3.4.1-Linux-x86_64.tar.gz

# cd cmake-3.4.1-Linux-x86_64

# ./configure

# make

# make install

② 安装MySQL

# groupadd mysql #添加mysql组

# useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统

# mkdir -p /Data/mysql #创建MySQL数据库存放目录

# chown -R mysql:mysql /Data/mysql #设置MySQL数据库存放目录权限

# mkdir -p /usr/local/mysql #创建MySQL安装目录

# cd /usr/local/src #进入软件包存放目录

# 下载的是tar.gz

# tar zxvf mysql-5.7.10.tar.gz #解压

# cd mysql-5.7.10 #进入目录

#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/Data/mysql-DSYSCONFDIR=/etc #配置

#make #编译

#make install #安装

#rm -rf /etc/my.cnf #删除系统默认的配置文件(如果默认没有就不用删除)

#cd /usr/local/mysql #进入MySQL安装目录

# ./scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/Data/mysql #生成mysql系统数据库

# ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接

# cp ./support-files/mysql.server/etc/rc.d/init.d/mysqld #把Mysql加入系统启动

# chmod 755 /etc/init.d/mysqld #增加执行权限

# chkconfig mysqld on #加入开机启动

# vi /etc/rc.d/init.d/mysqld #编辑

basedir=/usr/local/mysql #MySQL程序安装路径

datadir=/Data/mysql #MySQl数据库存放目录

:wq! #保存退出

# service mysqld start #启动

# vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行

export PATH=$PATH:/usr/local/mysql/bin

:wq! #保存退出

# source /etc/profile  #使配置立刻生效

下面这两行把myslq的库文件链接到系统默认的位置,这样在编译类似PHP等软件时可以不用指定mysql的库文件地址。

# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

# ln -s /usr/local/mysql/include/mysql /usr/include/mysql

# mkdir /var/lib/mysql #创建目录

# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接

# mysql_secure_installation #设置Mysql密码,根据提示按Y 回车输入2次密码

6、安装Nginx

1)安装pcre

# cd /usr/local/src

# mkdir /usr/local/pcre

# tar zxvf pcre-8.38.tar.gz

# cd pcre-8.38

# ./configure --prefix=/usr/local/pcre

# make

# make install

2)安装openssl

# cd /usr/local/src

# mkdir /usr/local/openssl

# tar zxvf openssl-1.0.2e.tar.gz

# cd openssl-1.0.2e

# ./config --prefix=/usr/local/openssl

# make

# make install

# vi /etc/profile

# export PATH=$PATH:/usr/local/openssl/bin

# :wq!

# source /etc/profile #使/etc/profile里的配置立即生效

3)安装zlib

# cd /usr/local/src

# mkdir /usr/local/zlib

# tar zxvf zlib-1.2.8.tar.gz

# cd zlib-1.2.8

# ./configure --prefix=/usr/local/zlib

# make

# make install

4)安装Nginx

# groupaddwww

# useradd-g www www -s /bin/false

# cd/usr/local/src

# tarzxvf nginx-1.8.0.tar.gz

# cdnginx-1.8.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.2e--with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.38

#注意
#--with-openssl=/usr/local/src/openssl-1.0.2e
#--with-zlib=/usr/local/src/zlib-1.2.8
#--with-pcre=/usr/local/src/pcre-8.38
指向的是源码包解压的路径,而不是安装路径

# make

# makeinstall

# /usr/local/nginx/sbin/nginx #启动Nginx

#设置nginx开机启动

# vi/etc/rc.d/init.d/nginx  #编辑启动文件添加下面内容

#!/bin/sh

#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(){

# makerequired directories

user=`$nginx-V 2>&1 | grep "configure arguments:" | sed's/[^*]*--user=\([^ ]*\).*/\1/g' -`

if [-z "`grep $user /etc/passwd`" ];

thenuseradd-M -s /bin/nologin $user

fi

options=`$nginx-V 2>&1 | grep 'configure arguments:'`

foropt 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

sleep1

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

:wq! #保存退出

#chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限

#chkconfig nginx on #设置开机启动

# /etc/rc.d/init.d/nginxrestart #重启

在浏览器中打开服务器IP地址,会看到“Welcome to nginx!”界面,说明Nginx安装成功。

7、安装php

1)安装yasm

# cd /usr/local/src

# tar zxvf yasm-1.3.0.tar.gz

# cd yasm-1.3.0

# ./configure

# make

# make install

2)安装libmcrypt

# cd /usr/local/src

# tar zxvf libmcrypt-2.5.7.tar.gz

# cd libmcrypt-2.5.7

# ./configure

# make

# make install

3)安装libvpx

# cd /usr/local/src

# tar xvf libvpx-v1.5.0.tar.bz2

# cd libvpx-v1.5.0

# mkdir /usr/local/libvpx

# ./configure --prefix=/usr/local/libvpx --enable-shared--enable-vp9

#libvpx安装的时候报“nasm OR yasm not found”的错误,那是因为安装yasm的时候配置到其他文
#件夹中

# make

# make install

4)安装tiff

# cd /usr/local/src

# tar zxvf tiff-4.0.3.tar.gz

# cd tiff-4.0.3

# ./configure --prefix=/usr/local/tiff --enable-shared

# make

# make install

5)安装libpng

# cd /usr/local/src

# tar zxvf libpng-1.6.12.tar.gz

# cd libpng-1.6.12

# mkdir /usr/local/libpng

# ./configure --prefix=/usr/local/libpng --enable-shared

# make

# make install

6)安装freetype

# cd /usr/local/src

# tar zxvf freetype-2.5.3.tar.gz

# cd freetype-2.5.3

# mkdir /usr/local/freetype

# ./configure --prefix=/usr/local/freetype --enable-shared

# make

# make install

7)安装jpeg

# cd /usr/local/src

# tar zxvf jpegsrc.v9a.tar.gz

# cd jpeg-9a

# mkdir /usr/local/jpeg

# ./configure --prefix=/usr/local/jpeg --enable-shared

# make 

# make install 

8)安装libgd

# cd /usr/local/src

# tar zxvf libgd-2.1.0.tar.gz 

# cd 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 

# make 

#报错:

/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:In function ‘VPXEncode’:
/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:709:24: error: ‘IMG_FMT_I420’undeclared (first use in this function)
vpx_img_wrap(&img, IMG_FMT_I420,
^
/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:709:24: note: each undeclaredidentifier is reported only once for each function it appears in
/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:711:16: error: ‘PLANE_Y’undeclared (first use in this function)
img.planes[PLANE_Y] = (uint8*)(Y);
^
/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:712:16: error: ‘PLANE_U’undeclared (first use in this function)
img.planes[PLANE_U] = (uint8*)(U);
^
/user/loca/src/php-5.6.16/ext/gd/libgd/webpimg.c:713:16: error: ‘PLANE_V’undeclared (first use in this function)
img.planes[PLANE_V] = (uint8*)(V);
^
Makefile:842: recipe for target 'ext/gd/libgd/webpimg.lo' failed
make: *** [ext/gd/libgd/webpimg.lo] Error 1
make: *** Waiting for unfinished jobs....

#上传补丁并且用patch命令

# patch -p1 < php-gd-newvpx.diff.patch.txt

can't find file to patch at input line 4

Perhaps you used the wrong -p or --strip option?

The text leading up to this was:

--------------------------

|diff -urN php-5.6.16.org/ext/gd/libgd/webpimg.cphp-5.5.24/ext/gd/libgd/webpimg.c

|--- php-5.6.16.org/ext/gd/libgd/webpimg.c      2015-04-15 13:43:00.000000000 +0300

|+++ php-5.6.16/ext/gd/libgd/webpimg.c  2015-04-18 11:46:36.247244985 +0300

--------------------------

File to patch: /usr/local/src/libgd-2.1.0/src/webpimg.c  #这个路径需要find -name webpimg.c

patching file /usr/local/src/libgd-2.1.0/src/webpimg.c

Hunk #1 succeeded at 711 (offset 5 lines).

# make #重新编译

# make install 

9)安装t1lib

# cd /usr/local/src

# tar zxvf t1lib-5.1.2.tar.gz  #然而并没有下载到这种格式的

# rpm2cpio t1lib-5.1.0-9.el5.kb.src.rpm  |cpio –id #得到压缩包t1lib-5.1.0.tar.gz和一些补丁

# tar zxvf t1lib-5.1.0.tar.gz

# cd t1lib-5.1.0

# ./configure --prefix=/usr/local/t1lib --enable-shared

# make without_doc

# make install

 

10)安装php

#注意:如果系统是64位,请执行以下两条命令,否则安装php会出错(32位系统不需要执行)

# \cp-frp /usr/lib64/libltdl.so*  /usr/lib/

# \cp-frp /usr/lib64/libXpm.so* /usr/lib/

# cd/usr/local/src

# tar-zvxf php-5.6.16.tar.gz

# cdphp-5.6.16

# exportLD_LIBRARY_PATH=/usr/local/libgd/lib

# ./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   #配置,注意修改成对应的路径即可

# make #编译

# makeinstall   #安装

# cpphp.ini-production /usr/local/php/etc/php.ini  #复制php配置文件到安装目录

# rm-rf /etc/php.ini  #删除系统自带配置文件

# ln-s /usr/local/php/etc/php.ini /etc/php.ini   #添加软链接到 /etc目录

# cp/usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf  #拷贝模板文件为php-fpm配置文件

# ln-s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf  #添加软连接到 /etc目录

# vi/usr/local/php/etc/php-fpm.conf #编辑

user =www #设置php-fpm运行账号为www

group= www #设置php-fpm运行组为www

pid =run/php-fpm.pid #取消前面的分号

:wq! #保存退出

#设置 php-fpm开机启动

# cp/usr/local/src/php-5.6.16/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录

# chmod+x /etc/rc.d/init.d/php-fpm #添加执行权限

# chkconfigphp-fpm on #设置开机启动

# vi/usr/local/php/etc/php.ini #编辑配置文件

disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

date.timezone= PRC #设置时区

expose_php= Off #禁止显示php版本的信息

short_open_tag= On #支持php短标签

opcache.enable=1 #php支持opcode缓存

opcache.enable_cli= 0#php支持opcode缓存

zend_extension=opcache.so #开启opcode缓存功能

:wq! #保存退出

#配置nginx支持php

# vi/usr/local/nginx/conf/nginx.conf

userwww www; #首行user去掉注释,修改Nginx运行组为wwwwww

#必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错

indexindex.html index.htm index.php; #添加index.php

# passthe PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location~ \.php$ {

roothtml;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;

includefastcgi_params;

}

#取消FastCGI server部分location的注释

#注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径

# /etc/init.d/nginxrestart #重启nginx

# servicephp-fpm start #启动php-fpm

#可能会报错:ERROR: unable to bindlistening socket for address '127.0.0.1:9000': Address already in use (98)

#killall php-fpm

# servicephp-fpm start

 

8、测试

# cd/usr/local/nginx/html/ #进入nginx默认网站根目录

# rm-rf /usr/local/nginx/html/* #删除默认测试页

# viindex.php #新建index.php文件

<?php
phpinfo();
?>

:wq! #保存退出

# chownwww.www /usr/local/nginx/html/ -R #设置目录所有者

# chmod700 /usr/local/nginx/html/ -R #设置目录权限

在浏览器中打开服务器IP地址,会看到下面的界面:

 

9、安装zabbix

从官网上下载安装包:zabbix-2.2.2.tar.gz ,同上述安装相似。

1)创建、导入zabbix数据库

# cd/usr/local/src #进入软件包下载目录

# tarzxvf zabbix-2.2.2.tar.gz #解压

# cd/usr/local/src/zabbix-2.2.2/database/mysql #进入mysql数据库创建脚本目录

# ls #列出文件,可以看到有schema.sql、images.sql、data.sql这三个文件

# mysql-u root -p #输入密码,进入MySQL控制台

>createdatabase zabbix character set utf8; #创建数据库zabbix,并且数据库编码使用utf8

> createuser 'zabbix'@'127.0.0.1';

> update mysql.user set Password=password('zabbix')where user='zabbix'; #修改密码

>flushprivileges; #刷新系统授权表

>grantall on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix' with grantoption; #允许账户zabbix能从本机连接到数据库zabbix

>flushprivileges; #再次刷新系统授权表

>usezabbix #进入数据库

source/usr/local/src/zabbix-2.2.2/database/mysql/schema.sql #导入脚本文件到zabbix数据库

source/usr/local/src/zabbix-2.2.2/database/mysql/images.sql #导入脚本文件到zabbix数据库

source/usr/local/src/zabbix-2.2.2/database/mysql/data.sql #导入脚本文件到zabbix数据库

#注意:请按照以上顺序进行导入,否则会出错。

>exit 

# cd/usr/lib64/mysql #32位系统为/usr/lib/mysql,注意系统版本,文件版本可能不一样,这里是16.0.0

# ln-s libmysqlclient.so.16.0.0 libmysqlclient.so #添加软连接

# ln-s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so #添加软连接

2)安装zabbix

#添加用户

# groupaddzabbix #创建用户组zabbix

# useraddzabbix -g zabbix -s /bin/false #创建用户zabbix,并且把用户zabbix加入到用户组zabbix中

# yuminstall net-snmp-devel curl curl-devel mysql-devel #安装依赖包 

#安装zabbix

# ln-s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2 #添加软连接

# /sbin/ldconfig #使配置立即生效

# cd /usr/local/src/zabbix-2.2.2 #进入安装目录

#mkdir/usr/local/zabbix

# ./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp--with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config

# make

# makeinstall 

# ln-s /usr/local/zabbix/sbin/* /usr/local/sbin/ #添加系统软连接

# ln-s /usr/local/zabbix/bin/* /usr/local/bin/ #添加系统软连接

#添加zabbix服务对应的端口

# vi/etc/services 

#Zabbix

zabbix-agent10050/tcp # Zabbix Agent

zabbix-agent10050/udp # Zabbix Agent

zabbix-trapper10051/tcp # Zabbix Trapper

zabbix-trapper10051/udp # Zabbix Trapper

:wq!

#修改zabbix配置文件

# cd/usr/local/zabbix/etc

# vi/usr/local/zabbix/etc/zabbix_server.conf

DBName=zabbix #数据库名称

DBUser=zabbix #数据库用户名

DBPassword=zabbix #数据库密码

ListenIP=127.0.0.1  #不能改,默认的local address即可

#0.0.0.0 表示监听本地所有ip地址,其他电脑是可以访问的,并且修改ip不受影响。
#127.0.0.1 表示只监听本机回环地址,只能本机访问。
#x.x.x.x ip地址,是只监听这个ip。修改ip后程序就不能监听了。需要手动修改软件监听地址才可以用

 

AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录

:wq! #保存退出

# vi/usr/local/zabbix/etc/zabbix_agentd.conf

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

UnsafeUserParameters=1 #启用自定义key

:wq! 

#添加开机启动脚本

# cp/usr/local/src/zabbix-2.2.2/misc/init.d/fedora/core/zabbix_server/etc/rc.d/init.d/zabbix_server #服务端

# cp /usr/local/src/zabbix-2.2.2/misc/init.d/fedora/core/zabbix_agentd/etc/rc.d/init.d/zabbix_agentd #客户端

# chmod+x /etc/rc.d/init.d/zabbix_server #添加脚本执行权限

# chmod+x /etc/rc.d/init.d/zabbix_agentd #添加脚本执行权限

# chkconfigzabbix_server on #添加开机启动

# chkconfigzabbix_agentd on #添加开机启动

#修改zabbix开机启动脚本中的zabbix安装目录

vi/etc/rc.d/init.d/zabbix_server #编辑服务端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录

:wq! #保存退出

vi/etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录

:wq! #保存退出

# 配置web站点

# cd/usr/local/src/zabbix-2.2.2

# cp-r /usr/local/src/zabbix-2.2.2/frontends/php /usr/local/nginx/html/zabbix

# chownwww.www -R /usr/local/nginx/html/zabbix

#/usr/local/nginx/html为Nginx默认站点目录 www为Nginx运行账户

# servicezabbix_server start #启动zabbix服务端

# servicezabbix_agentd start #启动zabbix客户端

#修改php配置文件参数

# vi/etc/php.ini 

post_max_size=16M

max_execution_time=300

max_input_time=300

:wq! 

# vi/usr/local/php/etc/php-fpm.conf 

request_terminate_timeout= 300

:wq!

# servicephp-fpm reload #重启php-fpm

 

10、配置web

1)浏览器输入:http://10.45.10.122/zabbix/setup.php#

 点击“Next”,检查环境变量是否全部配置完成。

 

点击“Next”,输入必填项,点击“Test”,进行测试。

 

测试通过之后,点击“Next”,输入host IP,再次点击“Next”。

 

 

 安装完成。

2)修改配置

① 更改zabbix默认语言为简体中文、替换监控图像上系统默认的中文字体

#修改系统配置文件,让web页面支持简体中文显示

# vi/usr/local/nginx/html/zabbix/include/locales.inc.php 

'zh_CN' => array('name' => _('Chinese(zh_CN)'),        'display' => true),

:wq! #保存退出

#替换监控图像上系统默认的字体 

#默认字体不支持中文,如果不替换,图像上会显示乱码

在Windows系统中的C:\Windows\Fonts目录中复制出一个中文字体文件,例如msyh.ttf

把字体文件msyh.ttf上传到zabbix站点根目录下fonts文件夹中

例如:/usr/local/nginx/html/zabbix/fonts

备份默认的字体文件:DejaVusSans.ttf-bak

修改msyh.ttf名称为DejaVusSans.ttf

3)在浏览器中打开:

http://192.168.21.127/zabbix

发现出现如图所示的问题:

需要依次检查:

ü   检查系统是否安装apache,以便解析html;

ü   php没有完全安装好;

ü   apache没有提供对php的支持;

ü   apache的配置文件中DocumentRoot的参数值没有改成zabbix的路径,zabbix默认的路径是“/var/www/html/”下。

前面两者检查后无误,主要是第三个原因,解决方式如下所示:

#vi /usr/local/apache/conf/httpd.conf #修改apache配置文件中的参数

DirectoryIndex index.html index.php
AddType application/x-httpd-php .php .php3 .php4

:wq

# apachectl graceful

#重启的时候报错:

httpd: apr_sockaddr_info_get()failed for hightest1.800best.com

httpd: Could not reliablydetermine the server's fully qualified domain name, using 127.0.0.1 forServerName

#原因是没有在/etc/httpd/conf/httpd.conf 中设定 ServerName。所以apache会用主机上的名称来
#取代,首先会去找 /etc/hosts 中有没有主机的定义。

#解决办法一:

#vi httpd.conf

ServerNamelocalhost:80

:wq!

#解决方式二:

# vi /etc/hosts

127.0.0.1   hightest1 #填入主机名

:wq!

# apachectlgraceful #重启

#可能会遇到这种报错:

(98)Addressalready in use: make_sock: could not bind to address [::]:80

(98)Addressalready in use: make_sock: could not bind to address 0.0.0.0:80

nolistening sockets available, shutting down

Unableto open logs

#是有进程占用了80端口

# netstat -tulnp | grep ':80 '
#找到对应的PID kill,或者修改apache的端口

#页面上红字报错:

ini_set(): Use of mbstring.internal_encoding is deprecated [dashboard.php:21 → require_once() → ZBase->run() → ZBase>initLocales() → init_mbstrings() → ini_set() in /usr/local/nginx/html/zabbix/include/locales.inc.php:25]

#将/usr/local/nginx/html/zabbix/include/locales.inc.php中第25行注释掉即可

scandir()has been disabled for security reasons [profile.php:193 → CView->render() → include()→ getSounds() → scandir() in/usr/local/nginx/html/zabbix/include/sounds.inc.php:24]

#这种报错可能是在配置php的时候将功能禁止掉了,只要在/usr/local/php/etc/php.ini中的
#disable_functions = 后的函数中去掉上述scandir,然后重启php-fpm。

 

点击界面右上角的“profile”,修改语言为“Chinese (zh_CN)”,点击“save”,界面就会显示中文。

#目前报错:zabbix server is not running.

# selinux是否关闭。

# /usr/sbin/sestatus -v

SELinux status:                 disabled

#关闭SELinux的方法:

# vi /etc/selinux/config

SELINUX=disabled

:wq!

#重启系统

# setenforce 0 #不想重启系统

#setenforce 1 设置SELinux 成为enforcing模式
#setenforce 0 设置SELinux 成为permissive模式 
#在lilo或者grub的启动参数中增加:selinux=0,也可以关闭selinux

 

#zabbix web目录下面  $ZBX_SERVER 是否为ip

# vi./usr/local/nginx/html/zabbix/conf/zabbix.conf.php

$ZBX_SERVER      = '10.45.10.122';

#如果是localhost,ping下localhost是否能解析。如果不能,需要在/etc/hosts文件里增加相应的项目

 

#查看php的fsockopen模块是否启用。

#方法一:

# vi /usr/local/php/etc/php.ini

allow_url_fopen = On

extension=php_openssl.dll

:wq!

# apachectl graceful #对本次没什么用,本身参数就是开启的,php-fpm重启还会报错:php_openssl.dll not found

#方法二

# vi php.ini

allow_url_fopen = On

:wq!

#编译openssl

# cd /usr/local/src/php-5.6.16/ext/openssl

# ./configure –with-openssl –with-php-config=/usr/local/bin/php-config

# make 

# make install

# cp openssl.so  /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

#make install之后会有提示需要复制的目的路径

# vi php.ini

extension=openssl.so

:wq!

# apachectl graceful

 

# /usr/local/php/bin/phpize

#这边可能会报错

Cannot find config.m4.

Make sure that you run /usr/local/bin/phpize inthe top level source directory of the module.

# /usr/local/src/php-5.6.16/ext

# ./ext_skel --extname=openssl

Creating directory openssl

Creating basic files: config.m4 .cvsignore sdomain.cphp_sdomain.h CREDITS EXPERIMENTAL tests/001.phpt openssl.php [done].

To use your new extension, you will have to execute thefollowing steps:

  1. $ cd ..

  2. $ vi ext/openssl/config.m4

  3. $ ./buildconf

  4. $ ./configure --[with|enable]-openssl

  5. $ make

  6. $ ./php -f ext/openssl/openssl.php

  7. $ vi ext/openssl/openssl.c

  8. $ make

  Repeat steps 3-6 until you are satisfied with ext/openssl/config.m4and

  step 6 confirms that your module is compiled into PHP. Then, startwriting

  code and repeat the last two steps as often as necessary.

# cd openssl/

# ls

config.m4 EXPERIMENTALopenssl.php tests CREDITS  openssl.c php_openssl.h

# 按照提示,要修改文件顺序是configue.m4、openssl.c、php_openssl.h

# vi config.m4

PHP_ARG_WITH(my_module, for my_module support,

[ --with-my_module Include my_module support])

# 或者修改

PHP_ARG_ENABLE(my_module, whether to enable my_modulesupport,

[ --enable-my_module Enable my_module support])

# 将这部分的dnl去掉,在这个文件里dnl就是注释的意思,相当于PHP里面的#或//

:wq!

#vi openssl.c

/* Every user visible function must have an entry inmy_module_functions[].
*/
function_entry my_module_functions[] = {
    PHP_FE(say_hello,    NULL)  /* For testing,remove later. */
    PHP_FE(confirm_my_module_compiled,   NULL) /* For testing, remove later. */
    {NULL, NULL, NULL}   /*Must be the last line in my_module_functions[] */
};

# 在文件的最后添加下列代码  /* For testing, remove later. */

PHP_FUNCTION(say_hello)
{
    zend_printf("hellosdomain!");
}

# vi php_openssl.h

PHP_FUNCTION(confirm_my_module_compiled ); /* For testing, remove later. */

PHP_FUNCTION(say_hello); /* For testing,remove later. */

:wq!

# /usr/local/php/bin/phpize

  Configuring for:

  PHP Api Version:     20020918

  Zend Module Api No:   20020429

  Zend Extension Api No:  20050606

# ./configure --with-openssl=/usr/local/openssl\

--with-php-config=/usr/local/php/bin/php-config

# make

# make install #后面的步骤和之前所述相同

上述的方式都没有什么大的用处,查看/tmp/zabbix_server.log,发现一个报错:

20160114:115118.610 [Z3005] queryfailed: [2006] MySQL server has gone away [select hostid,status from hostswhere host='Zabbix server' and status in (0,1) and flags<>2 andproxy_hostid is null]

查找了一下资料,发现这个是zabbix 2.2版本的一个bug,在2.5版本中才解决。

#vim src/libs/zbxdb/db.c

int    zbx_db_connect(char *host, char *user, char*password, char *dbname, char *dbschema, char *dbsocket, int port)

{
      int   ret = ZBX_DB_OK, last_txn_error,last_txn_level;
#if defined(HAVE_IBM_DB2)
      char  *connect = NULL;

#elifdefined(HAVE_MYSQL)
my_bool mysql_reconnect = 1;

#elif defined(HAVE_ORACLE)
      char   *connect = NULL;
      sword err = OCI_SUCCESS;

 

#elif defined(HAVE_MYSQL)
    conn = mysql_init(NULL);

    if (NULL == mysql_real_connect(conn, host, user, password,dbname, port, dbsocket, CLIENT_MULTI_STATEMENTS))
    {
            zabbix_errlog(ERR_Z3001, dbname,mysql_errno(conn), mysql_error(conn));
            ret = ZBX_DB_FAIL;

}

 

    if (0 != mysql_options(conn,MYSQL_OPT_RECONNECT, &mysql_reconnect))
             zabbix_log(LOG_LEVEL_WARNING, "Cannotset MySQL reconnect option.");

                                                           
    if (ZBX_DB_OK == ret && 0 != mysql_select_db(conn,dbname))
    {
            zabbix_errlog(ERR_Z3001, dbname,mysql_errno(conn), mysql_error(conn));
            ret = ZBX_DB_FAIL;

}

:wq!

# cd/usr/local/src/zabbix-2.2.2 

# ./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp--with-libcurl -with-libxml2 --enable-proxy--with-mysql=/usr/bin/mysql_config

# make

# makeinstall 

 

#查看zabbix_server.log

cannot send list of active checks to[127.0.0.1]: host [Zabbix server] not found

#vi/usr/local/zabbix/etc/zabbix_agentd.conf

Server=127.0.0.1

Hostname=10.45.10.122#和配置的hostname相同

ListenIP=127.0.0.1

Timeout=30

PidFile=/tmp/zabbix_agentd.pid

LogFile=/tmp/zabbix_agentd.log

:wq!

#servicezabbix_agentd restart


最终还是没有用(ㄒoㄒ),求助了IT发现是因为/usr/local/zabbix/etc/zabbix_server.conf配置了ListenIP为127.0.0.1导致的,修改为默认的0.0.0.0就可以了。

0.0.0.0 表示监听本地所有ip地址,其他电脑是可以访问的,并且修改ip不受影响。

127.0.0.1 表示只监听本机回环地址,只能本机访问。

x.x.x.x ip地址,是只监听这个ip。

 

 

参考链接:

http://www.osyunwei.com/archives/7984.html

http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html

http://www.2cto.com/os/201306/218238.html

http://www.92csz.com/study/linux/11.htm

http://my.oschina.net/u/1590519/blog/330357

http://lxsym.blog.51cto.com/1364623/293862/

 

 

.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章