搭建Linux(centos5.3)+Apache2+Mysql5+Php5+zabbix1.8.5系统环境实现网络状况监控



软件包版本
beecrypt-4.1.2.tar.gz
curl-7.15.0.tar.gz
fontconfig-2.8.0.tar.gz
freetype-2.4.4.tar.gz
gd-2.0.35.tar.bz2
gettext-0.18.1.1.tar.gz
httpd-2.2.12.tar.gz
jpegsrc.v8c.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.5.1.tar.gz
libxml2-2.7.2.tar.gz
net-snmp-5.3.2.tar.gz
openssl-1.0.0d.tar.gz
php-5.2.17.tar.gz
zabbix-1.8.5.tar.gz
zlib-1.2.5.tar.gz
以上面软件包版本为准,安装步骤版本没做修改
-----------------------------------------------------------------------
A.linux(centos5.5)安装将mysql安装全
-----------------------------------------------------------------------
B.Mysql5数据库
查看已经安装的模块
# rpm -qa | grep mysql
mysql-server-5.0.77-4.el5_4.2
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-devel-5.0.77-4.el5_4.2
mysql-5.0.77-4.el5_4.2
mod_auth_mysql-3.0.0-3.2.el5_3
libdbi-dbd-mysql-0.8.1a-1.2.2
mysql-bench-5.0.77-4.el5_4.2
php-mysql-5.1.6-27.el5

启动
/etc/init.d/mysql.d restart

查看端口3306打开情况
#netstat -atln

修改mysql的root登陆密码为xuesong
#/usr/bin/mysqladmin -u root password xuesong

查询mysql的相关信息

#whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

/var/lib/mysql/mysql/ 数据库位置

/var/lib/mysql/mysql.sock 数据库连接文件

-----------------------------------------------------------------------
C:安装Apache

解压缩
#tar zxvf httpd-2.2.12.tar.gz(http://httpd.apache.org/download.cgi)

进入apache安装目录
#cd httpd-2.2.12

配置apache
#./configure --prefix=/usr/local/apache --with-mysql --enable-module=so --enable-shared=max
#make
#make install

试试能否启动apache, 如果启动了,可以打开浏览器,就可以看到默认的apache页面了
#/usr/local/apache/bin/apachectl start

随系统启动
vi /etc/rc.d/rc.local
/usr/local/apache/bin/apachectl start

用ln做链接,可以在终端任何地方输入apache进行操作
#ln -s /usr/local/apache/bin/apachectl /usr/sbin/apache

-----------------------------------------------------------------------
D:安装PHP
#回到root目录进行php安装
cd /root

----------查看下以下组件是否安装,此操作可省略,直接进行下面的安装-----------------
(这些包全部是rpm包,只要安装的tar.gz的源码包编译后安装到/usr/local/下,php编译引用这些组建指定路径即可)

#rpm -qa |grep openssl
#rpm -qa | grep curl
#rpm -qa | grep zlib
#rpm -qa | grep libpng
#rpm -qa | grep freetype
#rpm -qa | grep jpeg
#rpm -qa | grep fontconfig
#rpm -qa | grep gettext
#rpm -qa | grep gd
#rpm -qa | grep libxml2
#rpm -qa | grep libxslt

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

OPENSSL安装
#tar zxvf openssl-0.9.8h.tar.gz
#cd openssl-0.9.8h
#./config --prefix=/usr/local/openssl
#make
#make install

#cd ..

curl安装
#tar zxvf curl-7.18.2.tar.gz
#cd curl-7.18.2
#./configure --prefix=/usr/local/curl
#make
#make install

#cd ..

Zlib的安装,安装libpng和gd前需要先安装zlib
#tar zxvf zlib-1.2.3.tar.gz
#cd zlib-1.2.3
#./configure --prefix=/usr/local/zlib
#make
#make install
#cd ..

Libpng的安装
#tar zxvf libpng-1.2.30.tar.gz
#cd libpng-1.2.30
#./configure --prefix=/usr/local/libpng
#make
#make install

#cd ..

Freetype的安装
#tar zxvf freetype-2.3.7.tar.gz
#cd freetype-2.3.7
#./configure --prefix=/usr/local/freetype
#make
#make install

#cd ..

mkdir -pv /usr/local/jpeg/{,bin,lib,include,man/man1,man1}
#tar zxvf jpeg-6b.tar.gz
#cd jpeg/src
#mkdir -pv /usr/local/jpeg/{,bin,lib,include,man/man1,man1}
#./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
#make
#make install

#cd ..


注意:fontconfig可以考虑不安装,因为在安装这个组件过程中出现很多问题...人品问题?还是代码问题?编译都有错误...
!解压fontconfig源代码,字体库fontconfig-2.6.0.tar.gz,可能会出现说freetype没安装的提示,在fontconfig进行confiure时,加上“�Cwith-freetype-config=/usr/local/freetype”选择,其中“/usr/local/freetype”要根据您具体的情况修改。完整的configure应该是:
./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype
问题解决 ---安装字体库出现问题,考虑之后不安装
#tar zxvf fontconfig-2.6.0.tar.gz
#cd fontconfig-2.6.0
#./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype
#make
#make install

#cd /root


GDlib的安装,不装此包可能会出现在装gd包时出现 AM_ICON 的错误提示,此时需要安装 gettext 软件包,安装时间稍长
#tar zxvf gettext-0.17.tar.gz
#cd gettext-0.17
#./configure --prefix=/usr/local/gettext
#make
#make install


gdlib安装
#tar zxvf gd-2.0.35.tar.gz
#cd gd-2.0.35
#CPPFLAGS="-I/usr/local/freetype/include -I/usr/local/jpeg/include -I/usr/local/libpng/include -I/usr/local/gettext/include" ./configure --prefix=/usr/local/gd2/ --with-zlib=/usr/local/zlib/ --with-png=/usr/local/libpng/ --with-jpeg=/usr/local/jpeg/ --with-freetype=/usr/local/freetype/ --with-gettext=/usr/local/gettext/
#make && make install
#cp gd.h /usr/local/gd2/lib/
返回:
-----------------------------------------
** Configuration summary for gd 2.0.34:

Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: no
Support for Xpm library: no
Support for pthreads: yes
----------------------------------------
#make && make install
#cd ..

libxml2的安装(有点久)
#tar zxvf libxml2-sources-2.6.32.tar.gz
#cd libxml2-2.6.32
#./configure --prefix=/usr/local/libxml2
#make
#make install

#cd ..

#libxslt的安装
#tar zxvf libxslt-1.1.22.tar.gz
#cd libxslt-1.1.22
#./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
#make && make install
#cd ..

zend引擎(对zabbix非必须,所以不装了...-_-)

开始PHP5的安装,只要通过./configure后出现thanks之类的话才表示成功...否则都要查看错误进行调整,如果提示make test,此步可以跳过
#tar zxvf php-5.2.17.tar.gz
#cd php-5.2.17

#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/var/lib/mysql --enable-ftp --with-libexpat-dir=/usr/local/lib --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg/ --with-zlib-dir=/usr/local/zlib/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --enable-bcmath --with-libxml-dir=/usr/local/libxml2 --with-config-file-path=/usr/local/php/lib --with-openssl --with-gettext --enable-sockets --with-curl=/usr/local/curl --enable-mbstring=all
#make && make install

提示:You may want to add: /usr/local/php/lib/php to your php.ini include_path

[

运行之后可能遇到的问题以及解决方法:

error 1

checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.

(看提示就明白 是一个lib库没装 先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)

解决办法

yum install libxml2-devel.x86_64

error 2

checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

这是ssl没装

解决办法

yum install openssl.x86_64 openssl-devel.x86_64 -y

error 3

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

这是bzip2软件包没有安装

解决办法

yum install bzip2-devel.x86_64 -y

error 4

configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/

curl和curl库文件没有安装

解决办法

yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5

checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

GD库没有安装

解决办法

yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

error 6

checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

libmcrypt库没有安装 ,要是不能用yun安装的话 就要去下载个gz包 自己编译安装

(编译安装 ./configure --piefix=/usr/local/libmcrypt make && make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

要是错误里面含有mysql的 那是mysql-devel 没有安装

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

]



#cp /root/php-5.2.17/php.ini-dist /usr/local/php/lib/php.ini
#vi /usr/local/php/lib/php.ini
extension=php_mysql.dll
extension=php_mbstring.dll
max_execution_time = 600
max_input_time = 600
post_max_size = 32M
date.timezone ="asia/shanghai"

整合php和apache
注意在/usr/local/apache/conf/httpd.conf加上下代码使apache执行PHP,LoadModule php5_module modules/libphp5.so 这段代码肯定可以在httpd.conf找到,如果找不到则需要重新编译了
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

这两行是让apache知道php的文件类型

DirectoryIndex index.html 改成DirectoryIndex index.html index.php
让apache默认的首页也支持index.php

重启apache服务器,使得其加载php解析...
#updatedb
#apache -k restart
/usr/local/apache/bin/apachectl restart
最后一步重新启动apache报如下错误:
httpd: Syntax error on line 53 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

不关闭SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1

在默认的/usr/local/apache/htdocs下建立info.php
<?php
phpinfo();
?>

------------------net-snmp组件安装-----------
先装beecrypt-4.1.2,因为net-snmp需要这个包
#tar zxvf beecrypt-4.1.2.tar.gz
#cd beecrypt-4.1.2
#./configure --prefix=/usr(默认是安装在/usr/local,我们需要安装在/usr目录下)
#make
#make install


开始安装
#tar -zxvf net-snmp-5.3.2.tar.gz
#cd net-snmp-5.3.2
#./configure
a.回车
b.输入 3
c.输入 root@
d.输入 Unknown
e.输入 /var/log/snmpd.log
f.输入 /var/net-snmp

2.ln -s libelf.so.1 /usr/lib/libelf.so
3.#make
4.#make install
-----------------------------------------------------------------------

E:zabbix1.8.5安装

#cd /root
#useradd zabbix -s /bin/false
#tar xvzf zabbix-1.8.5.tar.gz
#cd zabbix-1.8.5

#mysql -u root -p
输入密码进入mysql控制端

>create database zabbix;
创建成功后退出
>quit;
//xuesong代表上面安装mysql的时候设置的密码,下面三条语句一条条执行即可,将数据库信息导入到数据库zabbix中
#mysql -u root -pxuesong --default-character-set=utf8 -D zabbix < create/schema/mysql.sql
#mysql -u root -pxuesong --default-character-set=utf8 -D zabbix < create/data/data.sql
#mysql -u root -pxuesong --default-character-set=utf8 -D zabbix < create/data/images_mysql.sql

服务器端+客户端的编译:
./configure --with-mysql --with-net-snmp --enable-server --enable-agent --prefix=/usr/local/zabbix
./configure --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --enable-server --enable-agent --prefix=/usr/local/zabbix
遇到的问题:
1.提示缺少net-snmp,则要安装net-snmp组件
2.提示configure: error: Not found MySQL library或者提示缺失mysqlclient,则为mysql没装完整,还需要mysql-devel,建议全新安装mysql

===================make install后出现如下=====================
Configuration:

Detected OS: linux-gnu
Install path: /usr/local/zabbix
Compilation arch: linux

Compiler: gcc
Compiler flags: -g -O2 -I/usr/include/mysql -g -pipe -m32 -march=i386 -mtune=pentium4 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -I/usr/include/rpm -I. -I/usr/local/include

Enable server: yes
With database: MySQL
WEB Monitoring via: no
Native Jabber: no
SNMP: net-snmp
IPMI: no
Linker flags: -L/usr/lib/mysql -L/usr/lib -L/usr/local/lib -lnetsnmp -lcrypto -lm -lcrypto -L/usr/local/lib -lnetsnmp -lcrypto -lm -lcrypto
Libraries: -lm -lresolv -lmysqlclient -lnetsnmp

Enable proxy: no

Enable agent: yes
Linker flags:
Libraries: -lm -lresolv

LDAP support: no
IPv6 support: no

***********************************************************
* Now run 'make install' *
* *
* Thank you for using ZABBIX! *
* <http://www.zabbix.com> *
***********************************************************
==================================================
make
make install


zabbix 设置

#vi /etc/services
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper


配置文件

#chown -R zabbix.zabbix /usr/local/zabbix/
#cp misc/conf/zabbix_* /usr/local/zabbix/

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

ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=<password> 修改为xuesong
DBSocket=/tmp/mysql.sock 修改为 /var/lib/mysql/mysql.sock


复制启动程序
cp misc/init.d/redhat/zabbix_server_ctl /etc/init.d/
cp misc/init.d/redhat/zabbix_agentd_ctl /etc/init.d/


vi /etc/init.d/zabbix_server_ctl

# base zabbix dir
BASEDIR=/usr/local/zabbix
# PID file
PIDFILE=/var/tmp/zabbix_server.pid
# binary file
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server



复制zabbix

mkdir /usr/local/apache/htdocs/zabbix
cp -Rpf frontends/php/* /usr/local/apache/htdocs/zabbix


LAMPZ安装完成,接下来去web上看看是否可以进行安装了

------安装中第3步检查配置信息无错误则会返回正常,可进行继续安装操作--------
Current value Required Recommended
PHP version 5.2.17 5.0 5.3.0 Ok
PHP memory limit 128M 128M 256M Ok
PHP post max size 32M 16M 32M Ok
PHP upload max filesize 2M 2M 16M Ok
PHP max execution time 600 300 600 Ok
PHP max input time 600 300 600 Ok
PHP timezone asia/shanghai Ok
PHP databases support MySQL
Ok
PHP BC math yes Ok
PHP MB string yes Ok
PHP Sockets yes Ok
PHP Session yes Ok
PHP GD 2.0 2.0 2.0.34 Ok
GD PNG Support yes Ok
libxml module 2.7.2 2.6.15 2.7.6 Ok
ctype module yes Ok

Ok
-----------------
配置完成下载一个配置文件,按照提示放到指定目录
mv zabbix.conf.php /usr/local/apache/htdocs/zabbix/conf

安装完成进入界面管理(http://zabbix_server/zabbix),默认用户Admin,密码zabbix

语言选择
点击zabbix 首页右上角porfile,language 中选择Chinese(CN)即可
扩展汉化
点击Administration----Locales
选择chinese(CN)
下一步---Download---new_locale.inc.php保存到本地
可以自己翻译,翻译完了在放回服务器
覆盖include/locales/cn_zh.inc.php



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

zabbix监控mysql主从复制

起因:zabbix可能监控到mysql服务的运行情况,但确不能监控mysql的主从复制是否正常:有时候,同步已经停止,但管理人员却不知道。

下手处:登陆mysql从服务器,通过执行 mysql> show slave status\G 查看其输出,即可判定主从复制是否正常。下面是某个从服务器的输出:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.93.16
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 1752541
Relay_Log_File: hy-mysql3-relay-bin.000088
Relay_Log_Pos: 2339
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
这个输出,最关键处就是"Slave_IO_Running: Yes“和“Slave_SQL_Running: Yes”,这两个值全是"Yes"就表明主从复制正常,否则就是有问题。
操作步骤:
1、在主数据库服务器增加一个用户,给予较低的权限,操作为
mysql > grant Replication client on *.* to 'zabbix'@'%' identified by 'zabbix';
mysql> flush privileges;
2、登陆从服务器验证一下,看是否正常。操作为:
mysql -uzabbix -pzabbix -e "show slave stutas\G"
3、在从服务器安装 zabbix_agentd,然后在配置文件zabbix_agentd.conf加入一行
UserParameter=mysql.slave,/opt/scripts/check_mysql_slave |grep OK -c
4、编写脚本/opt/scripts/check_mysql_slave(这是监控其作用的核心),其内容如下:
#!/bin/sh
declare -a slave_is
slave_is=($(/usr/local/mysql/bin/mysql -uzabbix -pzabbix -e "show slave status\G"|grep Running |awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
then
echo "OK -slave is running"
exit 0
else
echo "Critical -slave is error"
exit 2
fi

5、修改配置item、trigger,并测试。


你可能感兴趣的:(apache,linux,mysql,PHP,zabbix)