基于模块化编译安装LAMP:httpd 2.4.9 + mysql-5.5.33 + php-5.4.26编译安装
编译安装LAMP
基于httpd的高度模块化可以将php作为httpd的一个模块,并且可以被Apache服务调用。而Mysql作为一个独立的服务提供数据存储,所以编译安装LAMP是必须先编译安装httpd和二进制源码安装Mysql(这两者没有依赖关系),最后编译安装php。
一:二进制源码安装Mysql
1.将数据存储在基于Raid5的逻辑卷中;
创建基于raid5的逻辑卷
1.1将磁盘格式化为raid卷
# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (5224-15665, default 5224): Using default value 5224 Last cylinder, +cylinders or +size{K,M,G} (5224-15665, default 15665): +10G Command (m for help): n Command action e extended p primary partition (1-4) e Selected partition 4 First cylinder (6530-15665, default 6530): Using default value 6530 Last cylinder, +cylinders or +size{K,M,G} (6530-15665, default 15665): +20G Command (m for help): n First cylinder (6530-9141, default 6530): Using default value 6530 Last cylinder, +cylinders or +size{K,M,G} (6530-9141, default 9141): +10G Command (m for help): n First cylinder (7836-9141, default 7836): Using default value 7836 Last cylinder, +cylinders or +size{K,M,G} (7836-9141, default 9141): +10G Command (m for help): t Partition number (1-6): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-6): 5 Hex code (type L to list codes): fd Changed system type of partition 5 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): fd Changed system type of partition 6 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
1.2.重读分区信息(在分区表中没有所见的分区信息需要重复kpartx和partx)
# kpartx -af /dev/sdb # partx -a /dev/sdb # cat /proc/partitions 验证 major minor #blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 62914560 sda2 8 16 125829120 sdb 8 17 10490413 sdb1 8 18 31463302 sdb2 8 19 10490445 sdb3 8 20 31 sdb4 8 21 10490413 sdb5 8 22 10490413 sdb6 253 0 20971520 dm-0 253 1 2097152 dm-1 253 2 20971520 dm-2 253 3 10485760 dm-3 253 4 20971520 dm-4
1.3raid5
# mdadm -C /dev/md0 -a yes -l 5 -c 32K -n 3 /dev/sdb{3,5,6} # mdadm -D /dev/md0 验证
1.4基于raid5创建逻辑卷,并开机自动挂载
# pvcreate /dev/md0 创建物理卷 Physical volume "/dev/md0" successfully created # vgcreate data /dev/md0 创建卷组 Volume group "data" successfully created # lvcreate -L 10G -n mydata data 创建逻辑卷 Logical volume "mydata" created # mkdir data 创建挂在点 # vim /etc/fstab 添加如下一行 自动挂载 /dev/data/mydata /data ext4 defaults 0 0 # mount -a # mke2fs -t ext4 -L MYDATA /dev/data/mydata 创建ext4文件系统
2.通用二进制格式安装Mysql
2.1为Mysql数据库创建用户和组
# groupadd -r mysql # useradd -g mysql -r -s /sbin/nologin mysql # id mysql uid=496(mysql) gid=493(mysql) groups=493(mysql)
2.2下载二进制格式的源码包至本地,解压至/usr/local目录
# tar -xf mysql-5.5.33-linux2.6-i686.tar.gz -C /usr/local/ # cd /usr/local/
2.3 为mysql-5.5.33-linux2.6-i686创建链接方便以后更新
# ln -sv mysql-5.5.33-linux2.6-i686 mysql `mysql‘ -> `mysql-5.5.33-linux2.6-i686‘
2.4改变mysql-
5.5
.
33
-linux2.
6
-i686目录Mysql数据目录下所有文件的属主和属组
# chown -R root:mysql mysql/* # cd mysql # ll # mkdir /data/data 创建Mysql的数据目录 chown -R mysql.mysql /data/data
2.5初始化Mysql的系统库
# scripts/mysql_install_db --datadir=/data/data/ --user=mysql # chown -R mysql ./* 将该目录下的所有文件的属主改变为mysql
2.6为Mysql添加启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld # chkconfig --add mysqld # chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.7为Mysql提供配置文件并对其进行如下修改
# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf # vim /etc/my.cnf thread_concurrency = 4 修改为cpu核心数的2倍 datadir=/data/data 添加一行为其指定数据目录
2.8 Mysql安装后的后续配置
# ln -sv /usr/local/mysql/include/ /usr/include/mysql 导出头文件 `/usr/include/mysql/include‘ -> `/usr/local/mysql/include/‘ # echo "/usr/local/mysql/lib/">/etc/ld.so.conf.d/mysql.conf 导出库文件 # ldconfig 重读库文件 # ldconfig -p | grep "mysql" libtcmalloc_minimal.so.0 (libc6) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0 libmysqlclient_r.so.16 (libc6) => /usr/lib/mysql/libmysqlclient_r.so.16 libmysqlclient.so.18 (libc6) => /usr/local/mysql/lib/libmysqlclient.so.18 libmysqlclient.so.16 (libc6) => /usr/lib/mysql/libmysqlclient.so.16 libmysqlclient.so (libc6) => /usr/local/mysql/lib/libmysqlclient.so # echo ‘/usr/local/mysql/bin:$PATH‘> /etc/profile.d/mysql.sh 导出二进止文件 # echo $PATH /usr/lib/qt3.3/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin # vim /etc/man.config MANPATH /usr/local/mysql/man 导出man文档
2.9启动Mysql服务
# service mysqld start Starting MySQL [ OK ]
二: 编译安装httpd-2.4.9
httpd-2.4.9依赖你较高版本的apr和apr-util,并且还依赖域pcre-devel开发
编译安装之前首先将apr-1.5.0、apr-util-1.5.3和httpd-2.4.9的源码包下载至本地
1.解决编译安装httpd的依赖关系
# yum install -y prce-devel # yum groupinstall -y "Development Tools" # yum groupinstall -y "Server Platform Development"
2.编译安装apr-1.5.0
# tar xf apr-1.5.0.tar.bz2 # cd apr-1.5.0 # ./configure --prefix=/usr/local/apr # make # make install
3.编译安装apr-util-1.5.3
# 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
4.编译安装httpd-2.4.9(生产环境根据自己的需要启用所需要的选项)
# tar xf httpd-2.4.9.tar.bz2 # cd httpd-2.4.9 # ./configure --prefix=/usr/local/apache 指定安装目录 --sysconfdir=/etc/httpd 制定配置文件的目录 --enable-so 让apache核心装载DSO,但是不实际编译任何动态模块 --enable-ssl 启用ssl --enable-cgi 启用通用网关接口协议 --enable-rewrite 重写Apache重写功能 --with-zlib zlib库 --with-pcre 启用pcre库 --with-apr=/usr/local/apr 启用apr --with-apr-util=/usr/local/ apr-util 启用apr-util --enables-modules=most 启用httpd常用的模块 --enable-mpms-shared=most 启用常用的mpm模块 --with-mpm=event 指定mpm工作模式为event # make # make install
5.编译安装httpd-2.4.9之后的配置
1提供服务启动脚本# vim /etc/rc.d/init.d/httpd # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL 2.为脚本添加可执行权限 /etc/rc.d/init.d/httpd 3.将Apache服务脚本添加服务列表 # chkconfig --add httpd # chkconfig --list httpd # chkconfig httpd on 4在/etc/httpd/httpd.conf配置文件中添加一行 PidFile "/var/run/httpd/httpd.pid" 5.导出二进制文件 # echo ‘export PATH=/usr/local/apache/bin:$PATH‘ > /etc/profile.d/httpd.sh . /etc/profile.d/httpd.sh
6.启动服务
# service httpd start Starting httpd: [ OK ]
7测试Apache服务
三:编译安装php-5.4.26
1.解决依赖关系
# yum -y groupinstall "Desktop Platform Development" # yum -y install libmcrypt-devel # yum -y install zipb2-devel
2.解压至当前目录中,并切换至其目录下
# tar xf php-5.4.26.tar.bz2 # cd php-5.4.26
3.编安装php-5.4.26 (生产环境根据自己的需要启用所需要的选项)
# ./configure --prefix=/usr/local/php 指定安装目录 --with-mysql=/usr/local/mysql 启用安装的目录 --with-openssl 启用openssl --with-mysqli=/usr/local/mysql/bin/mysql_config 启用mysqli,优化支持 --enable-mbstring 启用多字节,支持字符串 --with-freetype-dir 启用对freetype字体库的支持 --with-jpeg-dir 启用对jpeg图片的支持 --with-png-dir 启用对png图片的支持 --with-zlib 启用对压缩库的支持 --with-libxml-dir=/usr 启用libxml2库的支持 --enable-xml 启用xml --enable-sockets 启用对套接字的支持 --with-apxs2=/usr/local/apache/bin/apxs 启用对Apache2.0以上的版本的支持 --with-mcrypt 启用对加密的支持 --with-config-file-path=/etc 指定编译安装时配置文件安装的路径 --with-config-file-scan-dir=/etc/php.d 指定php.ini文件的安装路径 --with-bz2 启用b2压缩 --enable-maintainer-zts 启用对worker和event的支持 # make 编译php # make install 安装php
4.为php提供配置文件
# cp php.ini-production /etc/php.ini
四:使Apache支持php模块
1.编辑配置文件/etc/httpd/httpd.conf
# vim /etc/httpd/httpd.conf 1.定位至AddType添加如下两行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 2.定位至DirectoryIndex index.html 修改为: DirectoryIndex index.php index.html
五:重新启动httpd服务进行测试 ,提供测试页,使用 ab命令进行压力测试
# ab -c 1000 -n 100000 http://172.16.19.100
六:安装xcache,为php加速
1.安装xcache
先下载xcache-3.1.0.tar.bz2至本地 # tar xf xcache-3.1.0.tar.bz2 # cd xcache-3.1.0 # /usr/local/php/bin/phpize 生成configure文件 # ./configure --enable-xcache --withphp-config=/usr/local/php/bin/php-config # make #make install 安装结束时会出现类似如下行 Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/ 拷贝xcache.so模块的安装路径
2.编辑php.ini文件,整合php和xcache
创建/etc/php.d
# mkdir /etc/php.d
将xcache提供的样例配置文件复制到/etc/php.d/目录下
# cp /xcache-3.1.0/xcache.ini /etc/php.d/
编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行: zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so 注意:当有多条以extension开头的行时,确保当前添加的行放在所有以extension开头的行最前面
七:提供测试页,使用 ab命令进行压力测试,比较上一次的结果,使用xcache可以提高并发速度3倍左右
# ab -c 1000-n 100000http://172.16.19.100
本文出自 “Linux之旅” 博客,请务必保留此出处http://smallbirdzhou.blog.51cto.com/7120723/1386420
基于模块化编译安装LAMP:httpd 2.4.9 + mysql-5.5.33 + php-5.4.26编译安装,古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。