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/

 

 

.

 

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