httpd六之源码编译lamp并能够实现xcache为php加速

本文主要讲述如何通过源码来编译LAMP,并可以通过xcache能给为php加速,本文使用的是三台机器,本处不考虑单点故障的问题,关于负载均衡的问题,将在后续推出,敬请期待!!!

一、环境规划

用途ip地址安装应用下载地址

前段服务器192.168.1.200httpd2.4.9

后端php与服务器192.168.1.201php5.4.26

xcache服务器

192.168.1.201xcache

数据库服务器192.168.1.202mysqld5.5.36

本文所做实验的机器的系统都为centos6.5,并都已经安装好开发包组“Server Platform Development”和“Development tools”

二、编译安装httpd

关于编译安装httpd2.4.9请移步至本人的博客,本处就不再做累赘。

三、编译安装mysqld

1)、获取源程序、解压、创建软连接,此处创建软连接的好处在于在以后为mysql升级做便利。

[root@localhost ~]# tar xf mysql-5.5.36-linux2.6-x86_64.tar.gz -C /usr/local/[root@localhost ~]# cd /usr/local/[root@localhost local]# ln -sv mysql-5.5.36-linux2.6-x86_64 mysql

2)、建议:在生产环境中应该将数据库建在lvm上,底层的lvm应该通过硬raid来搭建。本文建立了一个10G的lvm的逻辑卷,并实现开机自动挂载/data下

在/etc/fstab中添加/dev/mydata/data/dataext4 defaults0 0

3)、挂载后再/data目录创建mydata目录来存放数据文件

[root@localhost local]# mkdir /data/mydata

4)、创建mysql系统用户和系统组,并使其不能登陆系统

[root@localhost local]# groupadd -r mysql[root@localhost local]# useradd -r -g mysql -s /sbin/nologin mysql

5)、为了安全起见,我们将mysql目录下的内容的属组改为mysql

[root@localhost local]# chown .mysql mysql -R

6)、安装数据库

[root@localhost mysql]# scripts/mysql_install_db –datadir=/data/mydata/ –user=mysql

查看/data/mydata下是否会生成默认数据库

7)、导出mysql的二进制文件、头文件、库文件、帮助文档

[root@localhost mysql]# echo “export PATH=/usr/local/mysql/bin:$PATH” > /etc/profile.d/mysql.sh[root@localhost mysql]# echo “/usr/local/mysql/lib” > /etc/ld.so.conf.d/mysql.conf[root@localhost mysql]# ln -sv include /usr/include/mysql`/usr/include/mysql’ -> `include'[root@localhost mysql]# . /etc/profile.d/mysql.sh

帮助文档在/etc/man.config中添加MANPATH /usr/local/mysql/man

8)、为mysql提供配置文件

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf# Try number of CPU’s*2 for thread_concurrencythread_concurrency = 2 //改成cpu的两倍datadir= /data/mydata //数据库文件的存放位置

9)、为mysql提供启动脚本,并使其能够开机自动启动

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@localhost mysql]# chkconfig –add mysqld[root@localhost mysql]# chkconfig –list mysqldmysqld0:off 1:off 2:on 3:on 4:on 5:on 6:off

10)、启动服务并尝试登陆

[root@localhost mysql]# service mysqld startStarting MySQL….[ OK ][root@localhost mysql]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.36-log MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.mysql>

11)、删除不必要的用户,并为登陆用户设置密码

mysql> drop user ”@’localhost’;Query OK, 0 rows affected (0.00 sec)mysql> drop user ”@’localhost.localdomain’;Query OK, 0 rows affected (0.00 sec)mysql> drop user ‘root’@’localhost.localdomain’;Query OK, 0 rows affected (0.00 sec)mysql> drop user ‘root’@’::1′;Query OK, 0 rows affected (0.00 sec)mysql> set password for ‘root’@’localhost’=password(‘wodehao123’);Query OK, 0 rows affected (0.00 sec)mysql> set password for ‘root’@’127.0.0.1’=password(‘wodehao123’);Query OK, 0 rows affected (0.00 sec)

四、编译php

1)、编译php

1、为了解决php的依赖关系,建议安装“Desktop Platform Development”,bzip2-devel

[root@localhost ~]# yum groupinstall “Desktop Platform Development” -y[root@localhost ~]# yum install -y bzip2-devel

2.解压编译

[root@localhost ~]# tar -xf php-5.4.26.tar.bz2[root@localhost ~]# cd php-5.4.26[root@localhost php-5.4.26]# ./configure –prefix=/usr/local/php –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –with-openssl –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-libxml-dir=/usr/ –enable-xml –enable-sockets –enable-fpm –with-config-file-path=/etc/ –with-config-file-scan-dir=/etc/php.d –with-bz2

如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。

–with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd

–with-openssl –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-bz2 加载openssl mbstring zlib bz2模块,创建freetype jpeg png存放目录

–with-libxml-dir=/usr/ libxml的查找目录

-enable-xml –enable-sockets –enable-fpm 默认开启xml sockets fpm模块

–with-config-file-path=/etc/ –with-config-file-scan-dir=/etc/php.d 生成的配置文件路径以及辅助文件的路径

[root@localhost php-5.4.26]# make && make install

3、为php提供配置文件

[root@localhost php-5.4.26]# cp php.ini-production /etc/php.ini往往为了自己的不能失败,而处心积虑前怕狼后怕虎,

httpd六之源码编译lamp并能够实现xcache为php加速

相关文章:

你感兴趣的文章:

标签云: