搜索
查看: 2666|回复: 0

linux教程之编译安装LAMP平台

[复制链接]

322

主题

0

回帖

1208

积分

网站编辑

积分
1208
发表于 2014-10-10 15:41:31 | 显示全部楼层 |阅读模式
之前安装的LAMP平台是用rpm包安装的,那么当在某些时候我们需要用到的一些功能而rpm包在制作的过程中没有把此功能做进去,那么怎么办呢,自己下载源代码进行编译安装,编译安装可以根据自己的需求配置安装软件,在企业中大多数都是编译安装的,下面将在一台默认安装有rhel5.8的系统上编译安装httpd-2.4.2和php-5.3.14和mysql-5.1.41来搭建LAMP应用平台,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
目录
一, 编译安装httpd-2.4.1
二,给编译安装的httpd提供SysV服务启动脚本
三, 编译安装mysql-5.1.41
四,编译安装php-5.3.14
五, 配置LAMP
六, 压力测试PHP页面的响应速度,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
准备以下软件包:
apr-1.4.6.tar.bz2
apr-util-1.4.1.tar.bz2
httpd-2.4.1.tar.bz2
mysql-5.1.41.tar.gz
php-5.3.14.tar.bz2
以上软件包准备好了之后复制到/usr/src目录里
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
一.编译安装apache,
1.  编译安装apr, 那么apr是什么? Apache Portable Run-time Librarie (apache的可移植运行库),我们都知道apache有很多版本,比如说w32的版本,network的版本等多种操作系统平台的版本,那么这么多的版本apache官方是不是每个操作系统平台都要新开发一个版本呢?,这个对apache官方来说不是什么难事,而对于那些开发模块的人来说,我开发一个新功能到底是跑在linux版本的apache还是跑在windows版本的apache呢?那么对于开发模块的那些人是不是也要开发不同操作系统的模块,这样岂不是很苦恼的一个事情,那么有了apr以后,对于应用程序而言.它们根本就不需要考虑具体的平台,不管是Unix .Linux还是Window的,apr类似java虚拟机,让apache跑在apr上.这样一来就方便多了.
rhel5.8的系统上默认安装了apr-1.2.7-11版本的,对于httpd-2.4版本apr-1.2.7在某些功能能上是不支持的,所以我们这里要编译安装比较新版本的apr

首先来安装基本开发库,需要注意的是这里装的基本开发库并不是只给apr用的,像下面编译http,等等都需要用到的
#yum -y groupinstall "Development Libraries" "Development Tools"
#cd /usr/src
#tar xjvf apr-1.4.6.tar.bz2
#cd apr-1.4.6
#./buildconf
#./configure --prefix=/usr/local/apr
#make && make install
#cd /usr/src
#tar xjvf apr-util-1.4.1.tar.bz2
#cd apr-util-1.4.1
#./buildconf --with-apr=/usr/src/apr-1.4.6 这里需要注意的是指定的目录是apr的源码目录
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && make install
2.编译安装apache
解决依赖关系
#yum -y install pcre-devel
安装apache
#cd /usr/src
#tar xjvf httpd-2.4.1.tar.bz2
#cd httpd-2.4.1
#./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite \ --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  
#make && make install
3. 将apache的命令以及头文件添加到系统搜素路径
添加apahe命令到系统搜索路径
#vim /etc/profile   在文件的44行上面添加一行如下
PATH=/usr/local/apache/bin:$PATH

#export PATH=/usr/local/apache/bin:$PATH
添加头文件到系统搜索路径
#ln -sv /usr/local/apache/include /usr/include/apache

二.给编译安装的apache提供SysV服务启动脚本,
SysV是Red Hat的系统上独有的服务启动脚本,我们都知道编译安装的服务程序,默认不支持service 来启动,停止等等,这样的话在某些时候需要重启服务,停止服务,等等不是很方便,那么下面提供了一个httpd的服务启动脚本
1.修改httpd主配置文件,添加pidfile文件路径
#echo "pidfile "/var/run/httpd.pid"" >> /usr/local/apache/conf/httpd.conf
2.在其它安装有rpm包的httpd 的RHEL的系统上复制两个文件到本地,并加以修改
服务启动脚本配置文件,位于/etc/sysconfig/httpd  复制到本地相同目录下即可
服务启动脚本, 位于/etc/init.d/httpd  复制到本地相同目录下
至于怎么复制自己想办法,

下面来修改服务启动脚本
#vim /etc/init.d/httpd  内容如下
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#          HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# 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.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} -d 10 $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=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart)
    if [ -f ${pidfile} ] ; then
        stop
        start
    fi
    ;;
  reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
    exit 1
esac

exit $RETVAL
3,给脚本执行权限,并添加系统服务,及下次开机自启
#chmod a+x /etc/init.d/httpd
#chkconfig --add httpd
#chkconfig httpd on
#service httpd start
上面脚本中默认有个chack13的函数,那个函数是检查一系列文件是否存在的, 我们可以不要那个函数,我已经将其删掉了,需要注意的是start函数中有调用chack13函数的,有需要将调用函数那行删掉,其他改动的地方就两个变量apachectl=/usr/local/apache/bin/apachectl   httpd=${HTTPD-/usr/local/apache/bin/httpd}
   
三.编译安装mysql数据库
1 .安装mysql
#cd /usr/src  
#tar xzvf mysql-5.1.41.tar.gz  
#cd mysql-5.1.41  
#./configure --prefix=/usr/local/mysql --sysconfdir=/usr/local/mysql/etc --with-ssl \
--localstatedir=/usr/local/mysql/database --enable-assembler --with-readline \
--with-extra-charsets=complex --enable-thread-safe-client --with-big-tables \
--with-embedded-server --enable-local-infile  --with-plugins=innobase  
#make && make install
2. 添加mysql命令,库文件,及头文件为系统搜素路径
添加mysql命令为系统搜索路径
#vim /etc/porfile   在文件的44行修改如下
PATH=/usr/local/apache/bin:/usr/local/mysql/bin:$PATH
#export PATH=/usr/local/mysql/bin:$PATH
添加库文件为系统搜索路径
#echo "/usr/local/mysql/lib/mysql" > /etc/ld.so.conf.d/mysql.conf
#ldconfig
添加头文件为系统搜索路径
ln -sv /usr/local/mysql/include/mysql /usr/include/mysql
3.给mysql提供配置文件及启动服务
创建mysql用户
#useradd -s /sbin/nologin mysql
#chown -R mysql:mysql /usr/local/mysql
复制配置文件
#cp /usr/src/mysql-5.1.41/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
复制服务启动脚本
#cp /usr/src/mysql-5.1.41/support-files/mysql.server /etc/init.d/mysqld
#chmod a+x /etc/init.d/mysqld
初始化数据库
#/usr/local/mysql/bin/mysql_install_db --user=mysql
添加为系统服务并启动
#chkconfig --add mysqld
#chkconfig mysqld on
#service mysqld restart
为mysql数据库管理员设置密码
#mysqladmin -u root password redhat

四.编译安装php
1. 安装基本开发库,因为在很多程序开发的时候需要依赖系统上的开发库
#yum -y groupinstall "X Software Development"
2.安装php
#cd /usr/src
#tar xjvf  php-5.3.14.tar.bz2
#cd php-5.3.14
#./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 \
--with-apxs2=/usr/local/apache/bin/apxs  --with-config-file-path=/etc  \
--with-config-file-scan-dir=/etc/php.d --with-bz2
#make && make install
3.给php提供配置文件
#cp /usr/src/php-5.3.14/php.ini-production /etc/php.ini
php的配置基本已经结束了,下面来让httpd支持php
五,配置LAMP
    其实也就是编辑下httpd的主配置文件让其支持php
1.编辑httpd的主配置文件让其支持php
#vim /usr/local/apache/conf/httpd.conf 修改以下内容
AddType application/x-httpd-php  .php  新加此行
AddType application/x-httpd-php-source  .phps  新加次行
DirectoryIndex  index.php  index.html   找到次行添加index.php
2.重启httpd服务
#service httpd restart
六,压力测试PHP页面的响应速度,
1.  使用httpd自带压力测试命令ab来测试
#ab -n 10000 -c 100 http://192.168.0.53/index.php  这里的IP是服务器的IP地址
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.53 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.1
Server Hostname:        192.168.0.53
Server Port:            80

Document Path:          /index.php
Document Length:        46500 bytes

Concurrency Level:      100
Time taken for tests:   10.322 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      466660000 bytes
HTML transferred:       465000000 bytes
Requests per second:    968.81 [#/sec] (mean)
Time per request:       103.219 [ms] (mean)
Time per request:       1.032 [ms] (mean, across all concurrent requests)
Transfer rate:          44151.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   15  16.9      8     101
Processing:     5   88  29.6     88     270
Waiting:        0   36  27.9     30     218
Total:          8  103  28.7    105     278

Percentage of the requests served within a certain time (ms)
  50%    105
  66%    114
  75%    119
  80%    122
  90%    130
  95%    145
  98%    173
  99%    195
100%    278 (longest request)
ok到这里基本已经配置完成了.编译安装软件的时候可以根据自己的需求,配置自己的编译参数,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 
 
大数据行业交流
大数据行业交流
大数据求职招聘
大数据求职招聘
站长电话:
15010106923
微信联系:
hb-0310
站长邮箱:
ab12-120@163.com
大数据中国微信

QQ   

版权所有: Discuz! © 2001-2013 大数据.

GMT+8, 2024-4-26 19:39 , Processed in 0.063169 second(s), 24 queries .

快速回复 返回顶部 返回列表