nawawa001 发表于 2018-12-14 10:20:36

linux命令:编译安装httpd、mysql、php等LAMP环境xcache缓存PHP

  
  MySQL服务器维护了两类变量:
      服务器变量:
         定义MySQL服务器运行特性
         SHOW GLOBAL VARIABLES ;
   状态变量:
  保存了MySQL服务器运行统计数据
  SHOW GLOBAL STATUS
  

  MySQL通配符:
  _: 匹配任意单个字符
  %:匹配任意长度的任意字符
  

  Httpd 2.4新特性:
  1、MPM可于运行时装载: --enable-mpms-shared=all --with-mpm=event编译安装是指定MPM运行模块为event
  2、Event MPM 支持event新的多路处理模块
  3、异步读写

  4、在每模块及每目录上指定日志级别
  5、每请求配置: ,,;
  6、增强的表达式分析器;
  7、毫秒级的Keepalive Timeout;
  8、基于域名的虚拟主机不再需要NameVirtualHost指令;
  9、降低了内存占用;
  10、支持在配置文件中使用自定义变量;
  11、对于基于IP的访问控制不再支持order all,deny allow from all
  而是支持Require user
  Usage:
  Require user USERNAME
  Require group GRPNAME
  Require ip IPADDR   允许该IP地址访问
  Require not ip IPADDR 拒绝该IP地址访问
  IP
  NETWORK/NETMASK
  NETWORK/LENGTH
  NET
  172.16.0.0/255.255.0.0=172.16.0.0/16=172.16
  Require host HOSTNAME
  HOSTNAME : www.linux.com
  DOMAIN:.linux.com
  允许所有主机访问:
  Require all granted
  拒绝所有主机访问:
  Require all deny
  

  --enable-modules=most
  新增的模块:
  mod_proxy(之前版本也有)
  mod_proxy_fcgi
  mod_proxy_scgi
  mod_proxy_express
  mod_remoteip
  mod_sesslon
  mod_ratelimit
  mod_request
  等等
  
  通过编译安装LAMP环境:
  安装顺序:httpd --> mysql --> php --> xcache(php缓存程序)
  Linux,Apache,Mysql,Php
  以下演示安装httpd:2.4.4   php:5.4.13Mysql:5.5(通用二进制格式,解压后即可使用)
  

  1、 安装httpd 2.4.4需安装高版本的apr1.4以上的版本 apr-util1.4版本以上
  ------------------------------------------------------------------------
  # rpm -q apr
  apr-1.3.9-3.el6.x86_64
  # rpm -q apr-util
  apr-util-1.3.9-3.el6.x86_64
  *所以需要下载更高版本的arp和apr-util,但是原来的安装程序不能卸载,因为他们被其他程序依赖
  需通过编译安装在其他目录下即可。
  

  把apr和apr-util安装在/usr/local目录下,这个目录为第三方软件安装目录:
  
  # ls

  anaconda-ks.cfg   apr-util-1.4.1.tar.bz2install.log
  apr-1.4.6.tar.gz httpd-2.4.4.tar.gz      install.log.syslog
  

  安装顺序:apr-1.4.6 --> apr-util-1.4.1 --> httpd-2.4.4
  
  # tar -zxf apr-1.4.6.tar.gz
  # tar -xf apr-util-1.4.1.tar.bz2
  # tar -xf httpd-2.4.4.tar.gz
# ls
anaconda-ks.cfg   apr-util-1.4.1     install.logapr-1.4.6
apr-util-1.4.1.tar.bz2apr-1.4.6.tar.gzhttpd-2.4.4.tar.gz    httpd-2.4.4      


安装前需确认开发环境组是否安装:Development Tools(开发工具)和Development Libraries(开发库)
# yum groupinstall "Development Tools"
  Loaded plugins: refresh-packagekit, rhnplugin
  This system is not registered with RHN.
  RHN support will be disabled.
  Setting up Group Process
# yum groupinstall "Development Libraries"


# cd apr-1.4.6
# ./configure --prefix=/usr/local/apr#编译安装前,
                               --prefix指定编译安装路径    
  # make

  # make install#至此编译安装apr完成(删除编译安装的软件,只需要把安装目录删除即可)
  # cd ~/apr-util-1.4.1
  # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr#编译安装apr-util需通过--prefix指定安装目录,以及--with-apr指定apr的安装路径。(必须2者都指定) 至此apr-util-1.4.1安装成功
  # cd ~/httpd-2.4.4

  # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util#编译安装httpd需指定安装目录--prefix,主配置文件目录--sysconfdir
  还需开通很多功能,--enable-so等功能,且必须指定apr和apr-util编译安装的位置。
  
  checking how to run the C preprocessor... gcc -E
  checking for gcc option to accept ISO C99... -std=gnu99
  checking for pcre-config... false
  configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/#这里报错提示pcre-config没有安装,需安装pcre-devel
  # yum install pcre-devel #安装pcre-devel
  Loaded plugins: refresh-packagekit, rhnplugin
  This system is not registered with RHN.
  RHN support will be disabled.
  Server                                  | 3.7 kB   00:00
  ...
  Setting up Install Process
  Resolving Dependencies
  --> Running transaction check
  ---> Package pcre-devel.x86_64 0:7.8-3.1.el6 set to be updated
  --> Finished Dependency Resolution
  ......
  Running Transaction
  Installing   : pcre-devel-7.8-3.1.el6.x86_64                1/1
  Installed:
  pcre-devel.x86_64 0:7.8-3.1.el6
  Complete!
  # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util    #再重新执行一次编译
  .......
  checking for OpenSSL... checking for user-provided OpenSSL base directory... none
  checking for OpenSSL version >= 0.9.7... FAILED#提示openssl version 错误,解决方法
                              安装openssl-devel
  configure: WARNING: OpenSSL version is too old
  no
  checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
  # yum install openssl-devel#安装openssl-devel
  Loaded plugins: refresh-packagekit, rhnplugin
  This system is not registered with RHN.
  RHN support will be disabled.
  Setting up Install Process
  Resolving Dependencies
  --> Running transaction check
  ---> Package openssl-devel.x86_64
  ..........
  Installed:
  openssl-devel.x86_64 0:1.0.0-4.el6
  Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.4-1.el6    krb5-devel.x86_64 0:1.8.2-3.el6         libcom_err-devel.x86_64 0:1.41.12-3.el6   libselinux-devel.x86_64 0:2.0.94-2.el6   libsepol-devel.x86_64 0:2.0.41-3.el6       zlib-devel.x86_64 0:1.2.3-25.el6
  Complete!
  # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util    #再重新执行一次编译

  .........
  config.status: creating build/rules.mk
  config.status: creating build/pkg/pkginfo
  config.status: creating build/config_vars.sh
  config.status: creating include/ap_config_auto.h
  config.status: executing default commands   #直到编译安装不再出现报错可以继续执行make
  # make#一般./configure 编译报错都解决后,make和make一般都会成功
  直接执行make和make install就可以了
  # make install
  ......
  
  Installing man pages and online manual
  mkdir /usr/local/apache/man
  mkdir /usr/local/apache/man/man1
  mkdir /usr/local/apache/man/man8
  mkdir /usr/local/apache/manual
  make: Leaving directory `/root/httpd-2.4.4'#至此httpd编译安装完成
  

  启动httpd前需把selinux关闭,否则无法启动:
  # getenforce #查看selinux当前状态
  Enforcing
  # setenforce 0#临时关闭selinux,重启失效。
  # vim /etc/selinux/config #编辑selinux配置文档,使设置永久有效
  # This file controls the state of SELinux on the system.
  # SELINUX= can take one of these three values:
  #   enforcing - SELinux security policy is enforced.
  #   permissive - SELinux prints warnings instead of enforcing.
  #   disabled - No SELinux policy is loaded.
  SELINUX=permissive#这项改成permissive或者disabled(建议改成permissive)
  # SELINUXTYPE= can take one of these two values:
  #   targeted - Targeted processes are protected,
  #   mls - Multi Level Security protection.
  SELINUXTYPE=targeted
  # getenforce
  Permissive   #状态变为permissive

  # cd /usr/local/apache
  # ls
  binbuildcgi-binerrorhtdocsiconsincludelogsmanmanualmodules
  

  # bin/apachectl start #测试启动apache服务
  # netstat -tlnp #查看监听的端口号
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address   Foreign Address    State    PID/Program name
  tcp    0   0 0.0.0.0:111      0.0.0.0:*      LISTEN   1325/rpcbind
  tcp    0    0 192.168.122.1:53    0.0.0.0:*      LISTEN    1809/dnsmasq
  tcp    0    0 0.0.0.0:22       0.0.0.0:*       LISTEN   1572/sshd
  tcp    0   0 :::111         :::*         LISTEN      1325/rpcbind
  tcp    0    0 :::80         :::*      LISTEN      14642/httpd
  

  至此httpd服务就启动了,通过客户端访问ip即可
  https://s4.运维网.com/wyfs02/M00/8D/9E/wKioL1ikETSQ4jYfAAFC8dnKxII098.jpg
  修改httpd.conf配置文档使得httpd.pid(httpd进程启动生成的文档,服务关闭后文档消失)文档生成路径修改为/var/run/httpd.pid,
  # bin/apachectl stop #停止httpd服务
  # vim /etc/httpd/httpd.conf #配置文件路径为编译安装httpd的时候设置的路径
  ..........
  # least PidFile.
  #
  ServerRoot "/usr/local/apache"
  PidFile "/var/run/httpd.pid"#新增该行内容(必须先停止httpd服务)
  .........
  

  ***为了使得httpd可以通过service httpd stop|start|restart管理方式,需在/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 server
   #      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
                 kellproc -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
  

  
  # chmod +x /etc/init.d/httpd   #赋予执行权限
  # service httpd restart#通过启用服务方式成功重新启动httpd服务
  停止 httpd:                                           [确定]
  正在启动 httpd:                                        [确定]
  # chkconfig --add httpd #把httpd服务添加到开机启动列表中
  # chkconfig --list#查看开机启动列表
  NetworkManager 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  ebtables   0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
  firstboot    0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
  gfs2       0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
  haldaemon    0:关闭1:关闭2:关闭3:启用4:启用5:启用6:关闭
  httpd       0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭#默认开机不启动
  ip6tables    0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  # chkconfig httpd on #设定httpd服务在级别2345默认开机启动(或者指定chkconfig --level 35 httpd on设定服务在级别35开机启动)
  # chkconfig --list#查看开机启动列表
  
NetworkManager 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
ebtables   0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
firstboot    0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
gfs2       0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
haldaemon    0:关闭1:关闭2:关闭3:启用4:启用5:启用6:关闭
  httpd       0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭 #默认开机启动
  ip6tables    0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  # cd
  # vim /etc/profile.d/httpd.sh#把/usr/local/httpd/bin执行脚本命令路径放置在PATH变量中,使得该路径中的命令可以直接执行。
  export PATH=$PATH:/usr/local/apache/bin #增加该行内容
  

  然后重新登录下系统,/usr/local/apache/bin中的命令都可以直接执行,而不用加路径
  # httpd -t   #检查httpd配置文件是否有语法错误
  Syntax OK
  
  # echo $PATH
  /usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache/bin:/root/bin   #已经把/usr/local/apache/bin目录加到了PATH变量中
  # vim /etc/httpd/httpd.conf#修改主配置文档中下面2行内容
  https://s3.运维网.com/wyfs02/M01/8D/A4/wKioL1ilD0uzju7nAAYcFsfxVjk533.jpg # httpd -t
  Syntax OK
  # service httpd restart
  停止 httpd:                                           [确定]
  正在启动 httpd:                                        [确定]
  # httpd -M   #查看当前启用的模块
  Loaded Modules:
  .......
  headers_module (shared)
  setenvif_module (shared)
  version_module (shared)
  mpm_prefork_module (shared)#默认模块已经修改为prefork模块了(以后需要切换其他模块只需                        要修改主配置文档中上一步骤的内容即可)
  unixd_module (shared)
  status_module (shared)
  ........
-----------------------------------------------------------------------------------

  2、开始安装mysql5.5.54版本
  --------------------------------------------------------------------------------
  # ls
  anaconda-ks.cfg   apr-util-1.4.1.tar.bz2install.log.syslog                   httpd-2.4.4             mysql-5.5.54-linux2.6-x86_64.tar.gz
  # tar xf mysql-5.5.54-linux2.6-x86_64.tar.gz -C /usr/local #-C 指定解压目录
  # cd /usr/local
  # ls
  apacheapr-utiletc    include   lost+foundmysql-5.5.54-linux2.6-x86_64
  
  # ln -sv mysql-5.5.54-linux2.6-x86_64 mysql #创建软链接mysql
  "mysql" -> "mysql-5.5.54-linux2.6-x86_64"
  # ls
  apacheapr-utiletc    includelib64   mysql-5.5.54-linux2.6-x86_64
  apr   bin      gameslib   libexec   mysql
  # cd mysql
  # groupadd -r -g 306 mysql#-r指创建系统组,-g指定组ID
  # useradd -r -g 306 -u 306 mysql #-r创建系统用户(不能登录系统的用户)
                                       -u指定UID
  # id mysql#查看用户信息,UID GID
  uid=306(mysql) gid=306(mysql) 组=306(mysql)
  # ls /home
  donggen
  
  # ll
  总用量 72
  drwxr-xr-x.2 root root   40962月 17 09:33 bin
  -rw-r--r--.1 7161 31415 17987 11月 28 20:32 COPYING
  drwxr-xr-x.3 root root   40962月 17 09:33 data
  drwxr-xr-x.2 root root   40962月 17 09:33 docs
  drwxr-xr-x.3 root root   40962月 17 09:33 include
  -rw-r--r--.1 7161 31415   301 11月 28 20:32 INSTALL-BINARY
  drwxr-xr-x.3 root root   40962月 17 09:33 lib
  drwxr-xr-x.4 root root   40962月 17 09:33 man
  drwxr-xr-x. 10 root root   40962月 17 09:34 mysql-test
  -rw-r--r--.1 7161 314152496 11月 28 20:32 README
  drwxr-xr-x.2 root root   40962月 17 09:33 scripts
  drwxr-xr-x. 27 root root   40962月 17 09:33 share
  drwxr-xr-x.4 root root   40962月 17 09:33 sql-bench
  drwxr-xr-x.2 root root   40962月 17 09:33 support-files
  # chown -R mysql.mysql /usr/local/mysql/*#-R递归把mysql目录下的所有文档                   或目录都修改为mysql用户和mysql组
  # ll
  总用量 72
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 bin
  -rw-r--r--.1 mysql mysql 17987 11月 28 20:32 COPYING
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 data
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 docs
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 include
  -rw-r--r--.1 mysql mysql   301 11月 28 20:32 INSTALL-BINARY
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 lib
  drwxr-xr-x.4 mysql mysql40962月 17 09:33 man
  drwxr-xr-x. 10 mysql mysql40962月 17 09:34 mysql-test
  -rw-r--r--.1 mysql mysql2496 11月 28 20:32 README
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 scripts
  drwxr-xr-x. 27 mysql mysql40962月 17 09:33 share
  drwxr-xr-x.4 mysql mysql40962月 17 09:33 sql-bench
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 support-files
  #
  

  ** 由于mysql数据库随着时间的增长,数据会越来越大,所以应该把数据库数据放置在一个单独的可扩展的分区卷上,以便后期管理和备份,挂载在逻辑卷是比较好的方法如下:
  

  # fdisk /dev/sdb#新建分区
  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  Building a new DOS disklabel with disk identifier 0xef7e9b34.
  Changes will remain in memory only, until you decide to write them.
  After that, of course, the previous content won't be recoverable.
  

  Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  

  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): p
  

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0xef7e9b34
  

  Device Boot      Start         End      Blocks   IdSystem
  

  Command (m for help): n
  Command action
  e   extended
  p   primary partition (1-4)
  p
  Partition number (1-4): 1
  First cylinder (1-2610, default 1):
  Using default value 1
  Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G
  

  Command (m for help): T
  Selected partition 1
  Hex code (type L to list codes): 8e
  Changed system type of partition 1 to 8e (Linux LVM)
  

  Command (m for help): p
  

  Disk /dev/sdb: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0xef7e9b34
  

  Device Boot      Start         End      Blocks   IdSystem
  /dev/sdb1               1      1306    10490413+8e Linux LVM
  

  Command (m for help): w
  The partition table has been altered!
  

  Calling ioctl() to re-read partition table.
  Syncing disks.
  # partprobe /dev/sdb#通知内核重读sdb分区
  # pvcreate /dev/sdb1   #先把/dev/sdb1分区建立一个pv物理卷
  Physical volume "/dev/sdb1" successfully created
  # pvs#查看物理卷
  PV         VG   FmtAttr PSizePFree
  /dev/sdb1       lvm2 a-   10.00g 10.00g
  # vgcreate myvg /dev/sdb1   #以/dev/sdb1分区创建myvg卷组
  Volume group "myvg" successfully created
  # vgs#查看卷组
  VG   #PV #LV #SN Attr   VSizeVFree
  myvg   1   0   0 wz--n- 10.00g 10.00g
  # lvcreate -n mydata -L 5G myvg#在卷组myvg中建立一个大小为5G,
                                   名称为mydata 的逻辑卷
  Logical volume "mydata" created
  
  # lvs    #查看逻辑卷
  LV   VG   Attr   LSize Origin Snap%Move Log Copy%Convert
  mydata myvg -wi-a- 5.00g
  
  # mke2fs -t ext4 /dev/myvg/mydata   #格式化mydata逻辑卷
  mke2fs 1.41.12 (17-May-2010)
  文件系统标签=
  操作系统:Linux
  块大小=4096 (log=2)
  分块大小=4096 (log=2)
  Stride=0 blocks, Stripe width=0 blocks
  327680 inodes, 1310720 blocks
  65536 blocks (5.00%) reserved for the super user
  第一个数据块=0
  Maximum filesystem blocks=1342177280
  40 block groups
  32768 blocks per group, 32768 fragments per group
  8192 inodes per group
  Superblock backups stored on blocks:
  32768, 98304, 163840, 229376, 294912, 819200, 884736
  

  正在写入inode表: 完成
  Creating journal (32768 blocks): 完成
  Writing superblocks and filesystem accounting information: 完成
  # mkdir /mydata   #建立一个目录作为挂载点
  # vim /etc/fstab    #设定逻辑卷开机自动挂载
  
  # /etc/fstab

  # Created by anaconda on Tue Feb 14 01:11:01 2017
  #
  # Accessible filesystems, by reference, are maintained under '/dev/disk'
  # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  #
  

  tmpfs          /dev/shm       tmpfs   defaults      0 0
  devpts          /dev/pts       devptsgid=5,mode=6200 0
  sysfs          /sys         sysfs   defaults       0 0
  proc         /proc      proc    defaults       0 0
  /dev/myvg/mydata   /mydata    ext4    defaults      0 0#新增该行内容
  
  # mount -a    #重读/etc/fstab硬盘挂载文件,使得新增的分区挂载成功
  # mount#查看已经挂载的分区
  /dev/sda2 on / type ext4 (rw)
  proc on /proc type proc (rw)
  sysfs on /sys type sysfs (rw)
  devpts on /dev/pts type devpts (rw,gid=5,mode=620)
  tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
  /dev/sda1 on /boot type ext4 (rw)
  /dev/sda5 on /home type ext4 (rw)
  /dev/sda3 on /usr/local type ext4 (rw)
  /dev/sda6 on /var type ext4 (rw)
  none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
  sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
  /dev/mapper/myvg-mydata on /mydata type ext4 (rw)#逻辑卷mydata已经挂载到/mydata目录
  
  # mkdir /mydata/data
  # ll /mydata
  总用量 20
  drwxr-xr-x. 2 root root40962月 17 17:30 data
  drwx------. 2 root root 163842月 17 15:11 lost+found
  # chown -R mysql.mysql /mydata/data/#更改文件夹属主和属组-R递归
  # ll /mydata
  总用量 20
  drwxr-xr-x. 2 mysql mysql40962月 17 17:30 data
  drwx------. 2 rootroot163842月 17 15:11 lost+found
  # chmod o-rx /mydata/data/   #删除/data组其他人的读和执行权限
  # ll /mydata
  总用量 20
  drwxr-x---. 2 mysql mysql40962月 17 17:30 data
  drwx------. 2 rootroot163842月 17 15:11 lost+found
  # cd /usr/local/mysql
  # pwd
  /usr/local/mysql
  
  # scripts/mysql_install_db --user=mysql --datadir=/mydata/data/#初始化mysql,以mysql用户,且数据目录需修改为/mydata/data目录
  Installing MySQL system tables...
  .........
  To start mysqld at boot time you have to copy
  support-files/mysql.server to the right place for your system
  PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  To do so, start the server, then issue the following commands:
  

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h lamp.com password 'new-password'
  

  Alternatively you can run:
  ./bin/mysql_secure_installation
  

  which will also give you the option of removing the test
  databases and anonymous user created by default.This is
  strongly recommended for production servers.
  

  See the manual for more instructions.
  

  You can start the MySQL daemon with:
  cd . ; ./bin/mysqld_safe &
  

  You can test the MySQL daemon with mysql-test-run.pl
  cd ./mysql-test ; perl mysql-test-run.pl
  

  Please report any problems at http://bugs.mysql.com/#初始化完成
  # ll#由于mysql目录内的文件和目录都为mysql属主,很容易被破解,所以把                  mysql目录内的文件和目录属主修改为root
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 bin
  -rw-r--r--.1 mysql mysql 17987 11月 28 20:32 COPYING
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 data
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 docs
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 include
  -rw-r--r--.1 mysql mysql   301 11月 28 20:32 INSTALL-BINARY
  drwxr-xr-x.3 mysql mysql40962月 17 09:33 lib
  drwxr-xr-x.4 mysql mysql40962月 17 09:33 man
  drwxr-xr-x. 10 mysql mysql40962月 17 09:34 mysql-test
  -rw-r--r--.1 mysql mysql2496 11月 28 20:32 README
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 scripts
  drwxr-xr-x. 27 mysql mysql40962月 17 09:33 share
  drwxr-xr-x.4 mysql mysql40962月 17 09:33 sql-bench
  drwxr-xr-x.2 mysql mysql40962月 17 09:33 support-files
  
  # chown -R root ./*#-R递归更改当前目录中所有文件和目录的属主为root
  # ll
  drwxr-xr-x.2 root mysql40962月 17 09:33 bin
  -rw-r--r--.1 root mysql 17987 11月 28 20:32 COPYING
  drwxr-xr-x.3 root mysql40962月 17 09:33 data#由于data数据文件夹已经修改为/mydata/data目录,所以此处不需要把属主修改为mysql,否则如果没有修改data路径需修改为mysql
  drwxr-xr-x.2 root mysql40962月 17 09:33 docs
  drwxr-xr-x.3 root mysql40962月 17 09:33 include
  -rw-r--r--.1 root mysql   301 11月 28 20:32 INSTALL-BINARY
  drwxr-xr-x.3 root mysql40962月 17 09:33 lib
  drwxr-xr-x.4 root mysql40962月 17 09:33 man
  drwxr-xr-x. 10 root mysql40962月 17 09:34 mysql-test
  -rw-r--r--.1 root mysql2496 11月 28 20:32 README
  drwxr-xr-x.2 root mysql40962月 17 09:33 scripts
  drwxr-xr-x. 27 root mysql40962月 17 09:33 share
  drwxr-xr-x.4 root mysql40962月 17 09:33 sql-bench
  drwxr-xr-x.2 root mysql40962月 17 09:33 support-files
  
  # ls support-files/
  binary-configure   magic      my-medium.cnf      mysql.server(mysql的服务启动脚本)
  config.medium.inimy-innodb-heavy-4G.cnfmysqld_multi.server
  # cp support-files/mysql.server /etc/init.d/mysqld#把启动脚本复制到                        linux系统默认服务启动的init.d目录中,并修改名称为mysqld
  # ll /etc/init.d/mysqld#查看mysqld是否有执行的权限
  -rwxr-xr-x. 1 root root 108752月 18 09:21 /etc/init.d/mysqld
  # chkconfig --add mysqld#把mysqld进程添加到开机启动列表
  # chkconfig --list mysqld #查看开机启动列表中mysqld是否设置为开机启动
  mysqld         0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  

  至此mysql启动进程,数据文件夹等都设置完成,接下来配置mysql的配置文档相关内容:
  MYsql配置文件路径:/etc/my.cnf

  
  # ll support-files/
  总用量 96
  -rwxr-xr-x. 1 root mysql1153 11月 29 00:10 binary-configure
  -rw-r--r--. 1 root mysql4691 11月 29 00:10 my-huge.cnf #配置文件
  -rw-r--r--. 1 root mysql 19759 11月 29 00:10 my-innodb-heavy-4G.cnf #配置文件
  -rw-r--r--. 1 root mysql4665 11月 29 00:10 my-large.cnf #配置文件
  -rw-r--r--. 1 root mysql4676 11月 29 00:10 my-medium.cnf #配置文件
  -rw-r--r--. 1 root mysql2840 11月 29 00:10 my-small.cnf #配置文件
  ..........
  以上5个都是配置文档模板,具体使用哪个作为自己mysql为配置文件,需根据自己的内存大小定义:
  内存小于64M选择small.cnf 内存128M选择medium.cnf 内存为512M选择large.cnf 内存1-2G选择
  huge.cnf作为配置文件。
  
  # free -m#查看内存大小,内存大小为2G,所以选择
  total    used   free    shared    buffers   cached
  Mem:    2007    239    1767   0      16      71
  -/+ buffers/cache:      151       1855
  Swap:1499      0    1499
  
  # cp support-files/my-huge.cnf /etc/my.cnf
  # vim /etc/my.cnf#修改配置文件,红色部分为修改过的
  ...........
  
  port            = 3306
  socket          = /tmp/mysql.sock
  skip-external-locking
  key_buffer_size = 384M
  max_allowed_packet = 1M
  table_open_cache = 512
  sort_buffer_size = 2M
  read_buffer_size = 2M
  read_rnd_buffer_size = 8M
  myisam_sort_buffer_size = 64M
  thread_cache_size = 8
  query_cache_size = 32M
  # Try number of CPU's*2 for thread_concurrency
  thread_concurrency = 4   #修改为4,数值为CPU的个数*2
   datadir = /mydata/data   #新增该行,指定数据目录为/mydata/data
  至此就可以启动mysql服务了

  # service mysqld start#启动mysqld服务
  Starting MySQL.. SUCCESS!
  # service mysqld restart#重启mysqld服务
  Shutting down MySQL. SUCCESS!
  Starting MySQL.. SUCCESS!
  # netstat -tlnp |grep mysqld
  tcp   0   0 0.0.0.0:3306    0.0.0.0:*         LISTEN    6954/mysqld #已启动
  

  # mysql#启用mysql客户端,无法启动,提示命令没发现(默认PATH变量没mysql                                    所在路径)
  -bash: mysql: command not found
  # vim /etc/profile.d/mysql.sh    #新建mysql.sh把mysql的启动命令路径加到                                    PATH变量中
  export PATH=$PATH:/usr/local/mysql/bin#新增该行内容

  

  重新登录系统后再测试mysql命令,如下:
  

  # msyql#成功登录到mysql客户端
  Welcome to the MySQL monitor.Commands end with ; or \g.
  Your MySQL connection id is 1
  Server version: 5.5.54-log MySQL Community Server (GPL)
  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql>
  
至此mysql已经配置完成,为了使得可以通过man命令查看mysql需修改/etc/man.conf配置文档
  # vim /etc/man.config

  ....

  
  MANPATH /usr/man
  MANPATH /usr/share/man
  MANPATH /usr/local/man
  MANPATH /usr/local/share/man
  MANPATH /usr/X11R6/man
  MANPATH /usr/local/mysql/man    #新增该行,使得帮助文档能通过man找到
  # vim /etc/ld.so.conf.d/mysql.conf #新建mysql库路径文件,使得系统能够识别到

   /usr/local/mysql/lib       #新增该行内容
  
# ldconfig -v   #通知系统重新读取库文件,-v显示重读过程
  ............

  
  libxklavier.so.15 -> libxklavier.so.15.0.0
  liblcms.so.1 -> liblcms.so.1.0.19
  /lib64/tls: (hwcap: 0x8000000000000000)
  /usr/lib64/sse2: (hwcap: 0x0000000004000000)
  /usr/lib64/tls: (hwcap: 0x8000000000000000)
  # ln -sv /usr/local/mysql/include /usr/include/mysql #创建mysql的头文件目录链                              接,使得可以直接输出头文件
  "/usr/include/mysql" -> "/usr/local/mysql/include"
  # ls /usr/include/mysql/
  decimal.h   my_attribute.hmy_global.h   mysqld_ername.hmy_sys.h
  my_alloc.hmy_getopt.h   mysql_com.h   mysql_version.hsql_common.h
  ------------------------------------------------------------------------------
  至此MySQL已经安装配置完成。

  
3、编译安装PHP
  
  lftp test@10.109.134.247:/> get php-5.4.23.tar.bz2
  12251671 bytes transferred in 1 second (11.10M/s)      
  lftp test@10.109.134.247:/> bye      #从ftp服务器上下载php或者从文章最后地址下载
  # ls
  anaconda-ks.cfg   apr-util-1.4.1.tar.bz2install.log.syslog
  apr-1.4.6.tar.gzhttpd-2.4.4.tar.gz    php-5.4.23.tar.bz2
  # tar xf php-5.4.23.tar.bz2
  # cd php-5.4.23
  # ls
  ........
  buildconf.bat   makedist   README.MAILINGLIST_RULES
  CODING_STANDARDSMakefile.frag    README.namespaces
  header   php.ini-developmentREADME.UNIX-BUILD-SYSTEM

  .......
  

这里为了演示event模块,所以这里需修改httpd的配置文档把模块修改为event模块。
  # vim /etc/httpd/httpd.conf
  .......
  #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so#注释掉该行
  LoadModule mpm_event_module modules/mod_mpm_event.so   #增加该行内容使用event模块
  ........
# httpd -M #查看httpd目前启用的模块类型有哪些
  
  ...........
  env_module (shared)
  headers_module (shared)
  setenvif_module (shared)
  version_module (shared)
  mpm_event_module (shared)#已经修改为event模块类型了
   ...............

  

  # ./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#指定安装路径,mysql安装路径,支持各种功能和接口,为了支持apache的worker和event这两个MPM多处理模块,编译时使用--enable-maintainer-zts选项,如果apache使用的是prefork模块则不需要使用该选项。
  ...........
  checking for strftime... (cached) yes
  checking which regex library to use... php
  checking whether to enable LIBXML support... yes
  checking libxml2 install dir... /usr
  checking for xml2-config path...
  configure: error: xml2-config not found. Please check your libxml2 installation.#编译是提示错误,先查询是否安装过libxml2,如果安装看是否安装了libxml2-devel
  

  # rpm -qa|grep libxml2#2个主程序已经安装
  libxml2-2.7.6-1.el6.x86_64
  libxml2-python-2.7.6-1.el6.x86_64
  
  # yum list all | grep libxml*
  This system is not registered with RHN.
  RHN support will be disabled.
  libxml2.x86_64   2.7.6-1.el6   @anaconda-RedHatEnterpriseLinux-201009221801.x86_64/6.0
  libxml2-python.x86_642.7.6-1.el6@anaconda-RedHatEnterpriseLinux-
  libxml2.i686   2.7.6-1.el6                     Server
  libxml2-devel.i686      2.7.6-1.el6                  Server
  libxml2-devel.x86_64   2.7.6-1.el6                  Server #64位系统安装
  perl-libxml-perl.noarch   0.08-10.el6                  Server
  

  
  # yum install libxml2-devel.x86_64
  Loaded plugins: refresh-packagekit, rhnplugin
  This system is not registered with RHN.
  RHN support will be disabled.
  Setting up Install Process
  Resolving Dependencies
  --> Running transaction check
  ---> Package libxml2-devel.x86_64 0:2.7.6-1.el6 set to be updated
  --> Finished Dependency Resolution
  

  Dependencies Resolved
  

  =====================================================================================================
  Package                  Arch                Version                  Repository         Size
  =====================================================================================================
  Installing:
  libxml2-devel            x86_64            2.7.6-1.el6                Server            1.1 M
  

  Transaction Summary
  =====================================================================================================
  Install       1 Package(s)
  Upgrade       0 Package(s)
  

  Total download size: 1.1 M
  Installed size: 8.5 M
  Is this ok : y
  Downloading Packages:
  Running rpm_check_debug
  Running Transaction Test
  Transaction Test Succeeded
  Running Transaction
  Installing   : libxml2-devel-2.7.6-1.el6.x86_64                                              1/1
  

  Installed:
  libxml2-devel.x86_64 0:2.7.6-1.el6
  Complete!   #libxml2-devel安装完成
  

  *再次执行PHP编译./configure
  # ./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
  .........
  checking for gzgets in -lz... yes
  checking whether to enable bc style precision math functions... no
  checking for BZip2 support... yes
  checking for BZip2 in default path... not found
  configure: error: Please reinstall the BZip2 distribution#提示BZip2报错
  # yum list all |grep bzip2* #查询是否缺少bzip2组建
  This system is not registered with RHN.
  RHN support will be disabled.
  bzip2.x86_64    1.0.5-6.1.el6      @anaconda-RedHatEnterpriseLinux
  bzip2-libs.x86_64   1.0.5-6.1.el6    @anaconda-RedHatEnterpriseLinux
  bzip2-devel.i686   1.0.5-6.1.el6         Server
  bzip2-devel.x86_64   1.0.5-6.1.el6         Server   #该组建未安装
  # yum install bzip2-devel.x86_64 #安装bzip-devel组建
  Loaded plugins: refresh-packagekit, rhnplugin
  This system is not registered with RHN.
  RHN support will be disabled.
  Setting up Install Process
  Resolving Dependencies
  --> Running transaction check
  ---> Package bzip2-devel.x86_64 0:1.0.5-6.1.el6 set to be updated
  --> Finished Dependency Resolution
  

  Dependencies Resolved
  

  =====================================================================================================
  Package                  Arch                Version                      Repository         Size
  =====================================================================================================
  Installing:
  bzip2-devel            x86_64            1.0.5-6.1.el6                Server            250 k
  

  Transaction Summary
  =====================================================================================================
  Install       1 Package(s)
  Upgrade       0 Package(s)
  

  Total download size: 250 k
  Installed size: 412 k
  Is this ok : y
  Downloading Packages:
  Running rpm_check_debug
  Running Transaction Test
  Transaction Test Succeeded
  Running Transaction
  Installing   : bzip2-devel-1.0.5-6.1.el6.x86_64                                              1/1
  

  Installed:
  bzip2-devel.x86_64 0:1.0.5-6.1.el6
  Complete!      #安装bzip2-devel成功
  

  
*再次执行PHP编译./configure
# ./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
  ....................
  checking for alloca... (cached) yes
  checking for working memcmp... yes
  checking for stdarg.h... (cached) yes
  checking for mcrypt support... yes
  configure: error: mcrypt.h not found. Please reinstall libmcrypt.#提示libmcrypt未安装,
  需安装mhash-0.9.9.2.rpm mhash-devel-0.9.2.rpm libmcrypt-2.5.7.rpmlibmcrypt-devel-2.5.7.rpm
  # ls
  apr-1.4.6   libmcrypt-2.5.8-9.el6.x86_64.rpm    apr-1.4.6.tar.gz
  libmcrypt-devel-2.5.8-9.el6.x86_64.rpm    mhash-0.9.9-2.3.x86_64.rpm
  apr-util-1.4.1.tar.bz2    mhash-devel-0.9.9-2.3.x86_64.rpm
  # rpm -ivh *.rpm#安装当前目录下,所有.rpm包
  warning: libmcrypt-2.5.8-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
  warning: mhash-0.9.9-2.3.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 04b8b50a: NOKEY
  Preparing...                  ###########################################
  1:mhash                  ########################################### [ 25%]
  2:libmcrypt               ########################################### [ 50%]
  3:libmcrypt-devel         ########################################### [ 75%]
  4:mhash-devel            ###########################################
  

  
*再次执行PHP编译./configure
# ./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-apxs2=/usr/local/apache/bin/apxs 这个表示把php做成httpd的模块方式即不用启动脚本的,如果需要把php做成fcgi,则该项需修改为--enable-fpm,两项不能同时使用。
  .................
  Generating files
  configure: creating ./config.status
  creating main/internal_functions.c
  creating main/internal_functions_cli.c
  +--------------------------------------------------------------------+
  | License:                                                         |
  | This software is subject to the PHP License, available in this   |
  | distribution in the file LICENSE.By continuing this installation |
  | process, you are bound by the terms of this license agreement.   |
  | If you do not agree with the terms of this license, you must abort |
  | the installation process at this point.                            |
  +--------------------------------------------------------------------+
  

  Thank you for using PHP.
  

  config.status: creating php5.spec
  config.status: creating main/build-defs.h
  config.status: creating scripts/phpize
  config.status: creating scripts/man1/phpize.1
  config.status: creating scripts/php-config
  config.status: creating scripts/man1/php-config.1
  config.status: creating sapi/cli/php.1
  config.status: creating sapi/cgi/php-cgi.1
  config.status: creating ext/phar/phar.1
  config.status: creating ext/phar/phar.phar.1
  config.status: creating main/php_config.h
  config.status: main/php_config.h is unchanged
  config.status: executing default commands   #至此第一步./configure完成
  # make
  # make install
  .............

  Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
  You may want to add: /usr/local/php/lib/php to your php.ini include_path
   Structures_Graph- installed: 1.0.4
   XML_Util       - installed: 1.2.1
  /root/php-5.4.23/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
  ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
  Installing PDO headers:          /usr/local/php/include/php/ext/pdo/
  至此php编译安装完成,接下来对php相关配置进行设置
  

  # pwd#确认当前路径,需把编译安装路径下的配置文档复制到对应路径
  /root/php-5.4.23
  # ls
  acinclude.m4   INSTALL    NEWS    README.TESTING
  aclocal.m4   install-sh   pear       README.TESTING2
  build   libphp5.la      php5.spec      README.UNIX-BUILD-SYSTEM
  buildconf   libs      php5.spec.in       README.WIN32-BUILD-SYSTEM
  buildconf.bat   libtool   run-tests.php
  CODING_STANDARDSLICENSE       php.ini-development(开发环境下的php配置文件)
  php.ini-production(生产环境的php配置文件)      scripts
  # cp php.ini-production /etc/php.ini   #复制生产环境的php配置文件到编译安装php时指定的路径--with-config-file-path=/etc中并改名
  

  接下来就是编辑php配置文件,使得php能跟httpd结合起来工作:
  # vim /etc/httpd/httpd.conf#编辑httpd配置文档,红色部分为修改或者新增
  .............
  AddType application/x-compress .Z
  AddType application/x-gzip .gz .tgz
  AddType application/x-httpd-php .php      #新增该行
   AddType application/x-httpd-php-source .phps   #新增该行
  

  
  DirectoryIndex index.php index.html#增加支持index.php主页网页
  
  修改以上2个地方后,php就可以测试运行了。
  
  
  # httpd -t#检测httpd配置文件是否有语法错误
  Syntax OK
  # service httpd restart#重启httpd服务
  停止 httpd:                                             [确定]
  正在启动 httpd:                                          [确定]
  # cd /usr/local/apache/htdocs/#进入httpd网页存放目录
  # ls
  index.html
  # mv index.html index.php
  # vim index.php   #编辑主页文件,内容如下,保存并退出。
  It works!test
  
  #

  在客户端浏览器中测试是否php启动生效,测试结果如下,php和httpd服务关联运行了
  https://s2.运维网.com/wyfs02/M02/8D/C9/wKiom1iqqwzSSSI5AAG8A0Up9Fk930.jpg
  
修改index.php文档内容,测试php是否与mysql关联运行:

  # vim index.php   #内容如下
  It works! My Apache!
  
  在客户端浏览器中测试php和mysql服务是否关联运行,测试结果如下:
  mysqld服务启动时,测试结果如下:
  https://s3.运维网.com/wyfs02/M02/8D/C6/wKioL1iqq_Kh8thRAAH1QOTYzpo927.jpg
  先停止mysqld服务:
  
  # service mysqld stop#关闭mysqld服务
  Shutting down MySQL.. SUCCESS!    #关闭成功
  mysqld服务停止时,测试结果如下:
  https://s1.运维网.com/wyfs02/M00/8D/C9/wKiom1iqrN7TB4z-AAHDr9lHinA412.jpg
  

  4、安装php扩展功能xcache,为PHP加速:
  先下载xcache软件,下载地址文章结尾有地址:
  安装步骤:
     1、tar xf xcache-2.0.1.tar.gz
     2、cd xcache-2.0.1
     3、/usr/local/php/bin/phpize (必须在解压缩目录中执行该脚本,以便能关联对应的php程序)
     4、./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
     5、make && make install
  
  # ls
  anaconda-ks.cfg         install.log            php-5.4.23
  apr-1.4.6          install.log.syslog            php-5.4.23.tar.bz2
  apr-1.4.6.tar.gz   libmcrypt-2.5.8-9.el6.x86_64.rpm       xcache-2.0.1.tar.gz
  
  # tar xf xcache-2.0.1.tar.gz
  # cd xcache-2.0.1
  # pwd
  /root/xcache-2.0.1
  # /usr/local/php/bin/phpize#运行该脚本加载xcache到php中
  Configuring for:
  PHP Api Version:         20100412
  Zend Module Api No:      20100525
  Zend Extension Api No:   220100525
  
  #./configure --enable-xcache --with-php-config=/usr/local/php/bin
  /php-config编译xcache,--enable-xcache启用xcache功能,--with-php-config指定php配置文档路径.........
  checking for grep that handles long lines and -e... /bin/grep
  checking for egrep... /bin/grep -E
  checking for a sed that does not truncate output... /bin/sed
  checking for cc... cc
  ..........

  appending configuration tag "CXX" to libtool
  configure: creating ./config.status
  config.status: creating config.h
  # make

  ............
  

  See any operating system documentation about shared libraries for
  more information, such as the ld(1) and ld.so(8) manual pages.
  ----------------------------------------------------------------------
  Build complete.
  Don't forget to run 'make test'.
  # make install
  Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

  #提示安装共享扩展在php库扩展路径中,该路径后面配置xcache配置文档时需提供。
  # mkdir /etc/php.d
  # cp xcache.ini /etc/php.d/ #把xcache配置文档复制到php.d路径中
  # vim /etc/php.d/xcache.ini #编辑xcache配置文档,红色部分为修改内容
  

  https://s1.运维网.com/wyfs02/M01/8D/CD/wKioL1irl92h5BE8AAJnoiAMzDA275.jpg

  https://s4.运维网.com/wyfs02/M02/8D/D0/wKiom1irmLnQH47IAAEhlQ0jp_Y136.jpg
  

  其他选项默认设置即可,设置完后保存退出,重启httpd服务后,xcache才会生效。

  
  # service httpd restart #重启httpd服务,使得相关配置生效
  停止 httpd:                                           [确定]
  正在启动 httpd:                                          [确定]
  # vim /usr/local/apache/htdocs/index.php #编辑配置文档
  https://s1.运维网.com/wyfs02/M02/8D/D0/wKiom1irmwyykEhhAAGImI8ks6w167.jpg
  在客户端访问测试,xcache是否关联成功:
  https://s2.运维网.com/wyfs02/M00/8D/CD/wKioL1irnjzCyZdgAANH1q2Qcmc887.jpg
  

  

  5、编译安装的httpad如何配置使用虚拟主机功能:
  先在httpd主配置文档中,关闭中心主机,启用virtualhost功能
  # cd /etc/httpd/
  # vim httpd.conf#编辑httpd主配置文档,修改内容如下图,注释中心主机配                           置,启用虚拟主机配置功能。
  
https://s3.运维网.com/wyfs02/M02/8D/D0/wKiom1irocOBHNgcAALcGBHQeuw812.jpg
https://s3.运维网.com/wyfs02/M01/8D/D0/wKiom1irocPAcnvpAAC70d4BHmo449.jpg
  # vim extra/httpd-vhosts.conf

  https://s4.运维网.com/wyfs02/M02/8D/CE/wKioL1iro_ngS55VAAIyCJlEjfc163.jpg
  # vim httpd.conf#查看httpd主配置文档是否启用mod_log模块。
  https://s4.运维网.com/wyfs02/M00/8D/CE/wKioL1irpJ6D_4tHAAE2wJ3agT4117.jpg
  
  # mkdir /web/www/{a.org,b.net} -pv#创建单独的目录存放网页内容
  mkdir: 已创建目录 "/web/www"
  mkdir: 已创建目录 "/web/www/a.org"
  mkdir: 已创建目录 "/web/www/b.net"
  # vim extra/httpd-vhosts.conf#编辑虚拟主机配置文档
  日志信息格式:combined显示更详细信息,common一般显示信息
  

  https://s5.运维网.com/wyfs02/M01/8D/D1/wKiom1irq42Q4u3CAAOyiWE8cKk179.jpg
  # mkdir /var/log/httpd#创建日志目录
  # httpd -t#检查httpd配置文件是否有语法错误
  Syntax OK
  # service httpd restart#重启httpd服务
  停止 httpd:                                             [确定]
  正在启动 httpd:                                          [确定]
  

  # vim extra/httpd-vhosts.conf#编辑虚拟主机配置文档,
                                 明确定义可以允许访问权限.

  

https://s1.运维网.com/wyfs02/M01/8D/D2/wKiom1irr7HB1sP4AAL6Kgy4hO0255.jpg
  保存退出。
  
# httpd -t#检查httpd配置文件是否有语法错误
Syntax OK
# service httpd restart#重启httpd服务
停止 httpd:                                           [确定]
正在启动 httpd:                                       [确定]
  通过客户端浏览器访问如下:
  
https://s4.运维网.com/wyfs02/M00/8D/CF/wKioL1irsFXDEJqaAADuQIKWHgs553.jpg
https://s2.运维网.com/wyfs02/M01/8D/D2/wKiom1irsFajoWy2AAEWwUh96Hc712.jpg
  # cd /usr/local/apache
  # pwd
  /usr/local/apache
  # ab -c 100 -n 1000 http://127.0.0.1/index.php #测试本机httpd服务器的压力测试 ,ab为apache自带的一个压力测试脚本,-c:指并发数(即一次接受多少个请求)-n: 指请求总   数(总共接受多少个请求)
  This is ApacheBench, Version 2.3
  Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  Licensed to The Apache Software Foundation, http://www.apache.org/
  Benchmarking 127.0.0.1 (be patient)
  Completed 100 requests
  Completed 200 requests
  Completed 300 requests
  Completed 400 requests
  Completed 500 requests
  Completed 600 requests
  Completed 700 requests
  Completed 800 requests
  Completed 900 requests
  Completed 1000 requests
  Finished 1000 requests
  

  Server Software:      Apache/2.4.4
  Server Hostname:      127.0.0.1
  Server Port:            80
  

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

  Concurrency Level:      100
  Time taken for tests:   0.288 seconds
  Complete requests:      1000
  Failed requests:      0
  Write errors:         0
  Total transferred:      239000 bytes
  HTML transferred:       53000 bytes
  Requests per second:    3472.81 [#/sec] (mean)
  Time per request:       28.795 (mean)
  Time per request:       0.288 (mean, across all concurrent requests)
  Transfer rate:          810.55 received
  Connection Times (ms)
  minmean[+/-sd] median   max
  Connect:      6   13   3.8   12      24
  Processing:   3   1516.0   12   173
  Waiting:      2   1315.8   11   170
  Total:         16   2816.2   23   183
  Percentage of the requests served within a certain time (ms)
  50%   23
  66%   27
  75%   31
  80%   34
  90%   37
  95%   41
  98%   45
  99%    136
  100%    183 (longest request)
  

  使用ab命令测试apache服务器性能:
  ========================================================
  -c concurrency: 一次性发起的请求格式,默认为1;
  -i:测试时使用HEAD方法,默认为GET;
  -k:启用HTTP长连接请求方式;
  -n requests:发起的模拟请求的总个数,默认为1个,请求数要大于等于并发连接数;
  -q:静默模式,在请求数大于150个时不输出请求完成百分比;
  输出结果:

   Time taken for tests: 从第一个请求连接建立到收到最后一个请求的响应保温结束所经历的时长;
   Complete requests: 成功的请求数;
  

  6、下载安装phpMyAdmin软件:下载地址文章结尾处有
  # ls
  apr-util-1.4.1.tar.bz2mysql-5.5.54-linux2.6-x86_64.tar.gz    install.log
  httpd-2.4.4   php-5.4.23    phpMyAdmin-4.0.10.19-all-languages.tar.gz
  # tar xf phpMyAdmin-4.0.10.19-all-languages.tar.gz -C /web/www/a.org
                                         #-C指定加压到那个目录下
  # cd /web/www/a.org/
  # mv phpMyAdmin-4.0.10.19-all-languages pma
  # cd pma
  # mv config.sample.inc.php config.inc.php   #修改名称
  
  # openssl rand -base64 10#通过openssl生成编码为base64且长度为10的随机数
  TM9OWK5xzr9RKg==
  # vim config.inc.php #编辑phpMyAdmin的配置文件,把刚生成的随机数写入,如下图:
  https://s2.运维网.com/wyfs02/M02/8D/D2/wKioL1ir6pKiRHQ-AAJ7VtiR7Qw302.jpg
  # mysqladmin -uroot password 'redhat' #给mysql的root用户设置密码,空密码不允许登录phpmyadmin
  # mysqladmin -uroot -p flush-privileges#测试新设置的密码是否正确有效
  Enter password:
  #
  在客户端浏览器输入地址测试是否能正常登录:
  
https://s4.运维网.com/wyfs02/M01/8D/D4/wKiom1ir7OnifKRjAAK87Q4QIws698.jpg
https://s5.运维网.com/wyfs02/M01/8D/D2/wKioL1ir7Ozxk1ppAAWx-FsbwoM618.jpg
  测试访问正常。
  
7、编译安装的apache如何实现ssl功能:

  # vim /etc/httpd/httpd.conf #编辑httpd配置文档,启用ssl模块和功能
  
https://s2.运维网.com/wyfs02/M00/8D/D5/wKiom1ir9iTyw7sRAAF5dHh37mw244.jpg
https://s4.运维网.com/wyfs02/M00/8D/D3/wKioL1ir9iXj7MDLAAFZXY5x-dI375.jpg
  # vim /etc/httpd/extra/httpd-ssl.conf
  
https://s1.运维网.com/wyfs02/M02/8D/D3/wKioL1ir_SzRJJmpAAL7LrEHgVQ850.jpg
https://s5.运维网.com/wyfs02/M00/8D/D6/wKiom1ir_TaDbHw6AAO1r_ommno926.jpg
  # httpd -t #检查httpd配置文档是否有语法错误
  AH00526: Syntax error on line 76 of /etc/httpd/extra/httpd-ssl.conf:
  SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?). #提示需要开启mod_socache模块
  # vim /etc/httpd/httpd.conf #编辑httpd配置文档,启用mod_socache模块
  https://s4.运维网.com/wyfs02/M00/8D/D3/wKioL1ir_cvS88e1AAFLHExMaXM718.jpg
  # httpd -t #再次检查httpd配置文档是否有语法错误
  AH00526: Syntax error on line 105 of /etc/httpd/extra/httpd-ssl.conf:
  SSLCertificateFile: file '/etc/httpd/server.crt' does not exist or is empty#提示自签证书文件为空或者不存在,因为我们没有建立自签证书服务和生成密钥。
  

  8、登录第二台服务器做CA证书服务器(10.109.134.236服务器)并配置好:
# cd /etc/pki
# cd CA
# pwd
/etc/pki/CA
# (umask 077; openssl genrsa -out private/cakey.pem 2048) #生成私钥;umask077表示生产私钥权限为600,genrsa证书加密格式,-out保存路径及文件名 2048私钥长度
Generating RSA private key, 2048 bit long modulus
...............................................+++
.......+++
e is 65537 (0x10001)
#vim /etc/pki/tls/openssl.cnf #编辑openssl配置文件,红色部分是更改的地方
[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
countryName_default            = CN#国家
countryName_min               = 2
countryName_max               = 2


stateOrProvinceName            = State or Province Name (full name)
stateOrProvinceName_default         = Jiangsu#省份


localityName                   = Locality Name (eg, city)
localityName_default            = Kunshan#城市

0.organizationName               = Organization Name (eg, company)
0.organizationName_default      = XueLinux#组织

# we can do this but it is not needed normally :-)
#1.organizationName            = Second Organization Name (eg, company)
#1.organizationName_default       = World Wide Web Pty Ltd

organizationalUnitName            = Organizational Unit Name (eg, section)
organizationalUnitName_default   = Tech#部门
# vim /etc/pki/tls/openssl.cnf #修改CA证书路径为绝对路径
https://s4.运维网.com/wyfs02/M00/8C/D8/wKiom1h676eC0vHiAAHgYhvWdvg015.jpg
# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3655#跟据cakey.pem私钥生成自签证书cacert.pem,其他默认格式,-days是证书有效期(天)
https://s4.运维网.com/wyfs02/M02/8C/D8/wKiom1h67AKB0TOFAATM7FQMx7s077.jpg
# mkdir certs crl newcerts#创建3个证书相关的目录
# touch index.txt   
# echo 01 > serial#下一个证书编号为01
# ls#确保/etc/pki/CA目录下有以下文件及目录
cacert.pemcertscrlindex.txtnewcertsprivateserial



9、重新登录到httpd服务器(10.109.134.237)端,进行相关私钥的设置:
# cd /etc/httpd
# ls
extrahttpd.confhttpd.conf.bakmagicmime.typesoriginal
# mkdir ssl#建立ssl目录
# cd ssl/

# (umask 077; openssl genrsa 1024 > httpd.key) #生成私钥文件
Generating RSA private key, 1024 bit long modulus
.............................++++++
..............................................++++++
e is 65537 (0x10001)
# openssl req -new -key httpd.key -out httpd.csr #生成证书签核请求
https://s3.运维网.com/wyfs02/M02/8D/D4/wKioL1isBYuiflQmAAaOOo5LlYk315.jpg

  # ls
  httpd.csr httpd.key
# scp httpd.csr 10.109.134.236:/tmp   #把生成的证书签核请求文件复制
                                       到CA证书服务器的/tmp目录下
  root@10.109.134.236's password:
  httpd.csr                                                          100%692   0.7KB/s   00:00


10、登录CA证书服务器端(10.109.134.236),对生成的证书签核请求进行签核:
# cd /tmp
# ls
httpd.csrlost+found
# openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 3650#签核证书申请,并生成证书文件httpd.crt,-days证书有效期,如提示以下错误,需修改配置文件
https://s5.运维网.com/wyfs02/M00/8C/D6/wKioL1h7GBjgiKICAAJdYR-D2jM107.jpg
#cd /etc/pki/CA
# vim /etc/pki/tls/openssl.cnf #修改配置文件,具体如下图,
全部修改为optional:
https://s3.运维网.com/wyfs02/M02/8C/D6/wKioL1h7GPPSsvJmAAFuC_aAxX0109.jpg
# openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 3650
https://s2.运维网.com/wyfs02/M01/8C/D6/wKioL1h7GbuhOMsxAAVyESYL5h8540.jpg# cat index.txt#查看签核证书记录文件,已经生成一条证书签核记录
V270113063102Z01unknown/C=CN/ST=Jiangsu/O=XueLinux/OU=Tech/CN=hello.xuelinux.com/emailAddress=hello@xuelinux.com
# cat serial   #查看证书版本号,下一个证书号为02
02
# scp /tmp/httpd.crt 10.109.134.237:/etc/httpd/ssl/ #把签核好的证书文                  件httpd.crt从CA服务器拷贝到httpd服务器/etc/httpd/ssl/目录下
The authenticity of host '10.109.134.249 (10.109.134.249)' can't be established.
RSA key fingerprint is 5c:ec:b4:96:87:ae:6a:f8:66:09:d9:7a:f8:39:21:ae.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.109.134.249' (RSA) to the list of known hosts.
root@10.109.134.237's password:
httpd.crt         100% 3892   3.8KB/s   00:00   #拷贝完成
# ls newcerts/   #查看是否有生成证书的记录01.pem生成的第一个证书记录
01.pem
# cd /tmp
# ls
httpd.crthttpd.csr
# rm -rf httpd.c*#需把临时目录下的证书文件清除,以免被别人获取
# ls


11、切换登录到httpd服务器端(10.109.134.237),对ssl配置文件进行修改:
# ls
httpd.crt httpd.csrhttpd.key
# vim /etc/httpd/extra/httpd-ssl.conf#修改配置文件httpd-ssl.conf,
如下图位置需做修改:

https://s5.运维网.com/wyfs02/M00/8D/D7/wKioL1is4rLxJPXqAAUx85Nv08k168.jpg
https://s4.运维网.com/wyfs02/M01/8D/D7/wKioL1is4rTDsDziAAOTUYxlySk592.jpg
  # httpd -t#检查httpd配置文件是否有语法错误
  Syntax OK
# service httpd restart#重启httpd服务
  停止 httpd:                                           [确定]
  正在启动 httpd:                                        [确定]
# netstat -tlnp   #查看主机是否监听了443端口
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address   Foreign Address    State    PID/Program name
  tcp    0    0   0.0.0.0:3306   0.0.0.0:*       LISTEN   8787/mysqld
  tcp    0    0   0.0.0.0:22   0.0.0.0:*      LISTEN      1646/sshd
  tcp    0    0    :::80         :::*         LISTEN      1871/httpd
  tcp    0    0    :::443      :::*         LISTEN      1871/httpd
至此httpd服务器端和CA证书服务器端配置完成。
  客户端没有安装证书的测试结果如下:
  https://s4.运维网.com/wyfs02/M01/8D/DA/wKiom1is6AfQf7rpAAN2JNPU8W0560.jpg
  把CA证书服务器上生成的证书文件/etc/pki/CA/cacert.pem拷贝到客户端后,并改名后缀名为
cacert.crt,然后点击安装安装证书至受信任机构中即可:
登录到CA证书服务器(10.109.134.236)
  
  # lftp test@10.109.134.247#远程连接ftp服务器
  口令:
  lftp test@10.109.134.247:/> put /etc/pki/CA/cacert.pem#把cacert.pem证书上传至ftp服务器
  1432 bytes transferred#传输完成
  lftp test@10.109.134.247:/> ls cacert.pem#查看ftp服务器上是否已经上传成功
  -rw-rw-rw-   1 user   group      1432 Feb 22 09:24 cacert.pem
  修改后缀为,cacert.crt并点击安装:
https://s2.运维网.com/wyfs02/M00/8D/DA/wKiom1is6nPQ48MGAASWR1mKxbw365.jpg
https://s5.运维网.com/wyfs02/M02/8D/D8/wKioL1is6mSxJvqUAAPk8B5nLFc525.jpg
  安装证书后,访问测试结果如下:
  如果安装证书后访问网站提示:You don't have permission to access / on this server.
需修改ssl配置文档的权限设定,具体修改内容如下:
#vim /etc/httpd/extra/httpd-ssl.conf
https://s3.运维网.com/wyfs02/M02/8D/DB/wKioL1itLMDip4TWAAIolDuKhSE585.jpg
  https://s4.运维网.com/wyfs02/M00/8D/DB/wKioL1itLCLCTH0AAAGfr41HAHs742.jpg
  

  

  

  

apr-util-1.4.1.tar.gz下载地址:
http://download.chinaunix.net/download.php?id=36061&ResourceID=470
apr-1.4.6.tar.gz下载地址:
http://download.chinaunix.net/download.php?id=37842&ResourceID=470
httpd-2.4.4.tar.gz下载地址:
http://download.csdn.net/download/www476907899/5208979

  
mysql-5.5.54通用二进制版本下载地址:
http://mirrors.sohu.com/mysql/MySQL-5.5/
php-5.4.23.tar.bz2下载地址:
http://mirrors.sohu.com/php/
  libmcrypt-2.5.8.rpm下载地址:
  http://rpm.pbone.net/index.php3/stat/4/idpl/15286582/dir/redhat_el_6/com/libmcrypt-2.5.8-9.el6.x86_64.rpm.html
  libmcrypt-devel-2.5.8.rpm下载地址:
  http://rpmfind.net/linux/rpm2html/search.php?query=libmcrypt-devel(x86-64)
  mhash-devel-0.9.9-2.3.x86_64.rpm下载地址:
  http://rpm.pbone.net/index.php3/stat/4/idpl/21892847/dir/centos_6/com/mhash-devel-0.9.9-2.3.x86_64.rpm.html
  mhash-0.9.9-2.3.x86_64.rpm下载地址:
  http://rpm.pbone.net/index.php3/stat/4/idpl/21892845/dir/centos_6/com/mhash-0.9.9-2.3.x86_64.rpm.html
  xcache-2.0.1.tar.gz下载地址:
  http://xcache.lighttpd.net/wiki/Release-2.0.1
  phpMyAdmin-4.0.10.19-all-languages.tar.gz下载地址:
  https://www.phpmyadmin.net/
  ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz下载地址:
  
  http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
  

  

其它下载链接 **************************************************************
1、Linux MySQL5.5源码安装
http://www.cnblogs.com/ghsea/p/4264696.html
2、Linux环境下安装zend optimizer
http://blog.sina.com.cn/s/blog_6797650b0100vzs5.html



3、ZendOptimizer-3.3.3 下载:

http://www.neatstudio.com/show-1038-1.shtml
ZendOptimizer-3.3.9 下载:
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz(32位)
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz(64位)
4、Zend Optimizer不支持php5.3的解决方案
http://284772894.iteye.com/blog/1920685


  

  




页: [1]
查看完整版本: linux命令:编译安装httpd、mysql、php等LAMP环境xcache缓存PHP