环境:lamp
系统:centos 6
前提:编译安装软件需要安装开发环境,关闭iptables和selinux
1
| # yum groupinstall "Development Tools" "Server Platform Development"
|
一、编译安装httpd
httpd2.4需要apr、apr-util依赖包
1.编译安装apr、apr-util
1
2
3
4
5
6
7
8
9
| # tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
|
2.编译安装httpd 在安装之前需要安装pcre-devel包,因为在编译安装http时会安装pcre,这个包依赖于pcre-devel,系统自带没有pcre-devel这个包
1
2
3
4
5
| # yum install pcre-devel
# tar xf httpd-2.4.10.tar.bz2
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
|
3.启动httpd服务
编译安装的httpd自带有启动脚本:apachectl,所以执行/usr/local/apache/bin/apachectl命令即可启动httpd服务
直接使用apachectl命令需做一下步骤:
1
2
3
4
5
| # vim /etc/profile.d/httpd.sh
# . /etc/profile.d/httpd.sh
# echo $PATH
# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
|
4.修改httpd的主配置文件 vim /etc/httpd24/httpd.conf ,添加下行即可:
1
| PidFile "/var/run/httpd.pid"
|
5.将之前的httpd sysv服务脚本拷贝过来并修改配置文件中的以下数据:
1
2
3
4
5
| cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
# pidfile: /var/run/httpd.pid
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}
|
给脚本执行权限:
1
| # chmod +x /etc/rc.d/init.d/httpd24
|
6.加入服务列表并启动服务:
1
2
3
4
| # chkconfig --add httpd24
# chkconfig httpd24 on
# service httpd24 status
# service httpd24 start
|
二、编译安装mysql
1.新建一个lvm,然后将其挂载到数据库目录下:
1
2
| # mkdir -pv /mydata/data
//此处省略lvm的创建和挂载
|
2.新建用户以安全方式运行
1
2
3
| # groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
|
3.安装并初始化mysql
1
2
3
4
5
6
| # tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql //初始化数据库
|
4.为数据库创建主配置文件
1
2
| # mkdir /etc/mysql
# cp support-files/my-large.cnf /etc/mysql/my.cnf
|
5.修改配置文件:添加如下几行,并修改此文件中thread_concurrency的值为你的CPU个数乘以2
1
2
3
| datadir = /mydata/data //数据存放目录
innodb_file_per_table= on //每个innnodb表使用单个表文件
skip_name_resolve = on //跳过主机名称解析
|
6.在配置文件中定义“pid-file”文件路径,否则启动mysql会出现错误
1
2
3
4
| vim /etc/my.cnf
pid-file=/mydata/data/mysql.pid
vim /etc/rc.d/init.d/mysqld
mysqld_pid_file_path=/mydata/data
|
7.为mysql提供sysv服务脚本,并添加至服务列表
1
2
3
4
| # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start
|
8.输出mysql的man手册至man命令中:
1
2
| # vim /etc/man.config 添加下行即可:
MANPATH /usr/local/mysql/man
|
9.输出mysql的头文件至系统文件路径/usr/include:
1
| # ln -sv /usr/local/mysql/include /usr/include/mysql
|
10.输出mysql的库文件给系统库查找路径:
1
2
3
| # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
重新加载系统库:
# ldconfig
|
11.修改PATH环境变量,让系统可以直接使用mysql的相关命令:
1
2
| vim /etc/profile.d/mysqld.sh
# export PATH=/usr/local/mysql/bin:$PATH
|
三、编译安装php
1.开始安装php所需依赖环境:
1
2
3
| # yum -y groupinstall "Desktop Platform Development"
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
// libmcrypt-devel 本地光盘没有在epel源里面。其他的是epel源.,编译安装libmcrypt
|
2.编译安装libmcrypt
1
2
3
4
| # tar xf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install
|
3.开始编译安装php:
1
2
3
4
5
6
7
8
| # tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-mcrypt=/usr/local/libmcrypt --with-gd --with-gettext --enable-bcmath
//msqli:对应mysql另外的一个接口 ,freetype:多种字体 libxml:处理xml的文档 socket:支持socket apxs:支持http第三方模块 zts:如果之前安装过httpd且模块是prefork则不需要,否则必须安装上去
# make -j //启用多线程安装(由于php安装比较耗时)
# make install
默认情况下http但是不支持php的,所以需要修改配置文件:
# cp /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak
|
4.为php提供配置文件: 1
| # cp php.ini-production /etc/php.ini
|
5.编辑apache文件使其支持php: 1
2
3
4
5
| 在文件中添加入下行:
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
|
6.重置下httpd服务: # /usr/local/apache/bin/apachectl reload
7.默认测试页面在/usr/local/apache/htdocs,添加一个index.php测试文件: 1
2
3
4
5
6
7
8
9
| <?php
$link = mysql_connect('127.0.0.1','root',' ');
if ($link)
echo "Success...";
else
echo "Failure...";
phpinfo();
mysql_close();
?>
|
四.编译安装zabbix 1.解压zabbix包
1
| # tar xf zabbix-2.4.7.tar.gz
|
2.创建用户和用户组
1
2
| # groupadd zabbix
# useradd -g zabbix zabbix
|
3.Server和agent端编译安装
提前安装好libcurl,否则会出错,一般报错都是因为没有安装所需要的包
1
2
| # yum install libcurl*
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-libcurl --with-libxml2
|
出现问题:
1
2
3
4
5
6
7
| configure: error: Not found mysqlclient library
解决办法:
sudo yum install mysql-devel
configure: error: Curl library not found
解决办法:
sudo yum install curl-devel
# make && make install
|
4.创建zabbix运行所需要的数据库和用户权限
1
2
3
| shell> mysql -uroot -p<password>
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql> GRANT ALL ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix';
|
5.将zabbix的初始数据导入到数据库中
1
2
3
4
| # mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
//导入的顺序跟目录下的顺序刚好相反
|
6.编辑zabiix-server配置文件
1
2
3
4
5
6
7
8
9
10
11
12
| # vim /usr/local/etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix_server.log
LogFileSize=10 //日志大小限制
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=172.16.100.67
DBName=zabbix
DBUser=zbxuser
DBPassword=zbxpass
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
|
7.编辑php.ini文件并重启httpd24服务
1
2
3
4
5
6
7
| # cp /etc/php.ini /etc/php.ini.bak
# vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
# service httpd24 restart
|
8.设置时区
1
2
3
| # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# yum install ntpdate //安装ntpdate
ntpdate us.pool.ntp.org //同步时间
|
9.服务启动与配置
1
2
3
| cp提供的init.d启动脚本到系统中去
$ sudo cp misc/init.d/fedora/core/* /etc/init.d/
编辑下启动脚本以适应自己的安装环境,由于默认没有指定安装目录所以不用修改,如果指定安装目录的话则修改“BASEDIR=”即可
|
10.启动server、agent服务
1
2
| $ sudo /etc/init.d/zabbix_server start (或者zabbix_server)
$ sudo /etc/init.d/zabbix_agentd start (或者zabbix_agentd)
|
11.添加开机启动服务
1
2
3
4
| sudo chkconfig --add zabbix_server
sudo chkconfig zabbix_server on
sudo chkconfig --add zabbix_agentd
sudo chkconfig zabbix_agentd on
|
12.创建并授权zabbix日志目录
1
2
3
| $ sudo mkdir /var/log/zabbix
$ sudo chown zabbix:zabbix /var/log/zabbix
$ sudo chmod -R 775 /var/log/zabbix
|
13.检查服务可用性
1
2
3
4
5
6
7
8
9
| $ sudo service zabbix_server restart
$ sudo service zabbix_server status
[cjx@localhost etc]$ sudo service zabbix_server restart
Shutting down zabbix_server: [确定]
Starting zabbix_server: [确定]
[cjx@localhost etc]$ sudo service zabbix_server status
zabbix_server (pid 11831) 正在运行...
[cjx@localhost etc]$ sudo service zabbix_agentd status
zabbix_agentd (pid 11501 11500 11499 11498 11497 11495) 正在运行...
|
14.复制网页到http网页目录下
1
2
3
| $ cd frontends/php/
$ sudo cp -a . /usr/local/apache/htdocs/zabbix
$ sudo locale/make_mo.sh
|
15.打开zabbix web界面
http://hostlocalIP/zabbix
|