PHP: 脚步编程语言,php解释器
WebApp: 面向对象的特性
Zend:
第一段: 词法分析、语法分析、编译成Opcode;
opcode放置于内存中
第二段: 指定opcode;
PHP 缓存器:
APC
eAccelerator
XCache
PHP解释器-->MySQL, 如何交互?
bash: a.sh
php53-mysql
作为web服务器而言,有一个进程叫做httpd进程,web服务器仅能解释静态内容,图片、各种网页文件、各种CSS样式表等等,只要不需要执行的程序,都由httpd自身来处理,一旦需要用户请求的是PHP脚步的话,httpd本身完成不了这个功能,它必须要借助PHP解释器来执行,前提是告诉httpd一旦有人请求的是这种内容,我们就要调用PHP功能来完成解释这些功能,让httpd跟PHP完成结合的方式有三种,第一CGI的方式,这是最传统的方式,这种方式用的很少,第二种Module(模块)的方式,把PHP直接编译成httpd的模块,它自己不能独立执行,当httpd用到PHP功能的时候,它才会被装载执行,apache是模块化设计,工作在CGI机制,这意味在主机上我们的httpd一旦有用户请求了PHP页面的时候,httpd一定要使用CGI协议启动另外一个独立进程的,这个进程是CGI进程,这个进程本身需要创建起来,然后运行脚步,运行结束以后,结果通过进程间通信的方式返回给httpd进程,CGI进程就结束了,而工作为模块化的时候,httpd进程一旦需要用到PHP功能,只需要将这个模块从磁盘上加载进来,在自身内部运行就可以了,不需要启动一个新进程,这叫模块化方式,所以只需要一个进程就能完成所有功能,而不需要两个进程,第三种方式叫fastcgi/fpm方式,什么叫cgi,它不做成模块,有用户请求相关内容的时候要额外启动另外一个进程来处理脚步,fsatcgi安装一个服务器软件,这个服务器软件自身可以提供能够执行PHP脚本的CGI进程,而且有多个空闲进程,当我们的httpd有人请求动态页面的时候,那么httpd发现请求的是个动态内容,它怎么解释动态内容,用PHP解释器,向服务器请求获取进程执行,这个时候进程不是httpd创建,后端的PHP服务器,对于第三种方式就意味着还要独立安装一个叫做PHP的服务器,必须把PHP做成一个服务器,自己能够启动起来,这里所说的服务器叫做Daemon(守护进程),可以使用service start启动起来,可以监听在某个Socket(套接字)上,默认安装PHP是以模块化方式工作,它不会启动一个服务器,不会监听端口,如果工作在fastcgi模式下就必须监听在一个端口上,默认监听在9000端口上,但无论哪一种方式它都能够让你的httpd去执行PHP脚步,在平时用户请求的是静态内容,不需要执行脚步,httpd本身就是模块化的,它的众多功能都是通过模块实现的,比如用户的认证、基于IP的认证、基于用户的认证也好里面都是模块,所以把PHP做成模块也是可以工作的,但是PHP本身比其他模块复杂的多,所以一般而言,让它做成模块固然很简便管理,但是性能不是特别的好,无论如何就算用户请求了动态内容他它也未必需要跟mysql数据库打交道,如果请求的动态页面里面压根脚本里面就是一堆的指令,跟数据库没有任何关系,不会跟数据库打交道,当用户请求动态内容会交由PHP服务器,而PHP脚步中涉及数据管理功能,而且这个管理功能是放在数据库当中的才会跟数据库打交道,而数据库本身也是个独立的服务器,它可以监听在3306端口上,而且可以通过TCP/IP接受用户请求并响应用户请求的,这也就意味着如果都工作成独立进程,这三个主机可以位于不同的服务器上,只要他们能够通过TCP/IP协议通信,位于同一台主机上和位于不同主机上各有利弊,位于不同主机的时候,它俩的通信都要封装成TCP/IP报文,通过网线发过去才可以,这中间需要涉及到大量的I/O操作,如果网络足够慢的话,事实上它俩直接的性能结合起来可能比较差,放在同一台主机上在自己本机内部就可以完成交互了,这种速度比较快的,所以到底应该分开放还是放在一起,这要看请求规模有多大,如果本身用户一天同时并发的用户也不会超过20个,这三个放在同一台主机没有任何问题,如果非常多的话,只能分层次来实现了,用二层设计还有三层设计,所以整个当中就把前端这个称作叫做web服务器,把中间称作应用程序服务器,应用程序服务器能够接收用户来自前端的请求,而应用程序服务器需要的时候再跟数据库服务器打交道,假如前端并发300个请求进来,是不是就意味着应用程序服务器就能看到这300个请求,不是,不一定都是动态请求,所以这300个请求,如果只有50个是动态的,一个index页面可能有很多图片,这些图片都是静态的,他们都是web对象,事实看在一个页面文件里面,事实它是多个不同的web对象组成的,所以说我们有个文件叫index.php没错,但里面可能包含众多的静态内容,只有封装在php中间的才是PHp脚步,只有这些内容才由应用程序服务器执行,剩下的内容都可以由web服务器自身实现,当然把静态内容交由后面应用程序服务器处理也是可以的,只不过自找麻烦,它又不需要执行,所以一般来讲静态内容都由前端服务器直接处理,只有动态内容才交由后端服务器,所以前端看上不去是300个请求,而能够到达应用程序服务器很可能只有了了的几个,很可能只有50个,比如说,同时这50个动态请求里面也未必都会查数据库,所以数据库服务器所看到的连接请求也有可能只有3两个,如果我们把所有内容都能够在前端完成,这个速度要快的多,同样每一个用户每一个httpd来请求的时候都有一个PHP进程来响应,每一个PHP进程,如果多个用户请求内容一样,怎么办,比如第一个用户请求是index.php里面的一些动态内容交由后端动态来执行,第二个用户也是同样内容让后端第二个进程来执行,这两个进程会共享opcould吗,不会,为了加速,安装xcache,就可以了,所以第一个内容opcould保存在xcache当中,第二个请求同样内容先检查xcache中有没有缓存,如果有就直接拿回来用,就不用再一次编译了,编译的速度比较慢,是需要消耗时间的,所以这就是各种不同的加速机制,静态内容的响应比动态内容要快的多的多,动态内容看起来固然很灵活很好用,但是代价是非常大的;
httpd+php:
CGI
Module
fastcgi
LAMP:
httpd
php5-mysql
mysql-server
编译配置LAMP:
Linux, Apache, MySQL, PHP(Python, Perl)
Apache: ASF(apache软件基金会),httpd, tocat, cloudware
httpd: 2.4.4
php: 5.4.13
MySQL: 5.6.10(rpm, 通用二进制,源码)
LAMP安装顺序:
httpd --> MySQL --> php --> XCache
httpd
apr: Apache Portable Runtime(Apache可移植程序)
apr-util
apr-iconv
rpm包:
/bin, sbin, /usr/bin, /usr/sbin
/lib, /usr/lib
/etc
/usrshare{doc,man}
编译安装:
/usr/local/
bin,sbin
lib
etc
share/{doc,man}
/usr/local/apr/
bin, sbin, lib, includes, etc, man, share/man
arp --> arp-utils --> httpd
MPM:prefork, worker, event 多道处理模块
模块化方式使用MPM
使用哪一种方式,在编译的时候已经确定了,而2.4的时候有个特性叫做可以以模块方式使用MPM,就意味着可以把这三个模块都编译进来,想用那个切换那个就可以,但是这样听起来固然很好,有一个缺陷PHP以模块化方式跟apache结合的时候,如果使用prefork模型PHP很简单,但是如果使用worker或event,我们的PHP必须要编译成zts格式,所以两种格式,使用prefork模型,PHP没关系,而使用worker、event模型跟第一种模型的PHP不一样,所以得编译两次PHP,如果要灵活使用不同模型,而默认编译使用的event模型,因为event性能最好的,所以在2.4编译的时候,默认的MPM是event,不像2.2是prefork;
apache编译安装步骤:
# yum -y install pcre-devel
# tar xf apr-1.4.6.tar.bz2
# cd apr-1.4.6
# ./configure --prefix=/usr/local/apr
# make
# make install
# tar xf apr-util-1.4.1.tar.bz2
# cd apr-util-1.4.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
# tar xf httpd-2.4.4.tar.bz2
# cd httpd-2.4.4
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --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支持动态共享模块,--enable-rewirte支持url重写,--enable-ssl启用ssl功能,--enable-cgi支持cgi,--enable-cgid支持cgid,被线程MPM使用,使用event或worker用MPM需要启用cgid,--enable-modules支持模块,--enable-mods是否启用共享模块,--enable-mpm-shared启用那些MPM,而且以共享方式启用,--with-apr指定apr安装路径,--with-apr-util指定apr-util安装路径,)
# make
# make install
提供SysV服务脚本/etc/rc.d/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(读取functions函数)
if [ -f /etc/sysconfig/httpd ]; then(判定/etc/sysconfig/httpd文件,就把他读进来)
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}(定义变量,如果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(变量pachectl程序路径)
httpd=${HTTPD-/usr/local/apache/bin/httpd}(变量httpd程序路径,有值就使用HTTD的值,如果没有就使用/usr/local/apache/bin/httpd值)
prog=httpd(程序httpd)
pidfile=${PIDFILE-/var/run/httpd.pid}(变量pidfile,有值就使用PIDFILE值,没有使用/var/run/httpd.pid值)
lockfile=${LOCKFILE-/var/lock/subsys/httpd}(lockfile锁文件,有值就使用LOCKFILE值,没有使用/var/lock/subsys/httpd的值)
RETVAL=0
start() {
echo -n $"Starting $prog: "(显示Starting httpd程序)
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS(在这种语言下启动,daemon是functions中提供的函数,以--pidfile=${pidfile}为pid文件,执行http start)
RETVAL=$?(取得上面命令状态返回值)
echo
[ $RETVAL = 0 ] && touch ${lockfile}(成功创建锁文件,并return状态返回值)
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
[root@Smoke ~]# rpm -q apr(查看是否看装apr软件)
apr-1.2.7-11.el5_6.5
[root@Smoke ~]# rpm -qi apr-util(查看apr-util软件相关信息)
Name : apr-util Relocations: (not relocatable)
Version : 1.2.7 Vendor: Red Hat, Inc.
Release : 11.el5_5.2 Build Date: Thu 02 Dec 2010 07:57:18 PM CST
Install Date: Sat 22 Nov 2014 03:55:33 AM CST Build Host: x86-003.build.bos.redhat.com
Group : System Environment/Libraries Source RPM: apr-util-1.2.7-11.el5_5.2.src.rpm
Size : 167764 License: Apache Software License 2.0
Signature : DSA/SHA1, Mon 06 Dec 2010 10:02:14 PM CST, Key ID 5326810137017186
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://apr.apache.org/
Summary : Apache Portable Runtime Utility library
Description :
The mission of the Apache Portable Runtime (APR) is to provide a
free library of C data structures and routines. This library
contains additional utility interfaces for APR; including support
for XML, LDAP, database interfaces, URI parsing and more.
[root@localhost ~]# cd /etc/yum.repos.d/(切换到yum.repos.d目录)
[root@localhost yum.repos.d]# wget ftp://172.16.0.1/pub/gls/server.repo(从外网下载server.repo文件)
[root@localhost yum.repos.d]# yum grouplist(查看安装的软件包组)
Installed Groups:
Administration Tools
Editors
GNOME Desktop Environment
Games and Entertainment
Graphical Internet
Graphics
Legacy Network Server
Legacy Software Development
Legacy Software Support
Mail Server
Network Servers
Office/Productivity
Printing Support
Server Configuration Tools
Sound and Video
System Tools
Text-based Internet
X Window System
Available Groups:
Authoring and Publishing
Cluster Storage
Clustering
DNS Name Server
Development Libraries
Development Tools
Engineering and Scientific
FTP Server
GNOME Software Development
Java Development
KDE (K Desktop Environment)
KDE Software Development
MySQL Database
News Server
OpenFabrics Enterprise Distribution
PostgreSQL Database
Web Server
Windows File Server
X Software Development
Xen
Done
[root@localhost yum.repos.d]# yum -y groupinstall "Development Libraries" "Development Tools"(安装开发库和开发工具,-y所有询问回答yes)
[root@localhost ~]# lftp 172.16.0.1/pub/Source(连接ftp服务器)
cd ok, cwd=/pub/Sources
lftp 172.16.0.1:/pub/Sources> cd new_lamp/(切换到new_lamp目录)
lftp 172.16.0.1:/pub/Sources/new_lamp> mget apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2(下载多个文件apr、apr-util、httpd)
6201013 bytes transferred
Total 3 files transferred
lftp 172.16.0.1:/pub/Sources/new_lamp> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2 install.log install.log.syslog
提示:这个几个软件需要先安装arp,再安装apr-util,因为apr-util依赖于arp;
[root@localhost ~]# date(查看系统时间)
Sat Nov 22 02:47:04 CST 2014
提示:如果系统时间比源码包的时间还要靠前,不然源码包制作时间是在未来的,这样系统就凌乱了;
[root@localhost ~]# hwclock -s(将软件时间同步为硬件时间)
[root@localhost ~]# date(查看系统时间)
Mon Sep 14 10:03:22 CST 2015
[root@localhost ~]# tar xf apr-1.4.6.tar.bz2(解压arp-1.4.6,x解压,f后面跟文件)
[root@localhost ~]# cd apr-1.4.6(切换到apr-1.4.6目录)
[root@localhost apr-1.4.6]# ls(查看当前目录文件及子目录)
apr-config.in apr.pc.in build.conf configure.in helpers libapr.rc memory NWGNUmakefile shmem threadproc
apr.dep apr.spec build-outputs.mk docs include LICENSE misc passwd strings time
apr.dsp atomic CHANGES dso libapr.dep locks mmap poll support user
apr.dsw build config.layout emacs-mode libapr.dsp Makefile.in network_io random tables
apr.mak buildconf configure file_io libapr.mak Makefile.win NOTICE README test
[root@localhost apr-1.4.6]# ./configure --help | less(获取配置帮助并分页显示)
--enable-other-child Enable reliable child processes(是否支持线程)
--disable-ipv6 Disable IPv6 support in APR.(是否禁用ipv6)
提示:默认情况下使用默认选项已经足够使用了;
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr(配置apr,--prefix指定安装路径为/usr/local/apr)
提示:我们用的是rhel 5.8版本,如果使用的是rhel 6.x版本,apr已经更新到1.4了,所以就不需要再编译安装apr了;
[root@localhost apr-1.4.6]# make(编译)
[root@localhost apr-1.4.6]# make install(安装)
提示:对于apr来讲,这个apr除了对apache有用之外,对于系统没有用,专为apache使用的,只要在安装httpd的时候2.4版本的时候告诉它apr在什么地方就可以了,所以这里
不需要输入/bin路径,也不需要输入它的头文件,更不需要输入它的库文件,apache自己会找的,就在编译安装apache的时候告诉它就行了;
[root@localhost apr-1.4.6]# cd(切换到用户家目录)
[root@localhost ~]# tar xf apr-util-1.4.1.tar.bz2(解压apr-util,x解压,f后面跟文件)
[root@localhost ~]# cd apr-util-1.4.1(切换到apr-util-1.4.1目录)
[root@localhost apr-util-1.4.1]# ./configure --help | less(获取配置帮助并分页显示)
--with-apr=PATH prefix for installed APR or the full path to
apr-config(告诉它apr安装目录)
[root@localhost apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/(配置apr-util,--prefix指定安装路径,
--with-apr指定apr安装目录)
[root@localhost apr-util-1.4.1]# make(编译)
[root@localhost apr-util-1.4.1]# make install(安装)
[root@localhost apr-util-1.4.1]# cd(切换到用户家目录)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 install.log
apr-1.4.6 apr-util-1.4.1 httpd-2.4.4.tar.bz2 install.log.syslog
[root@localhost ~]# tar xf httpd-2.4.4.tar.bz2(解压httpd文件,x解压,f后面跟文件)
[root@localhost ~]# cd httpd-2.4.4(切换到httpd-2.4.4目录)
[root@localhost httpd-2.4.4]# ./configure --help | less(获取配置帮助并分页显示)
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2](改变安装路径)
--sysconfdir=DIR read-only single-machine data [PREFIX/etc](指定配置文件路径)
--enable-modules=MODULE-LIST
Space-separated list of modules to enable | "all" |
"most" | "few" | "none" | "reallyall"
--enable-mods-shared=MODULE-LIST
Space-separated list of shared modules to enable |
"all" | "most" | "few" | "reallyall"(是否启用共享模块,all所有,most大多数,few仅有几个,reallyall真是所有)
--enable-mods-static=MODULE-LIST
Space-separated list of static modules to enable |
"all" | "most" | "few" | "reallyall"(静态方式,直接编译进去)
--disable-authn-file file-based authentication control(是否开启基于文件认证)
--enable-authn-dbm DBM-based authentication control(启用那种认证功能)
--enable-authn-anon anonymous user authentication control
--enable-authn-dbd SQL-based authentication control
--enable-so DSO capability. This module will be automatically
enabled unless you build all modules statically.(支持动态共享模块,如果不支持PHP将无法以模块方式apache结合起来)
--enable-ssl SSL/TLS support (mod_ssl)(启用ssl功能)
--enable-deflate Deflate transfer encoding support(压缩机制,节约带宽)
--enable-expires Expires header control(过期首部控制)
--enable-proxy-fcgi Apache proxy FastCGI module. Requires and is enabled
by --enable-proxy.(如果打算apache跟php结合使用fastcgi方式工作需要启用)
--enable-mpms-shared=MPM-LIST
Space-separated list of MPM modules to enable for
dynamic loading. MPM-LIST=list | "all"(定义启用那些MPM,而且以共享方式启用,all所有)
--with-mpm=MPM Choose the process model for Apache to use by
default. MPM={event|worker|prefork|winnt} This will
be statically linked as the only available MPM
unless --enable-mpms-shared is also specified.(明确说明那一个为默认,如果不指定系统会自己找一个为默认,而默认一般是ev
ent)
--enable-cgid CGI scripts. Enabled by default with threaded MPMs(被线程MPM使用,使用event或worker的MPM需要启用cgid)
--enable-cgi CGI scripts. Enabled by default with non-threaded
MPMs(支持cgi)
--enable-rewrite rule based URL manipulation(支持url重写)
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --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支持动态共享模块,--enable-rewirte支持
url重写,--enable-ssl启用ssl功能,--enable-cgi支持cgi,--enable-cgid支持cgid,被线程MPM使用,使用event或worker用MPM需要启用cgid,--enable-modul
es支持模块,--enable-mods是否启用共享模块,--enable-mpm-shared启用那些MPM,而且以共享方式启用,--with-apr指定apr安装路径,--with-apr-util指定apr-
util安装路径,)
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
提示:报错,没有pcre模块;
[root@localhost httpd-2.4.4]# yum -y install pcre-devel(通过yum安装pcre-devel)
[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --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支持动态共享模块,--enable-rewirte支持ur
l重写,--enable-ssl启用ssl功能,--enable-cgi支持cgi,--enable-cgid支持cgid,被线程MPM使用,使用event或worker用MPM需要启用cgid,--enable-modules
支持模块,--enable-mods是否启用共享模块,--enable-mpm-shared启用那些MPM,而且以共享方式启用,--with-apr指定apr安装路径,--with-apr-util指定apr-uti
l安装路径,)
[root@localhost httpd-2.4.4]# make(编译)
[root@localhost httpd-2.4.4]# make install(安装)
提示:web服务器是受selinux控制的,如果此时启动了selinux,无论如何httpd可能启动不了,所以建议一定要查看selinux是否关闭;
[root@localhost httpd-2.4.4]# getenforce(查看selinux状态)
Permissive
[root@localhost httpd-2.4.4]# setenforce 0(关闭selinux)
[root@localhost httpd-2.4.4]# vim /etc/selinux/config(编辑selinux配置文件)
SELINUX=permissive(关闭selinux)
[root@localhost httpd-2.4.4]# getenforce(查看selinux状态)
Permissive
[root@localhost httpd-2.4.4]# cd /usr/local/apache/(切换到/usr/local/apache目录)
[root@localhost apache]# ls(查看当前目录文件及子目录)
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost apache]# ls /etc/init.d/(查看/etc/init.d目录文件及子目录)
acpid cpuspeed hidd killall netfs psacct saslauthd wpa_supplicant
anacron crond hplip krb524 netplugd rawdevices sendmail xfs
apmd cups ip6tables kudzu network rdisc setroubleshoot xinetd
atd cups-config-daemon ipmi lvm2-monitor NetworkManager readahead_early single ypbind
auditd dnsmasq iptables mcstrans nfs readahead_later smartd yum-updatesd
autofs dund irda mdmonitor nfslock restorecond sshd
avahi-daemon firstboot irqbalance mdmpd nscd rhnsd svnserve
avahi-dnsconfd functions iscsi messagebus ntpd rhsmcertd syslog
bluetooth gpm iscsid microcode_ctl pand rpcgssd vncserver
capi haldaemon isdn multipathd pcscd rpcidmapd wdaemon
conman halt kdump netconsole portmap rpcsvcgssd winbind
提示:/etc/init.d目录下没有httpd启动脚步,只有rpm安装的才有这个脚步;
[root@localhost apache]# ls(查看当前目录文件及子目录)
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost apache]# pwd(查看当前所处路径)
/usr/local/apache
[root@localhost apache]# ls(查看当前目录文件及子目录)
bin build cgi-bin error htdocs icons include logs man manual modules
提示:在当前目录bin/apachectl脚步;
[root@localhost apache]# file bin/apachectl(查看apachectl文件类型)
bin/apachectl: Bourne shell script text executable
[root@localhost apache]# vim bin/apachectl(编辑apachectl文件)
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Apache control script designed to allow an easy command line interface
# to controlling Apache. Written by Marc Slemko, 1997/08/23
#
# The exit codes returned are:
# XXX this doc is no longer correct now that the interesting
# XXX functions are handled by httpd
# 0 - operation completed successfully
# 1 -
# 2 - usage error
# 3 - httpd could not be started
# 4 - httpd could not be stopped
# 5 - httpd could not be started during a restart
# 6 - httpd could not be restarted during a restart
# 7 - httpd could not be restarted during a graceful restart
# 8 - configuration syntax error
#
# When multiple arguments are given, only the error from the _last_
# one is reported. Run "apachectl help" for usage info
#
ACMD="$1"
ARGV="$@"
#
# |||||||||||||||||||| START CONFIGURATION SECTION ||||||||||||||||||||
# -------------------- --------------------
#
# the path to your httpd binary, including options if necessary
HTTPD='/usr/local/apache/bin/httpd'
#
# pick up any necessary environment variables
if test -f /usr/local/apache/bin/envvars; then
. /usr/local/apache/bin/envvars
fi
#
# a command that outputs a formatted text version of the HTML at the
# url given on the command line. Designed for lynx, however other
# programs may work.
LYNX="links -dump"
#
# the URL to your server's mod_status status page. If you do not
# have one, then status and fullstatus will not work.
STATUSURL="http://localhost:80/server-status"
#
# Set this variable to a command that increases the maximum
# number of file descriptors allowed per child process. This is
# critical for configurations that use many file descriptors,
# such as mass vhosting, or a multithreaded server.
ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"
# -------------------- --------------------
# |||||||||||||||||||| END CONFIGURATION SECTION ||||||||||||||||||||
# Set the maximum number of file descriptors allowed per child process.
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
$ULIMIT_MAX_FILES
fi
ERROR=0
if [ "x$ARGV" = "x" ] ; then
ARGV="-h"
fi
case $ACMD in
start|stop|restart|graceful|graceful-stop)
$HTTPD -k $ARGV
ERROR=$?
;;
startssl|sslstart|start-SSL)
echo The startssl option is no longer supported.
echo Please edit httpd.conf to include the SSL configuration settings
echo and then use "apachectl start".
ERROR=2
;;
configtest)
$HTTPD -t
ERROR=$?
;;
status)
$LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
;;
fullstatus)
$LYNX $STATUSURL
;;
*)
$HTTPD "$@"
ERROR=$?
esac
exit $ERROR
[root@localhost apache]# bin/apachectl start(启动httpd)
[root@localhost apache]# netstat -tnlp(查看系统服务器,-t代表tcp,-n以数字显示,-l监听端口,-p显示协议名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3494/./hpiod
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3175/portmap
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN 3214/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3515/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3527/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3564/sendmail
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4478/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 4516/sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 11123/sshd
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3499/python
tcp 0 0 :::80 :::* LISTEN 28739/httpd
tcp 0 0 :::22 :::* LISTEN 3515/sshd
tcp 0 0 ::1:6010 :::* LISTEN 4478/sshd
tcp 0 0 ::1:6011 :::* LISTEN 4516/sshd
tcp 0 0 ::1:6012 :::* LISTEN 11123/sshd
测试:通过windows的ie浏览器访问172.16.100.1;

[root@localhost apache]# ls(查看当前目录文件及子目录) bin(二进制程序) build(编译时的目录) cgi-bin(执行cgi程序存放位置) error(错误信息) htdocs(网页文件位置) icons(图标) include(头文件 ,二次开发使用) logs(日志) man(man帮助) manual(手册) modules(模块) [root@localhost apache]# ls bin/(查看bin目录文件及子目录) ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs 提示:这个目录不在PATH环境变量里面; [root@localhost apache]# pwd(显示当前所处路径) /usr/local/apache [root@localhost apache]# ls htdocs/(查看htdocs目录文件及子目录) index.html [root@localhost apache]# vim htdocs/index.html(编辑index.html文件) <html><body><h1>It works, my apache!</h1></body></html>
测试:通过windows的ie浏览器访问172.16.100.1;

[root@localhost apache]# ls logs/(查看logs目录文件及子目录)
access_log error_log httpd.pid
提示:每个进程都有一个pid文件,一般pid文件放在/var/run目录;
[root@localhost apache]# ls /var/run/(查看当前目录文件及子目录)
acpid.socket crond.pid hpiod.pid mdadm pcscd.pub sendmail.pid utmp
atd.pid cron.reboot hpiod.port mdmpd pm setrans winbindd
audispd_events cups hpssd.pid messagebus.pid ppp setroubleshoot wpa_supplicant
auditd.pid cupsd.pid hpssd.port netreport restorecond.pid setroubleshootd.pid xfs.pid
autofs.fifo-misc dbus iscsid.pid NetworkManager rhsm sm-client.pid xinetd.pid
autofs.fifo-net dhclient-eth1.pid iscsiuio.pid nscd rpc.statd.pid sshd.pid
avahi-daemon gpm.pid klogd.pid pcscd.comm saslauthd sudo
console haldaemon.pid lvm pcscd.pid sdp syslogd.pid
[root@localhost apache]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
#PidFile "/var/run/httpd.pid"(更改apache运行Pid文件路径)
[root@localhost apache]# bin/apachectl stop(停止httpd服务)
[root@localhost apache]# netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p显示服务名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3494/./hpiod
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3175/portmap
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN 3214/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3515/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3527/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3564/sendmail
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4478/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 4516/sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 11123/sshd
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3499/python
tcp 0 0 :::22 :::* LISTEN 3515/sshd
tcp 0 0 ::1:6010 :::* LISTEN 4478/sshd
tcp 0 0 ::1:6011 :::* LISTEN 4516/sshd
tcp 0 0 ::1:6012 :::* LISTEN 11123/sshd
提示:80端口没有了,说明关闭了;
[root@localhost apache]# ls logs/(查看logs目录文件及子目录)
access_log error_log
提示:apache进程关闭pid文件没有了;
[root@localhost apache]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
PidFile "/var/run/httpd.pid"(启用pid文件目录)
[root@localhost apache]# bin/apachectl start(启用httpd服务)
[root@localhost apache]# netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p显示服务名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3494/./hpiod
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3175/portmap
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN 3214/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3515/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3527/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3564/sendmail
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 4478/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 4516/sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 11123/sshd
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3499/python
tcp 0 0 :::80 :::* LISTEN 28923/httpd
tcp 0 0 :::22 :::* LISTEN 3515/sshd
tcp 0 0 ::1:6010 :::* LISTEN 4478/sshd
tcp 0 0 ::1:6011 :::* LISTEN 4516/sshd
tcp 0 0 ::1:6012 :::* LISTEN 11123/sshd
提示:80端口监听了;
[root@localhost apache]# ls logs/(查看logs目录文件及子目录)
access_log error_log
提示:pid文件没有了;
[root@localhost apache]# ls /var/run/(查看/var/run目录文件及子目录)
acpid.socket crond.pid hpiod.pid lvm pcscd.pid sdp syslogd.pid
atd.pid cron.reboot hpiod.port mdadm pcscd.pub sendmail.pid utmp
audispd_events cups hpssd.pid mdmpd pm setrans winbindd
auditd.pid cupsd.pid hpssd.port messagebus.pid ppp setroubleshoot wpa_supplicant
autofs.fifo-misc dbus httpd.pid netreport restorecond.pid setroubleshootd.pid xfs.pid
autofs.fifo-net dhclient-eth1.pid iscsid.pid NetworkManager rhsm sm-client.pid xinetd.pid
avahi-daemon gpm.pid iscsiuio.pid nscd rpc.statd.pid sshd.pid
console haldaemon.pid klogd.pid pcscd.comm saslauthd sudo
提示:httpd.pid文件在/var/run目录;
[root@localhost apache]# vim /etc/init.d/httpd(编辑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
[root@localhost apache]# chmod +x /etc/init.d/httpd(给httpd执行权限)
[root@localhost apache]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost apache]# service httpd status(显示httpd服务运行状态)
httpd (pid 29081) is running...
[root@localhost apache]# chkconfig --add httpd(将httpd添加到服务列表,让以后开机自动启动)
[root@localhost apache]# chkconfig --list httpd(显示httpd在系统不同运行级别启动情况)
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
提示:默认在所有系统运行级别都是off状态;
[root@localhost apache]# chkconfig --level 35 httpd on(让httpd在35级别下开机自动启动)
[root@localhost apache]# chkconfig --list httpd(显示httpd在系统不同运行级别启动情况)
httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
提示:此时httpd配置结束,但是此时apachectl命令无法直接执行;
[root@localhost apache]# cd(切换到用户家目录)
[root@localhost ~]# vim /etc/profile.d/httpd.sh(编辑httpd.sh脚步)
export PATH=$PATH:/usr/local/apache/bin
[root@localhost ~]# echo $PATH(显示命令环境变量)
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/apache/bin:/root/bin
提示:需要重写登录,有/usr/local/apache/bin目录;
[root@localhost ~]# httpd -t(测试httpd配置文件语法)
Syntax OK
[root@localhost ~]# httpd -l(列出模型)
Compiled in modules:
core.c
mod_so.c
http_core.c
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
LoadModule mpm_event_module modules/mod_mpm_event.so(默认使用event模型)
/LoadModule
[root@localhost ~]# httpd -M(查看httpd加载的模块)
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_event_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
提示:现在是event模型共享模块;
[root@localhost ~]vim /etc/httpd/httpd.conf(编辑httpd主配置文件)
#LoadModule mpm_event_module modules/mod_mpm_event.so(注释event模型)
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so(启用prefork模型)
[root@localhost ~]# ls /usr/local/apache/modules/(查看/usr/local/apache/modules目录文件及子目录)
httpd.exp mod_authz_groupfile.so mod_expires.so mod_proxy_balancer.so mod_setenvif.so
mod_access_compat.so mod_authz_host.so mod_ext_filter.so mod_proxy_connect.so mod_slotmem_shm.so
mod_actions.so mod_authz_owner.so mod_file_cache.so mod_proxy_express.so mod_socache_dbm.so
mod_alias.so mod_authz_user.so mod_filter.so mod_proxy_fcgi.so mod_socache_memcache.so
mod_allowmethods.so mod_autoindex.so mod_headers.so mod_proxy_ftp.so mod_socache_shmcb.so
mod_auth_basic.so mod_buffer.so mod_include.so mod_proxy_http.so mod_speling.so
mod_auth_digest.so mod_cache_disk.so mod_info.so mod_proxy_scgi.so mod_ssl.so
mod_auth_form.so mod_cache.so mod_lbmethod_bybusyness.so mod_proxy.so mod_status.so
mod_authn_anon.so mod_cgid.so mod_lbmethod_byrequests.so mod_ratelimit.so mod_substitute.so
mod_authn_core.so mod_cgi.so mod_lbmethod_bytraffic.so mod_remoteip.so mod_unique_id.so
mod_authn_dbd.so mod_dav_fs.so mod_lbmethod_heartbeat.so mod_reqtimeout.so mod_unixd.so
mod_authn_dbm.so mod_dav.so mod_log_config.so mod_request.so mod_userdir.so
mod_authn_file.so mod_dbd.so mod_log_debug.so mod_rewrite.so mod_version.so
mod_authn_socache.so mod_deflate.so mod_logio.so mod_sed.so mod_vhost_alias.so
mod_authz_core.so mod_dir.so mod_mime.so mod_session_cookie.so
mod_authz_dbd.so mod_dumpio.so mod_negotiation.so mod_session_dbd.so
mod_authz_dbm.so mod_env.so mod_proxy_ajp.so mod_session.so
[root@localhost ~]# httpd -t(查看httpd主配置文件语法)
[root@localhost apache]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost ~]# httpd -l(列出模型)
Compiled in modules:
core.c
mod_so.c
http_core.c
[root@localhost ~]# httpd -M(查看httpd加载的模块)
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_prefork_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
提示:现在是prefork模型;
httpd 2.4新特性:
1、MPM可于运行时装载;
--enable-mpms-shared=all --with-mpm=event
2、Event MPM
3、异步读写
4、在每模块及每目录上指定日志级别;
5、每请求配置;<If>, <ElseIf>, <Else>;
6、增强的表达式分析器;
7、毫秒级的KeepAlive Timeout;
8、基于域名的虚拟主机不再需要NameVirtualHost指令;
9、降低了内存占用;
10、支持在配置文件中使用自定义变量;
--enable-modules=most
新增加的模块:
mod_proxy_fcgi
mod_proxy_scgi
mod_proxy_express
mod_remoteip
mod_session
mod_ratelimit
mod_request
等等;
对于基于IP的访问控制
Order allow,deny
allow from all
2.4中不再支持此方法
2.4使用Require user
Require user USERNAME
Require group GRPNAME
Require ip IPADDR
Require not ip IPADDR
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
DOMAIN
www.magedu.com
.magedu.com
允许所有主机访问:
Require all granted
拒绝所有主机访问:
Require all deny
apr --> apr-util --> httpd --> MySQl
MySQL: 配置文件格式,集中式配置文件,可以为多个程序提供配置;
[mysql](客户端配置文件)
[mysqld](服务器端配置文件)
[client](所有客户端程序都生效)
/etc/my.cnf --> /etc/mysql/my.cnf --> $BASEDIR/my.cnf --> $DATADIR/my.cnf --> ~/.my.cnf(mysql配置文件,找配置文件顺序,找四处配置文件,配置冲突,以最后一个为准,后一个覆盖前一个,就算没有配置文件mysql也能运行,因为他的很多配置都有默认定义)
MySQL服务器维护了两类变量:
服务器变量:使用参数可以定义、改变mysql服务器的工作状态,就是在/etc/my.cnf配置文件中提供那些指令;
定义MySQL服务器运行特性
SHOW GLOBAL VARIABLES [LIKE 'STRING'];
状态变量:
保存了MySQL服务器运行统计数据
SHOW GLOBAL STATUS [LIKE 'STRING'];
MySQL通配符:
_: 任意单个字符
%: 任意长度任意字符
php53-mbstring(多字节string,用来支持中文,一个字节能表示字符的语言)
编译安装php-5.4.13
首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp。
# tar xf php-5.4.13.tar.bz2
# cd php-5.4.13
# ./configure --prefix=/usr/local/php(安装目录) --with-mysql=/usr/local/mysql(mysql路径) --with-openssl(支持openssl功能) --with-mysqli=/usr/local/mysql/bin/mysql_config(mysql另外一种让php跟mysql交互接口) --enable-mbstring(支持多字节字符,用于支持中文) --with-freetype-dir(支持freetype功能,freetype引用字体库) --with-jpeg-dir(支持jpeg图片) --with-png-dir(支持png图片) --with-zlib(zlib互联网通用压缩库,让数据文件先压缩再传送,节约带宽) --with-libxml-dir=/usr(xml扩展标记语言,现在众多的系统交互使用xml,xml库路径) --enable-xml(支持xml) --enable-sockets(支持基于套接字通信) --with-apxs2=/usr/local/apache/bin/apxs(基于apxs钩子实现php编译成apache模块) --with-mcrypt(支持加密) --with-config-file-path=/etc(php配置文件路径) --with-config-file-scan-dir=/etc/php.d(php配置文件包含的片段配置文件) --with-bz2(压缩库) --enable-maintainer-zts(此项使用取决于apache的mpm是什么类型,apache如果使用prefork,如果apache使用event或worker加这项,如果apache以线程工作就必须要编译成这种格式)
编译成fastcgi模型:
--with-apxs2=/usr/local/apache/bin/apxs(将这项更改为--enable-fpm)
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make
# make test
# make intall
PHP配置文件目录:
/etc/php.ini
/etc/php.d/*.ini
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2 install.log.syslog
apr-1.4.6 apr-util-1.4.1 httpd-2.4.4 install.log
[root@localhost ~]# lftp 172.16.0.1/pub/Sources(连接ftp服务器)
cd ok, cwd=/pub/Sources
lftp 172.16.0.1/pub/Sources> cd mysql-5.5/(切换到mysql-5.5目录)
lftp 172.16.0.1/pub/Sources/mysql-5.5> get mysql-5.5.28-linux2.6-i686.tar.gz(下载mysql-5.5.28)
179907710 bytes transferred in 4 seconds (39.12M/s)
lftp 172.16.0.1/pub/Sources/mysql-5.5> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2 install.log.syslog
apr-1.4.6 apr-util-1.4.1 httpd-2.4.4 install.log mysql-5.5.28-linux2.6-i686.tar.gz
[root@localhost ~]# ll -h(查看当前目录文件详细信息,并做单位换算)
total 178M
-rw------- 1 root root 1.1K Nov 22 2014 anaconda-ks.cfg
drwxr-sr-x 26 5000 10001 4.0K Sep 15 14:25 apr-1.4.6
-rw-r--r-- 1 root root 768K Nov 22 2014 apr-1.4.6.tar.bz2
drwxr-xr-x 20 501 games 4.0K Sep 15 14:29 apr-util-1.4.1
-rw-r--r-- 1 root root 621K Nov 22 2014 apr-util-1.4.1.tar.bz2
drwxr-xr-x 12 501 games 4.0K Sep 15 14:32 httpd-2.4.4
-rw-r--r-- 1 root root 4.6M Nov 22 2014 httpd-2.4.4.tar.bz2
-rw-r--r-- 1 root root 28K Nov 22 2014 install.log
-rw-r--r-- 1 root root 3.6K Nov 22 2014 install.log.syslog
-rw-r--r-- 1 root root 172M Sep 15 15:44 mysql-5.5.28-linux2.6-i686.tar.gz
[root@localhost ~]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local(解压mysql-5.5.28,x解压,f后面跟文件名,-C更改解压目录)
注意:mysql-5.5.28是通用二进制格式,编译好的,直接解压就可以使用,但是需要注意的是我们要求这个解压包必须要位于/usr/local目录下,这是官方要求,并且目录名
称还得叫mysql才行,创建链接是最好的,不要改变它的原有名称,这样通过mysql或原有名称也能找到它,原有名称包含版本号、平台都会保留,容易识别正在使用的是什么版本的;
[root@localhost ~]# cd /usr/local/(切换到/usr/local目录)
[root@localhost local]# ls(查看当前目录文件及子目录)
apache apr apr-util bin etc games include lib libexec mysql-5.5.28-linux2.6-i686 sbin share src
[root@localhost local]# ln -sv mysql-5.5.28-linux2.6-i686/ mysql(给mysql-5.5.28创建软连接叫mysql,-s软连接,-v显示创建过程)
create symbolic link `mysql' to `mysql-5.5.28-linux2.6-i686/'
[root@localhost local]# ll(查看当前目录文件及子目录详细信息)
total 108
drwxr-xr-x 13 root root 4096 Sep 15 14:35 apache
drwxr-xr-x 6 root root 4096 Sep 15 14:27 apr
drwxr-xr-x 5 root root 4096 Sep 15 14:29 apr-util
drwxr-xr-x 2 root root 4096 Oct 1 2009 bin
drwxr-xr-x 2 root root 4096 Oct 1 2009 etc
drwxr-xr-x 2 root root 4096 Oct 1 2009 games
drwxr-xr-x 2 root root 4096 Oct 1 2009 include
drwxr-xr-x 2 root root 4096 Oct 1 2009 lib
drwxr-xr-x 2 root root 4096 Oct 1 2009 libexec
lrwxrwxrwx 1 root root 27 Sep 15 15:53 mysql -> mysql-5.5.28-linux2.6-i686/
drwxr-xr-x 13 root root 4096 Sep 15 15:49 mysql-5.5.28-linux2.6-i686
drwxr-xr-x 2 root root 4096 Oct 1 2009 sbin
drwxr-xr-x 4 root root 4096 Nov 22 2014 share
drwxr-xr-x 2 root root 4096 Oct 1 2009 src
[root@localhost local]# cd mysql(切换到mysql目录)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 root root 4096 Sep 15 15:49 bin
-rw-r--r-- 1 7161 wheel 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 root root 4096 Sep 15 15:49 data
drwxr-xr-x 2 root root 4096 Sep 15 15:49 docs
drwxr-xr-x 3 root root 4096 Sep 15 15:49 include
-rw-r--r-- 1 7161 wheel 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 Sep 15 15:49 lib
drwxr-xr-x 4 root root 4096 Sep 15 15:49 man
drwxr-xr-x 10 root root 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 7161 wheel 2552 Aug 29 2012 README
drwxr-xr-x 2 root root 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 root root 4096 Sep 15 15:49 share
drwxr-xr-x 4 root root 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 root root 4096 Sep 15 15:49 support-files
提示:属主属组比较独特,要想初始化安装mysql的使用mysql用户mysql组;
[root@localhost mysql]# groupadd -r -g 306 mysql(创建系统组mysql,-r系统组,-g指定组id)
[root@localhost mysql]# useradd -g 306 -r -u 306 mysql(创建系统用户mysql,-g指定加入组,-r系统用户,-u指定uid)
[root@localhost mysql]# id mysql(查看mysql用户信息)
uid=306(mysql) gid=306(mysql) groups=306(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@localhost mysql]# ls /home/(查看/home目录文件及子目录)
Smoke
[root@localhost mysql]# grep mysql /etc/passwd(显示passwd文件包含mysql字符串的行)
mysql:x:306:306::/home/mysql:/bin/bash
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 root root 4096 Sep 15 15:49 bin
-rw-r--r-- 1 7161 wheel 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 root root 4096 Sep 15 15:49 data
drwxr-xr-x 2 root root 4096 Sep 15 15:49 docs
drwxr-xr-x 3 root root 4096 Sep 15 15:49 include
-rw-r--r-- 1 7161 wheel 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 Sep 15 15:49 lib
drwxr-xr-x 4 root root 4096 Sep 15 15:49 man
drwxr-xr-x 10 root root 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 7161 wheel 2552 Aug 29 2012 README
drwxr-xr-x 2 root root 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 root root 4096 Sep 15 15:49 share
drwxr-xr-x 4 root root 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 root root 4096 Sep 15 15:49 support-files
提示:INSTALL-BINARY文件中明确说明了安装步骤;
[root@localhost mysql]# less INSTALL-BINARY(分页显示INSTALL-BINARY文件内容)
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 root root 4096 Sep 15 15:49 bin
-rw-r--r-- 1 7161 wheel 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 root root 4096 Sep 15 15:49 data
drwxr-xr-x 2 root root 4096 Sep 15 15:49 docs
drwxr-xr-x 3 root root 4096 Sep 15 15:49 include
-rw-r--r-- 1 7161 wheel 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 Sep 15 15:49 lib
drwxr-xr-x 4 root root 4096 Sep 15 15:49 man
drwxr-xr-x 10 root root 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 7161 wheel 2552 Aug 29 2012 README
drwxr-xr-x 2 root root 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 root root 4096 Sep 15 15:49 share
drwxr-xr-x 4 root root 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 root root 4096 Sep 15 15:49 support-files
[root@localhost mysql]# chown -R mysql.mysql /usr/local/mysql/*(更改/usr/loca/mysql目录下所有文件属主属组为mysql,-R递归更改)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 bin
-rw-r--r-- 1 mysql mysql 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 data
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 include
-rw-r--r-- 1 mysql mysql 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 man
drwxr-xr-x 10 mysql mysql 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 mysql mysql 2552 Aug 29 2012 README
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 mysql mysql 4096 Sep 15 15:49 share
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 support-files
[root@localhost mysql]# ls scripts/(查看scriptes目录文件及子目录)
mysql_install_db
提示:mysql_install_db脚步用于初始化;
[root@localhost mysql]# scripts/mysql_install_db --help(查看mysql_install_db文件帮助)
Usage: scripts/mysql_install_db [OPTIONS]
--basedir=path The path to the MySQL installation directory.
--builddir=path If using --srcdir with out-of-directory builds, you
will need to set this to the location of the build
directory where built files reside.
--cross-bootstrap For internal use. Used when building the MySQL system
tables on a different host than the target.
--datadir=path The path to the MySQL data directory.(数据目录,使用rpm安装保存到/var/lib/mysql,解压装在当前目录下data)
--defaults-extra-file=name
Read this file after the global files are read.
--defaults-file=name Only read default options from the given file name.
--force Causes mysql_install_db to run even if DNS does not
work. In that case, grant table entries that normally
use hostnames will use IP addresses.
--help Display this help and exit.
--ldata=path The path to the MySQL data directory. Same as --datadir.
--no-defaults Don't read default options from any option file.
--rpm For internal use. This option is used by RPM files
during the MySQL installation process.
--skip-name-resolve Use IP addresses rather than hostnames when creating
grant table entries. This option can be useful if
your DNS does not work.
--srcdir=path The path to the MySQL source directory. This option
uses the compiled binaries and support files within the
source tree, useful for if you don't want to install
MySQL yet and just want to create the system tables.
--user=user_name The login username to use for running mysqld. Files
and directories created by mysqld will be owned by this
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.(以那个用户身份进行初始化)
All other options are passed to the mysqld program
[root@localhost mysql]# ls -l(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 bin
-rw-r--r-- 1 mysql mysql 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 data
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 include
-rw-r--r-- 1 mysql mysql 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 man
drwxr-xr-x 10 mysql mysql 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 mysql mysql 2552 Aug 29 2012 README
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 mysql mysql 4096 Sep 15 15:49 share
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 support-files
提示:使用解压安装mysql数据装在当前目录下data,一般建议放在独立分区,而且是独立逻辑卷上;
[root@localhost mysql]# fdisk /dev/sda(管理磁盘分区,进入交互模式)
The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p(显示当前分区情况)
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 2755 1052257+ 82 Linux swap / Solaris
Command (m for help): n(新建分区)
Command action
e extended
p primary partition (1-4)
e(扩展分区)
Selected partition 4(分区号)
First cylinder (2756-6527, default 2756):
Using default value 2756
Last cylinder or +size or +sizeM or +sizeK (2756-6527, default 6527):
Using default value 6527
Command (m for help): n(新建分区)
First cylinder (2756-6527, default 2756):
Using default value 2756
Last cylinder or +size or +sizeM or +sizeK (2756-6527, default 6527): +20G(创建20G分区)
Command (m for help): t(更改分区类型)
Partition number (1-5): 5(分区号)
Hex code (type L to list codes): 8e(类型为LVM)
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): p(显示当前分区情况)
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 2755 1052257+ 82 Linux swap / Solaris
/dev/sda4 2756 6527 30298590 5 Extended
/dev/sda5 2756 5188 19543041 8e Linux LVM
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.
Syncing disks.
[root@localhost mysql]# partprobe /dev/sda(让内核重读分区表)
[root@localhost mysql]# pvcreate /dev/sda5(将/dev/sda5创建为PV物理卷)
Writing physical volume data to disk "/dev/sda5"
Physical volume "/dev/sda5" successfully created
[root@localhost mysql]# vgcreate myvg /dev/sda5(创建/dev/sda5创建为卷组)
Volume group "myvg" successfully created
[root@localhost mysql]# lvcreate -n mydata -L 5G myvg(创建LV逻辑卷,-L大小为5G,-n名字mydata)
Logical volume "mydata" created
[root@localhost mysql]# lvs(查看系统上LV逻辑卷信息)
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mydata myvg -wi-a- 5.00G
[root@localhost mysql]# mke2fs -j /dev/myvg/mydata(将/dev/myvg/mydata格式化为ext3类型文件系统,-j带日志文件系统)
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost mysql]# mkdir /mydata(创建mydata目录)
[root@localhost mysql]# vim /etc/fstab(编辑开机自动挂载配置文件)
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/myvg/mydata /mydata ext3 defaults 0 0
[root@localhost mysql]# mount -a(挂载/etc/fstab文件中所有文件系统)
[root@localhost mysql]# mount(查看系统所有挂载的文件系统)
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sr0 on /media type iso9660 (ro)
/dev/mapper/myvg-mydata on /mydata type ext3 (rw)
[root@localhost mysql]# mkdir /mydata/data(创建data目录)
[root@localhost mysql]# ll /mydata/(查看/mydata目录文件及子目录详细信息)
total 24
drwxr-xr-x 2 root root 4096 Sep 15 16:54 data
drwx------ 2 root root 16384 Sep 15 16:38 lost+found
[root@localhost mysql]# chown -R mysql.mysql /mydata/data/(将data目录属主属组改为mysql,-R递归更改)
[root@localhost mysql]# ll /mydata/(查看/mydata目录文件及子目录详细信息)
total 24
drwxr-xr-x 2 mysql mysql 4096 Sep 15 16:54 data
drwx------ 2 root root 16384 Sep 15 16:38 lost+found
[root@localhost mysql]# chmod o-rx /mydata/data/(去掉data目录其他用户的读执行权限)
[root@localhost mysql]# ll /mydata/(查看/mydata目录文件及子目录详细信息)
total 24
drwxr-x--- 2 mysql mysql 4096 Sep 15 16:54 data
drwx------ 2 root root 16384 Sep 15 16:38 lost+found
[root@localhost mysql]# ls -ld /mydata/data/(查看data目录本身详细信息,-d显示目录本身)
drwxr-x--- 2 mysql mysql 4096 Sep 15 16:54 /mydata/data/
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/(初始化mysql,--user初始化用户,--datadir指定数据文
件存放位置)
Installing MySQL system tables...
OK
Filling help tables...
OK
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 localhost.localdomain 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 with the ./bin/mysqlbug script!
[root@localhost mysql]# pwd(查看当前所处的目录)
/usr/local/mysql
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 bin
-rw-r--r-- 1 mysql mysql 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 data
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 include
-rw-r--r-- 1 mysql mysql 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Sep 15 15:49 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 man
drwxr-xr-x 10 mysql mysql 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 mysql mysql 2552 Aug 29 2012 README
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 mysql mysql 4096 Sep 15 15:49 share
drwxr-xr-x 4 mysql mysql 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 mysql mysql 4096 Sep 15 15:49 support-files
提示:初始化完成以后,/user/local/mysql目录下的目录及文件不要给mysql用户,因为一旦攻破mysql进程,它将获得整个文件的所有权限,所以一般而言将属主还是改回
root用户;
[root@localhost mysql]# chown -R root /usr/local/mysql/*(更改/usr/loca/mysql目录下所有文件属主为root,-R递归)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 root mysql 4096 Sep 15 15:49 bin
-rw-r--r-- 1 root mysql 17987 Aug 29 2012 COPYING
drwxr-xr-x 4 root mysql 4096 Sep 15 15:49 data
drwxr-xr-x 2 root mysql 4096 Sep 15 15:49 docs
drwxr-xr-x 3 root mysql 4096 Sep 15 15:49 include
-rw-r--r-- 1 root mysql 7604 Aug 29 2012 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Sep 15 15:49 lib
drwxr-xr-x 4 root mysql 4096 Sep 15 15:49 man
drwxr-xr-x 10 root mysql 4096 Sep 15 15:49 mysql-test
-rw-r--r-- 1 root mysql 2552 Aug 29 2012 README
drwxr-xr-x 2 root mysql 4096 Sep 15 15:49 scripts
drwxr-xr-x 27 root mysql 4096 Sep 15 15:49 share
drwxr-xr-x 4 root mysql 4096 Sep 15 15:49 sql-bench
drwxr-xr-x 2 root mysql 4096 Sep 15 15:49 support-files
提示:默认数据目录在data,假如没有改到/mydata目录,也就意味着数据目录还是这里,而数据目录mysql用户必须要有写权限,所以还需要姜data目录改回mysql;
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
[root@localhost mysql]# ls /etc/init.d/(查看/etc/init.d目录文件及子目录)
acpid cpuspeed hidd kdump netconsole portmap rpcsvcgssd winbind
anacron crond hplip killall netfs psacct saslauthd wpa_supplicant
apmd cups httpd krb524 netplugd rawdevices sendmail xfs
atd cups-config-daemon ip6tables kudzu network rdisc setroubleshoot xinetd
auditd dnsmasq ipmi lvm2-monitor NetworkManager readahead_early single ypbind
autofs dund iptables mcstrans nfs readahead_later smartd yum-updatesd
avahi-daemon firstboot irda mdmonitor nfslock restorecond sshd
avahi-dnsconfd functions irqbalance mdmpd nscd rhnsd svnserve
bluetooth gpm iscsi messagebus ntpd rhsmcertd syslog
capi haldaemon iscsid microcode_ctl pand rpcgssd vncserver
conman halt isdn multipathd pcscd rpcidmapd wdaemon
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
提示:在suport-files目录提供有启动脚步;
[root@localhost mysql]# ls support-files/(查看support-files目录文件及子目录)
binary-configure config.small.ini my-innodb-heavy-4G.cnf my-small.cnf mysql.server
config.huge.ini magic my-large.cnf mysqld_multi.server ndb-config-2-node.ini
config.medium.ini my-huge.cnf my-medium.cnf mysql-log-rotate
提示:mysql.server是mysqld的启动脚步;
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld(复制mysql.server文件到/etc/init.d目录下叫mysqld)
[root@localhost mysql]# ls -l /etc/init.d/mysqld(查看mysqld文件的详细信息)
-rwxr-xr-x 1 root root 10650 Sep 15 17:16 /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld(将mysqld添加到服务列表)
[root@localhost mysql]# chkconfig --list mysqld(查看mysqld在不同系统级别启动情况)
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]# ls support-files/(查看support-files目录文件及子目录)
binary-configure config.small.ini my-innodb-heavy-4G.cnf(存储引擎) my-small.cnf(小的) mysql.server
config.huge.ini magic my-large.cnf(大级) mysqld_multi.server ndb-config-2-node.ini
config.medium.ini my-huge.cnf(巨级别) my-medium.cnf(中级) mysql-log-rotate
提示:提供了一堆配置文件,my-small.cnf、my-mdium.cnf、my-large.cnf、my-huge.cnf,my-inodb-heavy-4G.cnf的innodb是mysql的存储引擎,大小在于内存大小;
[root@localhost mysql]# cat support-files/my-medium.cnf(查看my-medium.cnf文件内容)
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[root@localhost mysql]# head support-files/my-medium.cnf(查看my-mdedium.cnf文件前10行)
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
提示:内存有32M-64M;
[root@localhost mysql]# head support-files/my-small.cnf(查看my-small.cnf文件前10行)
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
提示:内存小于64M;
[root@localhost mysql]# free -m(查看内存使用情况,-m以MB为单位显示内存使用情况)
total used free shared buffers cached
Mem: 1010 805 205 0 27 628
-/+ buffers/cache: 149 860
Swap: 1027 0 1027
[root@localhost mysql]# head support-files/my-large.cnf(查看my-large.cnf文件前10行)
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
提示:内存等于512M;
[root@localhost mysql]# head support-files/my-huge.cnf(查看my-huge.cnf文件前10行)
# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
提示:内存为1G-2G;
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf(复制my-large.cnf到/etc/叫my.cnf)
[root@localhost mysql]# vim /etc/my.cnf(编辑my.cnf文件)
[mysqld]
port = 3306(端口号)
socket = /tmp/mysql.sock(本机通信使用socket,rpm安装mysql在/var/lib,数据文件目录下)
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8(线程缓存大小)
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4(线程并发量,最多启动多少个mysql线程,mysql线程多了,每一个线程要占用一个cpu,cpu个数乘以2)
datadir = /mydata/data(数据目录,如果不加mysql启动不了)
[root@localhost ~]# cat /proc/cpuinfo(查看cpu信息)
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
stepping : 9
cpu MHz : 2494.409
cache size : 3072 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss nx rdtscp
lm constant_tsc up ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm [8]
bogomips : 4988.81
[root@localhost mysql]# service mysqld start(启动mysqld服务)
Starting MySQL... [ OK ]
[root@localhost mysql]# netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p显示协议名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3494/./hpiod
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 29682/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3175/portmap
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN 3214/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3515/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3527/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3564/sendmail
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 28909/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 29250/sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 29346/sshd
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3499/python
tcp 0 0 :::80 :::* LISTEN 371/httpd
tcp 0 0 :::22 :::* LISTEN 3515/sshd
tcp 0 0 ::1:6010 :::* LISTEN 28909/sshd
tcp 0 0 ::1:6011 :::* LISTEN 29250/sshd
tcp 0 0 ::1:6012 :::* LISTEN 29346/sshd
提示:3306端口启动,说明mysql启动;
[root@localhost mysql]# cd(切换到用户家目录)
[root@localhost ~]# mysql(连接mysql)
-bash: mysql: command not found
提示:没有客户端命令;
[root@localhost ~]# ls /usr/local/mysql/bin/(查看/usr/local/mysql/bin目录)
innochecksum mysqlaccess.conf mysqld mysqlhotcopy mysql_tzinfo_to_sql
msql2mysql mysqladmin mysqld-debug mysqlimport mysql_upgrade
myisamchk mysqlbinlog mysqld_multi mysql_plugin mysql_waitpid
myisam_ftdump mysqlbug mysqld_safe mysql_secure_installation mysql_zap
myisamlog mysqlcheck mysqldump mysql_setpermission perror
myisampack mysql_client_test mysqldumpslow mysqlshow replace
my_print_defaults mysql_client_test_embedded mysql_embedded mysqlslap resolveip
mysql mysql_config mysql_find_rows mysqltest resolve_stack_dump
mysqlaccess mysql_convert_table_format mysql_fix_extensions mysqltest_embedded
提示:编译安装mysql的时候,客户端和服务器端都安装了,它会把所有东西都装好,只有红帽在制作rpm包的时候才有必须将他们分成各个包子包;
[root@localhost ~]# vim /etc/profile.d/mysql.sh(编辑mysql的PATH环境变量文件)
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost ~]# mysql(连接mysql服务器)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.28-log MySQL Community Server (GPL)(版本5.5.28)
Copyright (c) 2000, 2012, 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> SHOW DATABASES;(查看数据库)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
提示:performance_schema是系统状态收集库,mysql已经接受多少用户请求,多少用户曾经连进来过,那个用户连进来以后,我们网络发送了多少数据量过去这些都
有统计数据的,这些数据都放在performance_schema库中;
mysql> SHOW GLOBAL VARIABLES;(查看MySQL服务器运行特性)
+---------------------------------------------------+-----------------------------------------------------------------------+
| Variable_name | Value |
+---------------------------------------------------+-----------------------------------------------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| autocommit | ON |
| automatic_sp_privileges | ON |
| back_log | 50 |
| basedir | /usr/local/mysql |
| big_tables | OFF |
| binlog_cache_size | 32768 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | MIXED |
| binlog_stmt_cache_size | 32768 |
| bulk_insert_buffer_size | 8388608 |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.5.28-linux2.6-i686/share/charsets/ |
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
| completion_type | NO_CHAIN |
| concurrent_insert | AUTO |
| connect_timeout | 10 |
| datadir | /mydata/data/ |
| date_format | %Y-%m-%d |
| datetime_format | %Y-%m-%d %H:%i:%s |
| default_storage_engine | InnoDB |
| default_week_format | 0 |
| delay_key_write | ON |
| delayed_insert_limit | 100 |
| delayed_insert_timeout | 300 |
| delayed_queue_size | 1000 |
| div_precision_increment | 4 |
| engine_condition_pushdown | ON |
| event_scheduler | OFF |
| expire_logs_days | 0 |
| flush | OFF |
| flush_time | 0 |
| foreign_key_checks | ON |
| ft_boolean_syntax | + -><()~*:""&| |
| ft_max_word_len | 84 |
| ft_min_word_len | 4 |
| ft_query_expansion_limit | 20 |
| ft_stopword_file | (built-in) |
| general_log | OFF |
| general_log_file | /mydata/data/localhost.log |
| group_concat_max_len | 1024 |
| have_compress | YES |
| have_crypt | YES |
| have_csv | YES |
| have_dynamic_loading | YES |
| have_geometry | YES |
| have_innodb | YES |
| have_ndbcluster | NO |
| have_openssl | DISABLED |
| have_partitioning | YES |
| have_profiling | YES |
| have_query_cache | YES |
| have_rtree_keys | YES |
| have_ssl | DISABLED |
| have_symlink | YES |
| hostname | localhost.localdomain |
| ignore_builtin_innodb | OFF |
| init_connect | |
| init_file | |
| init_slave | |
| innodb_adaptive_flushing | ON |
| innodb_adaptive_hash_index | ON |
| innodb_additional_mem_pool_size | 8388608 |
| innodb_autoextend_increment | 8 |
| innodb_autoinc_lock_mode | 1 |
| innodb_buffer_pool_instances | 1 |
| innodb_buffer_pool_size | 134217728 |
| innodb_change_buffering | all |
| innodb_checksums | ON |
| innodb_commit_concurrency | 0 |
| innodb_concurrency_tickets | 500 |
| innodb_data_file_path | ibdata1:10M:autoextend |
| innodb_data_home_dir | |
| innodb_doublewrite | ON |
| innodb_fast_shutdown | 1 |
| innodb_file_format | Antelope |
| innodb_file_format_check | ON |
| innodb_file_format_max | Antelope |
| innodb_file_per_table | OFF |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_flush_method | |
| innodb_force_load_corrupted | OFF |
| innodb_force_recovery | 0 |
| innodb_io_capacity | 200 |
| innodb_large_prefix | OFF |
| innodb_lock_wait_timeout | 50 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | 8388608 |
| innodb_log_file_size | 5242880 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | ./ |
| innodb_max_dirty_pages_pct | 75 |
| innodb_max_purge_lag | 0 |
| innodb_mirrored_log_groups | 1 |
| innodb_old_blocks_pct | 37 |
| innodb_old_blocks_time | 0 |
| innodb_open_files | 300 |
| innodb_purge_batch_size | 20 |
| innodb_purge_threads | 0 |
| innodb_random_read_ahead | OFF |
| innodb_read_ahead_threshold | 56 |
| innodb_read_io_threads | 4 |
| innodb_replication_delay | 0 |
| innodb_rollback_on_timeout | OFF |
| innodb_rollback_segments | 128 |
| innodb_spin_wait_delay | 6 |
| innodb_stats_method | nulls_equal |
| innodb_stats_on_metadata | ON |
| innodb_stats_sample_pages | 8 |
| innodb_strict_mode | OFF |
| innodb_support_xa | ON |
| innodb_sync_spin_loops | 30 |
| innodb_table_locks | ON |
| innodb_thread_concurrency | 0 |
| innodb_thread_sleep_delay | 10000 |
| innodb_use_native_aio | ON |
| innodb_use_sys_malloc | ON |
| innodb_version | 1.1.8 |
| innodb_write_io_threads | 4 |
| interactive_timeout | 28800 |
| join_buffer_size | 131072 |
| keep_files_on_create | OFF |
| key_buffer_size | 268435456 |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| large_files_support | ON |
| large_page_size | 0 |
| large_pages | OFF |
| lc_messages | en_US |
| lc_messages_dir | /usr/local/mysql-5.5.28-linux2.6-i686/share/ |
| lc_time_names | en_US |
| license | GPL |
| local_infile | ON |
| lock_wait_timeout | 31536000 |
| locked_in_memory | OFF |
| log | OFF |
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
| log_error | /mydata/data/localhost.localdomain.err |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | 1 |
| long_query_time | 10.000000 |
| low_priority_updates | OFF |
| lower_case_file_system | OFF |
| lower_case_table_names | 0 |
| max_allowed_packet | 1048576 |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_size | 1073741824 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| max_connect_errors | 10 |
| max_connections | 151 |
| max_delayed_threads | 20 |
| max_error_count | 64 |
| max_heap_table_size | 16777216 |
| max_insert_delayed_threads | 20 |
| max_join_size | 18446744073709551615 |
| max_length_for_sort_data | 1024 |
| max_long_data_size | 1048576 |
| max_prepared_stmt_count | 16382 |
| max_relay_log_size | 0 |
| max_seeks_for_key | 4294967295 |
| max_sort_length | 1024 |
| max_sp_recursion_depth | 0 |
| max_tmp_tables | 32 |
| max_user_connections | 0 |
| max_write_lock_count | 4294967295 |
| metadata_locks_cache_size | 1024 |
| min_examined_row_limit | 0 |
| multi_range_count | 256 |
| myisam_data_pointer_size | 6 |
| myisam_max_sort_file_size | 2146435072 |
| myisam_mmap_size | 4294967295 |
| myisam_recover_options | OFF |
| myisam_repair_threads | 1 |
| myisam_sort_buffer_size | 67108864 |
| myisam_stats_method | nulls_unequal |
| myisam_use_mmap | OFF |
| net_buffer_length | 16384 |
| net_read_timeout | 30 |
| net_retry_count | 10 |
| net_write_timeout | 60 |
| new | OFF |
| old | OFF |
| old_alter_table | OFF |
| old_passwords | OFF |
| open_files_limit | 1024 |
| optimizer_prune_level | 1 |
| optimizer_search_depth | 62 |
| optimizer_switch | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_m |
erge_intersection=on,engine_condition_pushdown=on | |
| performance_schema | OFF |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
| performance_schema_max_cond_classes | 80 |
| performance_schema_max_cond_instances | 1000 |
| performance_schema_max_file_classes | 50 |
| performance_schema_max_file_handles | 32768 |
| performance_schema_max_file_instances | 10000 |
| performance_schema_max_mutex_classes | 200 |
| performance_schema_max_mutex_instances | 1000000 |
| performance_schema_max_rwlock_classes | 30 |
| performance_schema_max_rwlock_instances | 1000000 |
| performance_schema_max_table_handles | 100000 |
| performance_schema_max_table_instances | 50000 |
| performance_schema_max_thread_classes | 50 |
| performance_schema_max_thread_instances | 1000 |
| pid_file | /mydata/data/localhost.localdomain.pid |
| plugin_dir | /usr/local/mysql/lib/plugin/ |
| port | 3306 |
| preload_buffer_size | 32768 |
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 16777216 |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| range_alloc_block_size | 4096 |
| read_buffer_size | 1048576 |
| read_only | OFF |
| read_rnd_buffer_size | 4194304 |
| relay_log | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| report_host | |
| report_password | |
| report_port | 3306 |
| report_user | |
| rpl_recovery_rank | 0 |
| secure_auth | OFF |
| secure_file_priv | |
| server_id | 1 |
| skip_external_locking | ON |
| skip_name_resolve | OFF |
| skip_networking | OFF |
| skip_show_database | OFF |
| slave_compressed_protocol | OFF |
| slave_exec_mode | STRICT |
| slave_load_tmpdir | /tmp |
| slave_max_allowed_packet | 1073741824 |
| slave_net_timeout | 3600 |
| slave_skip_errors | OFF |
| slave_transaction_retries | 10 |
| slave_type_conversions | |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /mydata/data/localhost-slow.log |
| socket(socket文件在那) | /tmp/mysql.sock |
| sort_buffer_size | 1048576 |
| sql_auto_is_null | OFF |
| sql_big_selects | ON |
| sql_big_tables | OFF |
| sql_buffer_result | OFF |
| sql_log_bin | ON |
| sql_log_off | OFF |
| sql_low_priority_updates | OFF |
| sql_max_join_size | 18446744073709551615 |
| sql_mode | |
| sql_notes | ON |
| sql_quote_show_create | ON |
| sql_safe_updates | OFF |
| sql_select_limit | 18446744073709551615 |
| sql_slave_skip_counter | 0 |
| sql_warnings | OFF |
| ssl_ca | |
| ssl_capath | |
| ssl_cert | |
| ssl_cipher | |
| ssl_key | |
| storage_engine | InnoDB |
| stored_program_cache | 256 |
| sync_binlog | 0 |
| sync_frm | ON |
| sync_master_info | 0 |
| sync_relay_log | 0 |
| sync_relay_log_info | 0 |
| system_time_zone | CST |
| table_definition_cache | 400 |
| table_open_cache | 256 |
| thread_cache_size | 8 |
| thread_concurrency | 4 |
| thread_handling | one-thread-per-connection |
| thread_stack | 196608 |
| time_format | %H:%i:%s |
| time_zone | SYSTEM |
| timed_mutexes | OFF |
| tmp_table_size | 16777216 |
| tmpdir | /tmp |
| transaction_alloc_block_size | 8192 |
| transaction_prealloc_size | 4096 |
| tx_isolation | REPEATABLE-READ |
| unique_checks | ON |
| updatable_views_with_limit | YES |
| version | 5.5.28-log |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | i686 |
| version_compile_os | linux2.6 |
| wait_timeout | 28800 |
+---------------------------------------------------+-----------------------------------------------------------------------+
316 rows in set (0.01 sec)
mysql> SHOW GLOBAL VARIABLES LIKE 'datadir';(查看mysql服务器运行特性,只显示datadir参数)
+---------------+---------------+
| Variable_name | Value |
+---------------+---------------+
| datadir | /mydata/data/ |
+---------------+---------------+
1 row in set (0.00 sec)
mysql> SHOW GLOBAL VARIABLES LIKE 'data%';(查看mysql服务器运行特性,只显示data开始任意长度任意字符结尾段)
+---------------+---------------+
| Variable_name | Value |
+---------------+---------------+
| datadir | /mydata/data/ |
+---------------+---------------+
1 row in set (0.00 sec)
mysql> SHOW GLOBAL VARIABLES LIKE '%data%';(查看mysql服务器运行特性,值显示任意长度任意字符开头,中间data,任意长度任意字符结尾段)
+----------------------------+------------------------+
| Variable_name | Value |
+----------------------------+------------------------+
| character_set_database | latin1 |
| collation_database | latin1_swedish_ci |
| datadir | /mydata/data/ |
| innodb_data_file_path | ibdata1:10M:autoextend |
| innodb_data_home_dir | |
| innodb_stats_on_metadata | ON |
| max_length_for_sort_data | 1024 |
| max_long_data_size | 1048576 |
| metadata_locks_cache_size | 1024 |
| myisam_data_pointer_size | 6 |
| skip_show_database | OFF |
| updatable_views_with_limit | YES |
+----------------------------+------------------------+
12 rows in set (0.01 sec)
mysql> SHOW GLOBAL STATUS;(查看mysql服务器状态统计数据)
+------------------------------------------+-------------+
| Variable_name | Value |
+------------------------------------------+-------------+
| Aborted_clients | 0 |(终止、中断的客户端)
| Aborted_connects | 0 |(终止、中断的连接)
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
| Bytes_received | 373 |(从mysql启动到此刻收到多少字节)
| Bytes_sent | 11369 |(从mysql启动到此刻发送多少字节)
| Com_admin_commands | 0 |
| Com_assign_to_keycache | 0 |
| Com_alter_db | 0 |
| Com_alter_db_upgrade | 0 |
| Com_alter_event | 0 |
| Com_alter_function | 0 |
| Com_alter_procedure | 0 |
| Com_alter_server | 0 |
| Com_alter_table | 0 |
| Com_alter_tablespace | 0 |
| Com_analyze | 0 |
| Com_begin | 0 |
| Com_binlog | 0 |
| Com_call_procedure | 0 |
| Com_change_db | 0 |
| Com_change_master | 0 |
| Com_check | 0 |
| Com_checksum | 0 |
| Com_commit | 0 |
| Com_create_db | 0 |
| Com_create_event | 0 |
| Com_create_function | 0 |
| Com_create_index | 0 |
| Com_create_procedure | 0 |
| Com_create_server | 0 |
| Com_create_table | 0 |
| Com_create_trigger | 0 |
| Com_create_udf | 0 |
| Com_create_user | 0 |
| Com_create_view | 0 |
| Com_dealloc_sql | 0 |
| Com_delete | 0 |
| Com_delete_multi | 0 |
| Com_do | 0 |(有一类命令执行多少次)
| Com_drop_db | 0 |
| Com_drop_event | 0 |
| Com_drop_function | 0 |
| Com_drop_index | 0 |
| Com_drop_procedure | 0 |
| Com_drop_server | 0 |
| Com_drop_table | 0 |
| Com_drop_trigger | 0 |
| Com_drop_user | 0 |
| Com_drop_view | 0 |
| Com_empty_query | 0 |
| Com_execute_sql | 0 |
| Com_flush | 0 |
| Com_grant | 0 |
| Com_ha_close | 0 |
| Com_ha_open | 0 |
| Com_ha_read | 0 |
| Com_help | 0 |
| Com_insert | 0 |
| Com_insert_select | 0 |
| Com_install_plugin | 0 |
| Com_kill | 0 |
| Com_load | 0 |
| Com_lock_tables | 0 |
| Com_optimize | 0 |
| Com_preload_keys | 0 |
| Com_prepare_sql | 0 |
| Com_purge | 0 |
| Com_purge_before_date | 0 |
| Com_release_savepoint | 0 |
| Com_rename_table | 0 |
| Com_rename_user | 0 |
| Com_repair | 0 |
| Com_replace | 0 |
| Com_replace_select | 0 |
| Com_reset | 0 |
| Com_resignal | 0 |
| Com_revoke | 0 |
| Com_revoke_all | 0 |
| Com_rollback | 0 |
| Com_rollback_to_savepoint | 0 |
| Com_savepoint | 0 |
| Com_select | 1 |(select命令执行多少次)
| Com_set_option | 0 |
| Com_signal | 0 |
| Com_show_authors | 0 |
| Com_show_binlog_events | 0 |
| Com_show_binlogs | 0 |
| Com_show_charsets | 0 |
| Com_show_collations | 0 |
| Com_show_contributors | 0 |
| Com_show_create_db | 0 |
| Com_show_create_event | 0 |
| Com_show_create_func | 0 |
| Com_show_create_proc | 0 |
| Com_show_create_table | 0 |
| Com_show_create_trigger | 0 |
| Com_show_databases | 1 |
| Com_show_engine_logs | 0 |
| Com_show_engine_mutex | 0 |
| Com_show_engine_status | 0 |
| Com_show_events | 0 |
| Com_show_errors | 0 |
| Com_show_fields | 0 |
| Com_show_function_status | 0 |
| Com_show_grants | 0 |
| Com_show_keys | 0 |
| Com_show_master_status | 0 |
| Com_show_open_tables | 0 |
| Com_show_plugins | 0 |
| Com_show_privileges | 0 |
| Com_show_procedure_status | 0 |
| Com_show_processlist | 0 |
| Com_show_profile | 0 |
| Com_show_profiles | 0 |
| Com_show_relaylog_events | 0 |
| Com_show_slave_hosts | 0 |
| Com_show_slave_status | 0 |
| Com_show_status | 1 |
| Com_show_storage_engines | 0 |
| Com_show_table_status | 0 |
| Com_show_tables | 0 |
| Com_show_triggers | 0 |
| Com_show_variables | 4 |
| Com_show_warnings | 0 |
| Com_slave_start | 0 |
| Com_slave_stop | 0 |
| Com_stmt_close | 0 |
| Com_stmt_execute | 0 |
| Com_stmt_fetch | 0 |
| Com_stmt_prepare | 0 |
| Com_stmt_reprepare | 0 |
| Com_stmt_reset | 0 |
| Com_stmt_send_long_data | 0 |
| Com_truncate | 0 |
| Com_uninstall_plugin | 0 |
| Com_unlock_tables | 0 |
| Com_update | 0 |
| Com_update_multi | 0 |
| Com_xa_commit | 0 |
| Com_xa_end | 0 |
| Com_xa_prepare | 0 |
| Com_xa_recover | 0 |
| Com_xa_rollback | 0 |
| Com_xa_start | 0 |
| Compression | OFF |
| Connections | 2 |
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 6 |
| Created_tmp_tables | 6 |
| Delayed_errors | 0 |
| Delayed_insert_threads | 0 |
| Delayed_writes | 0 |
| Flush_commands | 1 |
| Handler_commit | 0 |
| Handler_delete | 0 |
| Handler_discover | 0 |
| Handler_prepare | 0 |
| Handler_read_first | 3 |
| Handler_read_key | 0 |
| Handler_read_last | 0 |
| Handler_read_next | 0 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 357 |
| Handler_rollback | 0 |
| Handler_savepoint | 0 |
| Handler_savepoint_rollback | 0 |
| Handler_update | 0 |
| Handler_write | 334 |
| Innodb_buffer_pool_pages_data | 306 |
| Innodb_buffer_pool_pages_dirty | 0 |
| Innodb_buffer_pool_pages_flushed | 316 |
| Innodb_buffer_pool_pages_free | 7884 |
| Innodb_buffer_pool_pages_misc | 1 |
| Innodb_buffer_pool_pages_total | 8191 |
| Innodb_buffer_pool_read_ahead_rnd | 0 |
| Innodb_buffer_pool_read_ahead | 0 |
| Innodb_buffer_pool_read_ahead_evicted | 0 |
| Innodb_buffer_pool_read_requests | 2558 |
| Innodb_buffer_pool_reads | 0 |
| Innodb_buffer_pool_wait_free | 0 |
| Innodb_buffer_pool_write_requests | 2385 |
| Innodb_data_fsyncs | 19 |
| Innodb_data_pending_fsyncs | 0 |
| Innodb_data_pending_reads | 0 |
| Innodb_data_pending_writes | 0 |
| Innodb_data_read | 0 |
| Innodb_data_reads | 0 |
| Innodb_data_writes | 358 |
| Innodb_data_written | 9113088 |
| Innodb_dblwr_pages_written | 143 |
| Innodb_dblwr_writes | 2 |
| Innodb_have_atomic_builtins | OFF |
| Innodb_log_waits | 0 |
| Innodb_log_write_requests | 3170 |
| Innodb_log_writes | 4 |
| Innodb_os_log_fsyncs | 10 |
| Innodb_os_log_pending_fsyncs | 0 |
| Innodb_os_log_pending_writes | 0 |
| Innodb_os_log_written | 1589248 |
| Innodb_page_size | 16384 |
| Innodb_pages_created | 306 |
| Innodb_pages_read | 0 |
| Innodb_pages_written | 316 |
| Innodb_row_lock_current_waits | 0 |
| Innodb_row_lock_time | 0 |
| Innodb_row_lock_time_avg | 0 |
| Innodb_row_lock_time_max | 0 |
| Innodb_row_lock_waits | 0 |
| Innodb_rows_deleted | 0 |
| Innodb_rows_inserted | 0 |
| Innodb_rows_read | 0 |
| Innodb_rows_updated | 0 |
| Innodb_truncated_status_writes | 0 |
| Key_blocks_not_flushed | 0 |
| Key_blocks_unused | 231960 |
| Key_blocks_used | 0 |
| Key_read_requests | 0 |
| Key_reads | 0 |
| Key_write_requests | 0 |
| Key_writes | 0 |
| Last_query_cost | 0.000000 |
| Max_used_connections | 1 |
| Not_flushed_delayed_rows | 0 |
| Open_files | 20 |
| Open_streams | 0 |
| Open_table_definitions | 33 |
| Open_tables | 26 |
| Opened_files | 82 |
| Opened_table_definitions | 33 |
| Opened_tables | 33 |
| Performance_schema_cond_classes_lost | 0 |
| Performance_schema_cond_instances_lost | 0 |
| Performance_schema_file_classes_lost | 0 |
| Performance_schema_file_handles_lost | 0 |
| Performance_schema_file_instances_lost | 0 |
| Performance_schema_locker_lost | 0 |
| Performance_schema_mutex_classes_lost | 0 |
| Performance_schema_mutex_instances_lost | 0 |
| Performance_schema_rwlock_classes_lost | 0 |
| Performance_schema_rwlock_instances_lost | 0 |
| Performance_schema_table_handles_lost | 0 |
| Performance_schema_table_instances_lost | 0 |
| Performance_schema_thread_classes_lost | 0 |
| Performance_schema_thread_instances_lost | 0 |
| Prepared_stmt_count | 0 |
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 16768384 |
| Qcache_hits | 0 |
| Qcache_inserts | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 1 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
| Queries | 9 |
| Questions | 9 |
| Rpl_status | AUTH_MASTER |
| Select_full_join | 0 |
| Select_full_range_join | 0 |
| Select_range | 0 |
| Select_range_check | 0 |
| Select_scan | 6 |
| Slave_heartbeat_period | 0.000 |
| Slave_open_temp_tables | 0 |
| Slave_received_heartbeats | 0 |
| Slave_retried_transactions | 0 |
| Slave_running | OFF |
| Slow_launch_threads | 0 |
| Slow_queries | 0 |
| Sort_merge_passes | 0 |
| Sort_range | 0 |
| Sort_rows | 0 |
| Sort_scan | 0 |
| Ssl_accept_renegotiates | 0 |
| Ssl_accepts | 0 |
| Ssl_callback_cache_hits | 0 |
| Ssl_cipher | |
| Ssl_cipher_list | |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_ctx_verify_depth | 0 |
| Ssl_ctx_verify_mode | 0 |
| Ssl_default_timeout | 0 |
| Ssl_finished_accepts | 0 |
| Ssl_finished_connects | 0 |
| Ssl_session_cache_hits | 0 |
| Ssl_session_cache_misses | 0 |
| Ssl_session_cache_mode | NONE |
| Ssl_session_cache_overflows | 0 |
| Ssl_session_cache_size | 0 |
| Ssl_session_cache_timeouts | 0 |
| Ssl_sessions_reused | 0 |
| Ssl_used_session_cache_entries | 0 |
| Ssl_verify_depth | 0 |
| Ssl_verify_mode | 0 |
| Ssl_version | |
| Table_locks_immediate | 36 |
| Table_locks_waited | 0 |
| Tc_log_max_pages_used | 0 |
| Tc_log_page_size | 0 |
| Tc_log_page_waits | 0 |
| Threads_cached | 0 |
| Threads_connected | 1 |
| Threads_created | 1 |
| Threads_running | 1 |
| Uptime | 1646 |
| Uptime_since_flush_status | 1646 |
+------------------------------------------+-------------+
310 rows in set (0.00 sec)
mysql> SELECT VERSION();(查看mysql版本,version是Mysql内置函数)
+------------+
| VERSION() |
+------------+
| 5.5.28-log |
+------------+
1 row in set (0.00 sec)
mysql> SELECT DATABASE();(显示当前默认数据库)
+------------+
| DATABASE() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> USE mysql(改变默认数据库为mysql)
Database changed
mysql> SELECT DATABASE();(显示当前默认数据库)
+------------+
| DATABASE() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)
mysql> SELECT USER();(查看当前登录的用户)
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> SHOW GLOBAL STATUS LIKE '%select%';(查看mysql服务器状态,只显示任意长度任意字符开头中间select任意长度任意字符结尾的段)
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| Com_insert_select | 0 |
| Com_replace_select | 0 |
| Com_select | 7 |
| Select_full_join | 0 |
| Select_full_range_join | 0 |
| Select_range | 0 |
| Select_range_check | 0 |
| Select_scan | 8 |
+------------------------+-------+
8 rows in set (0.00 sec)
mysql> \q(退出mysql)
Bye
输出mysql的man帮助文件:
[root@localhost ~]#man mysql(查看mysql的man帮助手册)
[root@localhost ~]# vim /etc/man.config(编辑man.config配置文件)
[root@localhost ~]# cd /usr/local/mysql(切换到/usr/local/mysql目录)
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
提示:mysql的帮助手册在man目录;
[root@localhost mysql]# ls man/(查看man目录文件及子目录)
man1 man8
[root@localhost mysql]# vim /etc/man.config(编辑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
/MANPATH
提示:在MANPATH新增/usr/local/mysql/man的man帮助文件路径;
输出mysql的库文件:
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf(创建mysql.conf文件)
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
提示:mysql的库文件在lib目录;
[root@localhost mysql]# ls lib/(查看lib目录文件及子目录)
libmysqlclient.a libmysqlclient_r.so.18 libmysqlclient.so.18 libmysqld-debug.a plugin
libmysqlclient_r.a libmysqlclient_r.so.18.0.0 libmysqlclient.so.18.0.0 libmysqlservices.a
libmysqlclient_r.so libmysqlclient.so libmysqld.a libtcmalloc_minimal.so
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf(创建mysql.conf文件)
/usr/local/mysql/lib
提示:将mysql的库文件路径写在mysql.conf文件;
[root@localhost mysql]# ldconfig -v(让系统重新读取库文件,-v显示过程)
提示:操作系统到那找库文件,内核到那去找库文件,操作系统启动的时候,它会自动把这些库文件都找出来,然后缓存在一个路径下,有多少可用他都会有缓存的,新建的没有缓存,
ldconfig命令就是让操作系统重新建立库文件缓存;
[root@localhost mysql]# ls -ll /etc/ld.so.cache(查看ld.so.cache文件详细信息)
-rw-r--r-- 1 root root 54205 Sep 15 19:13 /etc/ld.so.cache
提示:/etc/ld.so.cache就是库文件的缓存文件;
输出mysql的头文件:
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
提示:mysql的头文件在include目录;
[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql(给/usr/local/mysql/include创建软连接到/usr/include/mysql,
-s软连接,-v显示创建过程)
create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include/'
[root@localhost mysql]# ls /usr/include/mysql/(查看/usr/include/mysql目录文件及子目录)
decimal.h my_alloc.h my_dir.h my_pthread.h mysql_embed.h my_xml.h sql_state.h
errmsg.h my_attribute.h my_getopt.h mysql mysql.h plugin_audit.h sslopt-case.h
keycache.h my_compiler.h my_global.h mysql_com.h mysql_time.h plugin_ftparser.h sslopt-longopts.h
m_ctype.h my_config.h my_list.h mysqld_ername.h mysql_version.h plugin.h sslopt-vars.h
m_string.h my_dbug.h my_net.h mysqld_error.h my_sys.h sql_common.h typelib.h
提示:后面四部并非必须的,倒出二进制文件、man帮助、库文件、头文件,只不过不做可能有些功能实现不了而已,对Mysql安装只实现前面那些功能就行;
编译安装PHP:
PHP有三种工作模式,CGI、FastCGI、模块,对apache而言最简单的模式还是模块,如何将PHP安装为apache模块;
[root@localhost mysql]# cd(切换到用户家目录)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2 install.log.syslog
apr-1.4.6 apr-util-1.4.1 httpd-2.4.4 install.log mysql-5.5.28-linux2.6-i686.tar.gz
[root@localhost ~]# ltfp 172.16.0.1/pub/Sources(连接ftp服务器)
ltfp 172.16.0.1/pub/Sources> cd new_lamp/(切换到new_lamp目录)
ltfp 172.16.0.1/pub/Sources/new_lamp> get php-5.4.13.tar.bz2(下载php源码包)
11545777 bytes transferred
ltfp 172.16.0.1/pub/Sources/new_lamp> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-util-1.4.1 httpd-2.4.4.tar.bz2 mysql-5.5.28-linux2.6-i686.tar.gz
apr-1.4.6 apr-util-1.4.1.tar.bz2 install.log php-5.4.13.tar.bz2
apr-1.4.6.tar.bz2 httpd-2.4.4 install.log.syslog
[root@localhost ~]# tar xf php-5.4.13.tar.bz2(解压php-5.4.13,x解压,f后面跟文件名)
[root@localhost ~]# cd php-5.4.13(切换到php-5.4.13目录)
提示:php有很多功能都是依赖于额外本身系统上某些功能的,php可以动态帮我们生成图片,但是要想生成图片它要依赖于图片库,如果系统没有图片库,它就没法使用这种功能;
[root@localhost php-5.4.13]# ./configure --help | less(查看php的配置帮助,并分页显示)
[root@localhost php-5.4.13]# rpm -qi freetype(查看freetype软件的信息)
Name : freetype Relocations: (not relocatable)
Version : 2.2.1 Vendor: Red Hat, Inc.
Release : 28.el5_7.2 Build Date: Tue 15 Nov 2011 10:50:19 PM CST
Install Date: Sat 22 Nov 2014 09:22:11 AM CST Build Host: x86-003.build.bos.redhat.com
Group : System Environment/Libraries Source RPM: freetype-2.2.1-28.el5_7.2.src.rpm
Size : 626801 License: BSD/GPL dual license
Signature : DSA/SHA1, Wed 16 Nov 2011 05:35:27 PM CST, Key ID 5326810137017186
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://www.freetype.org
Summary : A free and portable font rendering engine
Description :
The FreeType engine is a free and portable font rendering
engine, developed to provide advanced font support for a variety of
platforms and environments. FreeType is a library which can open and
manages font files as well as efficiently load, hint and render
individual glyphs. FreeType is not a font server or a complete
text-rendering library.(freetype引擎是一个自由的可移植的字体库,能够实现引用特定字体)
[root@localhost php-5.4.13]# httpd -M(查看httpd加载的模块)
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_prefork_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
提示:mpm是prefork模型;
[root@localhost php-5.4.13]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
提示:注释prefork模块,启用event模块;
[root@localhost php-5.4.13]# service httpd restart(重启httd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost php-5.4.13]# httpd -M(查看httpd加载的模块)
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_event_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
提示:现在mpm是event模型;
[root@localhost php-5.4.13]# ./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-con
fig-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zt(配置php,--prefix指定php安装目录,--with-mysql指定mysql的路径,--with-
openssl支持openssl功能,--with-mysqli另一种让php跟mysql交互接口,--enable-mbstring支持多字节字符,用于支持中文,--with-freetype-dir支持freet
ype功能,引用字体库,--with-jpeg-dir支持jpeg图片,--with-png-dir支持png图片,--with-zlib让数据文件先压缩再传送,--with-libxml-dir指定xml库路径
,--enable-xml支持xml,xml扩展标记语言,现在总舵的系统交互使用xml,--enable-sockets支持基于套接字通信,--with-apxs2基于apxs钩子实现将php编译成apa
che模块,--with-mcrypt支持加密,--with-config-file-path配置文件路径,--with-config-file-scan-dir配置文件的片段,--with-bz2压缩库,--enable-
maintainer-zts仅在event和worker使用,如果apache以线程工作需要编译成这种格式)
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
提示:报错,没有mcrypt.h的头文件,解决方法,不实用加密功能--with-mcrypt选项去掉,要使用加密功能安装加密功能所依赖的包;
[root@localhost mysql]# cd(切换到用户家目录)
[root@localhost mysql]# cd
[root@localhost ~]# lftp 172.16.0.1/pub/Sources(连接ftp服务器)
lftp 172.16.0.1/pub/Sources> cd nginx(切换到nginx目录)
lftp 172.16.0.1/pub/Sources/nginx> mget mhash-0.9.2-6.el5.i386.rpm mhash-devel-0.9.2-6.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm(下载mhash、mhash-devel、libmcrypt、libmcrypt-devel)
404104 bytes transferred
Total 4 files transferred
lftp 172.16.0.1/pub/Sources/nginx> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-util-1.4.1.tar.bz2 install.log.syslog mhash-devel-0.9.2-6.el5.i386.rpm
apr-1.4.6 httpd-2.4.4 libmcrypt-2.5.7-5.el5.i386.rpm mysql-5.5.28-linux2.6-i686.tar.gz
apr-1.4.6.tar.bz2 httpd-2.4.4.tar.bz2 libmcrypt-devel-2.5.7-5.el5.i386.rpm php-5.4.13
apr-util-1.4.1 install.log mhash-0.9.2-6.el5.i386.rpm php-5.4.13.tar.bz2
[root@localhost ~]# rpm -ivh *.rpm(安装当前目录所有的rpm包)
warning: libmcrypt-2.5.7-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:mhash ########################################### [ 25%]
2:libmcrypt ########################################### [ 50%]
3:libmcrypt-devel ########################################### [ 75%]
4:mhash-devel ########################################### [100%]
[root@localhost php-5.4.13]# ./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-con
fig-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zt(配置php,--prefix指定php安装目录,--with-mysql指定mysql的路径,--with-
openssl支持openssl功能,--with-mysqli另一种让php跟mysql交互接口,--enable-mbstring支持多字节字符,用于支持中文,--with-freetype-dir支持freety
pe功能,引用字体库,--with-jpeg-dir支持jpeg图片,--with-png-dir支持png图片,--with-zlib让数据文件先压缩再传送,--with-libxml-dir指定xml库路径,
--enable-xml支持xml,xml扩展标记语言,现在总舵的系统交互使用xml,--enable-sockets支持基于套接字通信,--with-apxs2基于apxs钩子实现将php编译成apache
模块,--with-mcrypt支持加密,--with-config-file-path配置文件路径,--with-config-file-scan-dir配置文件的片段,--with-bz2压缩库,--enable-main
tainer-zts仅在event和worker使用,如果apache以线程工作需要编译成这种格式)
[root@localhost php-5.4.13]# make(编译)
[root@localhost ~]# cd php-5.4.13(切换到php-5.4.13目录)
[root@localhost php-5.4.13]# ls(查看当前目录文件及子目录)
acinclude.m4 generated_lists Makefile.objects README.input_filter scripts
aclocal.m4 genfiles makerpm README.MAILINGLIST_RULES server-tests-config.php
build header meta_ccld README.namespaces server-tests.php
buildconf include missing README.NEW-OUTPUT-API snapshot
buildconf.bat INSTALL mkinstalldirs README.PARAMETER_PARSING_API stamp-h.in
CODING_STANDARDS install-sh modules README.PHP4-TO-PHP5-THIN-CHANGES stub.c
config.guess libs netware README.REDIST.BINS svnclean.bat
config.log libtool NEWS README.RELEASE_PROCESS tests
config.nice LICENSE pear README.SELF-CONTAINED-EXTENSIONS TSRM
config.status ltmain.sh php5.spec README.STREAMS UPGRADING
config.sub main php5.spec.in README.SUBMITTING_PATCH UPGRADING.INTERNALS
configure makedist php.gif README.TESTING vcsclean
configure.in Makefile php.ini-development(开发环境) README.TESTING2 win32
CREDITS Makefile.frag php.ini-production(生产环境) README.UNIX-BUILD-SYSTEM Zend
ext Makefile.fragments README.EXTENSIONS README.WIN32-BUILD-SYSTEM
EXTENSIONS Makefile.gcov README.EXT_SKEL run-tests.php
footer Makefile.global README.GIT-RULES sapi
提示:php的配置文件php.ini-development(开发环境)、php.ini-production(生产环境),我们用生产环境;
为php提供配置文件:
# cp php.ini-production /etc/php.ini
3、 编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。
php支持扩展功能
xcache
安装xcache,为php加速:
1、安装
# tar xf xcache-3.0.1.tar.gz
# cd xcache-3.0.1
# /usr/local/php/bin/phpize(准备好一个PHP扩展以便进行编译,几乎所有的扩展在执行之前都要对其执行这个命令)
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config(--enable-xcache启用xcache, --with-php-config指定php配置命令路径)
# make && make install
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
垃圾回收器
压力测试工具:
ab
http_load
siege
webbench
[root@localhost php-5.4.13]# make install(安装)
Installing PHP SAPI module: apache2handler(php的sapi模块,意味着为apache2添加了一个处理器,让apache2可以直接以模块化方式调用php)
/usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libphp5.la /usr/local/apache/modules
/usr/local/apr/build-1/libtool --mode=install install libphp5.la /usr/local/apache/modules/
libtool: install: install .libs/libphp5.so /usr/local/apache/modules/libphp5.so(模块安装路径)
libtool: install: install .libs/libphp5.lai /usr/local/apache/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /root/php-5.4.13/libs'
chmod 755 /usr/local/apache/modules/libphp5.so(权限是755)
[activating module `php5' in /etc/httpd/httpd.conf]
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util - installed: 1.2.1
[PEAR] PEAR - installed: 1.9.4
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
/root/php-5.4.13/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/
[root@localhost php-5.4.13]# ls /usr/local/php/(查看/usr/local/ppp目录文件及子目录)
bin etc include lib php
[root@localhost php-5.4.13]# ls /usr/local/php/bin/
pear peardev pecl phar phar.phar php php-cgi php-config phpize
提示:/usr/local/php/bin目录都是php的命令行工具)
[root@localhost php-5.4.13]# ls /usr/local/php/etc/(查看/usr/local/php/etc目录文件及子目录)
pear.conf
提示:/usr/local/php/etc目录是为其他php子项目所提供的配置文件存放路径;
[root@localhost ~]# ls /usr/local/php/php/(查看/usr/local/php/php目录文件及子目录)
man
[root@localhost ~]# ls /usr/local/php/php/man/(查看/usr/local/php/php/man目录文件及子目录)
man1
提示:/usr/local/php/php/man目录下是php的man帮助手册;
[root@localhost php-5.4.13]# ls(查看当前目录文件及子目录)
acinclude.m4 configure install-sh Makefile.gcov php5.spec README.NEW-OUTPUT-API
README.WIN32-BUILD-SYSTEM TSRM aclocal.m4 configure.in libphp5.la Makefile.global php5.spec.in
README.PARAMETER_PARSING_API run-tests.php UPGRADING
build CREDITS libs Makefile.objects php.gif README.PHP4-TO-PHP5-THIN-CHANGES
sapi UPGRADING.INTERNALS
buildconf ext libtool makerpm php.ini-development README.REDIST.BINS
scripts vcsclean buildconf.bat EXTENSIONS LICENSE meta_ccld php.ini-production(php配置文件)
README.RELEASE_PROCESS server-tests-config.php win32 CODING_STANDARDS footer ltmain.sh missing
README.EXTENSIONS README.SELF-CONTAINED-EXTENSIONS server-tests.php Zend config.guess generated_lists
main mkinstalldirs README.EXT_SKEL README.STREAMS snapshot config.log genfiles
makedist modules README.GIT-RULES README.SUBMITTING_PATCH stamp-h.in config.nice
header Makefile netware README.input_filter README.TESTING stub.c config.status
include Makefile.frag NEWS README.MAILINGLIST_RULES README.TESTING2 svnclean.bat config.sub
INSTALL Makefile.fragments pear README.namespaces README.UNIX-BUILD-SYSTEM tests
[root@localhost php-5.4.13]# pwd(查看当前目录文件及子目录)
/root/php-5.4.13
[root@localhost php-5.4.13]# cp php.ini-production /etc/php.ini(复制php.ini-production到/etc/php.ini)
提示:在配置php的时候通过-with-config-file-path=/etc指定过配置文件路径为/etc,所以它会在/etc下找配置文件;
[root@localhost php-5.4.13]# vim /etc/php.ini(编辑php.ini配置文件)
让apache跟php结合起来:
[root@localhost php-5.4.13]# cd(切换到用户家目录)
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
# Server-pool management (MPM specific)(把其他配置文件包含进来)
#Include /etc/httpd/extra/httpd-mpm.conf
# Multi-language error messages
#Include /etc/httpd/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
#Include /etc/httpd/extra/httpd-autoindex.conf(能够自动索引的)
# Language settings
#Include /etc/httpd/extra/httpd-languages.conf(支持更多文件的)
# User home directories
#Include /etc/httpd/extra/httpd-userdir.conf(支持用户个人家目录下使用网页文件的)
# Real-time info on requests and configuration
#Include /etc/httpd/extra/httpd-info.conf
# Virtual hosts
#Include /etc/httpd/extra/httpd-vhosts.conf
# Local access to the Apache HTTP Server Manual
#Include /etc/httpd/extra/httpd-manual.conf
# Distributed authoring and versioning (WebDAV)
#Include /etc/httpd/extra/httpd-dav.conf
# Various default settings
#Include /etc/httpd/extra/httpd-default.conf
# Secure (SSL/TLS) connections
#Include /etc/httpd/extra/httpd-ssl.conf(支持ssl的,启用这项还不够,还需要装载modessl模块)
/AddType
/DirectoryIndex
提示:让apache能够处理php结尾的页面文件;
[root@localhost ~]# httpd -t(检查httpd配置文件语法)
Syntax OK
[root@localhost ~]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
测试PHP运行:
[root@localhost ~]# cd /usr/local/apache/htdocs/(切换到/usr/local/apache/htdocs目录)
[root@localhost htdocs]# ls(查看当前目录文件及子目录)
index.html
[root@localhost htdocs]# mv index.html index.php(重命名index.html叫index.php)
[root@localhost htdocs]# vim index.php(编辑index.php文件)
<html><body><h1>It works, my apache!</h1></body></html>
<?php
phpinfo();
?>
测试:通过windows的ie浏览器输入172.16.100.1进行测试;

测试PHP连接MySQL:
[root@localhost htdocs]# vim index.php(编辑index.php文件)
<html><body><h1>It works, my apache!</h1></body></html>
<?php
$conn=mysql_connect('localhost','root','');
if ($conn)
echo "Success...";
else
echo "Failure...";
?>
测试:通过windows的ie浏览器输入172.16.100.1进行测试,Success...说明连接MySQL成功;

[root@localhost htdocs]# service mysqld stop(停止mysqld服务) Shutting down MySQL. [ OK ]
测试:通过windows的ie浏览器输入172.16.100.1进行测试,Failure...说明连接MySQL失败;

[root@localhost htdocs]# service mysqld start(启动mysqld服务)
Starting MySQL.. [ OK ]
使用xcache对PHP进行加速:
能够跟PHP2.4结合的只有xcache2.0极其以后的版本;
[root@localhost htdocs]# cd(切换到用户家目录)
[root@localhost ~]# lftp 172.16.0.1/pub/Sources(连接ftp服务器)
cd ok, cwd=/pub/Sources> cd new_lamp(切换到new_lamp目录)
lftp 172.16.0.1/pub/Sources/new_lamp> get xcache-2.0.0.tar.bz2(下载xcache-2.0.0)
108614 bytes transferred
lftp 172.16.0.1/pub/Sources/new_lamp> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg httpd-2.4.4 libmcrypt-devel-2.5.7-5.el5.i386.rpm php-5.4.13.tar.bz2
apr-1.4.6 httpd-2.4.4.tar.bz2 mhash-0.9.2-6.el5.i386.rpm xcache-2.0.0.tar.bz2
apr-1.4.6.tar.bz2 install.log mhash-devel-0.9.2-6.el5.i386.rpm
apr-util-1.4.1 install.log.syslog mysql-5.5.28-linux2.6-i686.tar.gz
apr-util-1.4.1.tar.bz2 libmcrypt-2.5.7-5.el5.i386.rpm php-5.4.13
[root@localhost ~]# tar xf xcache-2.0.0.tar.bz2(解压xcache,x解压,f后面跟文件名)
[root@localhost ~]# cd xcache-2.0.0(切换到xcache-2.0.0目录)
[root@localhost xcache-2.0.0]# ls(查看当前目录文件及子目录)
admin COPYING lock.c optimizer.h THANKS
align.h coverager lock.h phpdc.phpr utils.c
assembler.c coverager.c Makefile.frag phpdop.phpr utils.h
AUTHORS coverager.h mem.c prepare.devel xcache.c
ChangeLog decoder.c mem.h prepare.devel.inc xcache_globals.h
config.m4 Decompiler.class.php mkopcode.awk prepare.devel.inc.example xcache.h
config.w32 decompilesample.php mkopcode_spec.awk processor xcache.ini
const_string.c disassembler.c mkstructinfo.awk processor.c xcache-test.ini
const_string.h disassembler.h mmap.c README xcache-zh-gb2312.ini
const_string_opcodes_php4.x.h encoder.c NEWS run-xcachetest xc_malloc.c
const_string_opcodes_php5.0.h foreachcoresig.h opcode_spec.c stack.c xc_shm.c
const_string_opcodes_php5.1.h graph opcode_spec_def.h stack.h xc_shm.h
const_string_opcodes_php5.4.h includes.c opcode_spec.h test.mak
const_string_opcodes_php6.x.h INSTALL optimizer.c tests
提示:xcache的安装比较独特,因为xcache是PHP的模块;
[root@localhost xcache-2.0.0]# man phpize(查看phpize的man帮助文档)
No manual entry for phpize
提示:没有帮助文档;
[root@localhost xcache-2.0.0]# man -M /usr/local/php/php/ phpize(查看phpize的man帮助手册,-M指定phpize的man帮助文档路径)
No manual entry for phpize
提示:没有帮助文档;
[root@localhost xcache-2.0.0]# ls /usr/local/php/php/man/(查看/usr/local/php/php/man目录文件及子目录)
man1
[root@localhost xcache-2.0.0]# ls /usr/local/php/php/man/man1/(查看/usr/local/php/php/man/man1目录文件及子目录)
php.1 php-config.1 phpize.1
[root@localhost xcache-2.0.0]# man -M /usr/local/php/php/man phpize(查看phpize的man帮助手册,-M指定phpize的man帮助文档路径)
phpize - prepare a PHP extension for compiling(准备好一个PHP扩展以便进行编译,几乎所有的扩展在执行之前都要对其执行这个命令)
[root@localhost xcache-2.0.0]# pwd(查看当前所出的路径)
/root/xcache-2.0.0
[root@localhost xcache-2.0.0]# /usr/local/php/bin/phpize(执行phpize程序)
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@localhost xcache-2.0.0]# man -M /usr/local/php/php/man php-config(查看php-config命令的man帮助文档)
php-config - get information about PHP configuration and compile options(能够获取PHP的配置信息以及编译时所使用的选项信息,xcache就必
须要根据这种功能来获取我们PHP在安装时候到底启用那些功能,所以告诉它这个程序在什么地方,不然它会找不着的,因为我们不在默认安装路径下)
[root@localhost xcache-2.0.0]# ./configure --help | less(查看xcache的配置帮助,并分页显示)
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local](指定xcache安装路径,不用指定会默认安装到PHP的扩展路径)
--enable-xcache Include XCache support.(开启支持xcache功能)
--enable-xcache-constant XCache: Handle new constants made by php compiler (e.g.: for __halt_compiler)
--enable-xcache-coverager XCache: Enable code coverage dumper, useful for testing php scripts
--enable-xcache-disassembler XCache: Enable opcode to php variable dumper, NOT for production server
--with-php-config=PATH Path to php-config php-config
[root@localhost xcache-2.0.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config(配置xcache,--enable-xc
ache启用xcache功能,--with-php-config指定php配置命令路径)
[root@localhost xcache-2.0.0]# make(编译)
[root@localhost xcache-2.0.0]# make install(安装)
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/(安装共享扩展,在/usr/local/php/lib/php/e
xtensions/no-debug-zts-20100525/目录,这个路径很关键)
[root@localhost xcache-2.0.0]# ls(查看当前目录文件及子目录)
acinclude.m4 const_string.lo install-sh NEWS stack.h
aclocal.m4 const_string_opcodes_php4.x.h libtool opcode_spec.c stack.lo
admin const_string_opcodes_php5.0.h lock.c opcode_spec_def.h structinfo.m4
align.h const_string_opcodes_php5.1.h lock.h opcode_spec.h test.mak
assembler.c const_string_opcodes_php5.4.h lock.lo opcode_spec.lo tests
AUTHORS const_string_opcodes_php6.x.h ltmain.sh optimizer.c THANKS
autom4te.cache COPYING Makefile optimizer.h utils.c
build coverager Makefile.frag phpdc.phpr utils.h
ChangeLog coverager.c Makefile.fragments phpdop.phpr utils.lo
config.guess coverager.h Makefile.global prepare.devel xcache.c
config.h decoder.c Makefile.objects prepare.devel.inc xcache_globals.h
config.h.in Decompiler.class.php mem.c prepare.devel.inc.example xcache.h
config.log decompilesample.php mem.h processor xcache.ini
config.m4 disassembler.c mem.lo processor.c xcache.la
config.nice disassembler.h missing processor.h xcache.lo
config.status encoder.c mkinstalldirs processor.lo xcache-test.ini
config.sub foreachcoresig.h mkopcode.awk processor.out xcache-zh-gb2312.ini
configure graph mkopcode_spec.awk processor_real.c xc_malloc.c
configure.in include mkstructinfo.awk README xc_shm.c
config.w32 includes.c mmap.c run-tests.php xc_shm.h
const_string.c includes.i mmap.lo run-xcachetest xc_shm.lo
const_string.h INSTALL modules stack.c
提示:xcache.ini是样例配置文件,要想让PHP支持xcache功能,意味着把xcache配置信息必须要提供到PHP里面去,可以把xcache.ini的内容追加的php.ini中去,或者复制
这个内容到php.d目录下去;
[root@localhost xcache-2.0.0]# mkdir /etc/php.d(创建php.d目录)
[root@localhost xcache-2.0.0]# cp xcache.ini /etc/php.d/(复制xcache.ini到/etc/php.d目录下去)
[root@localhost xcache-2.0.0]# vim /etc/php.d/xcache.ini(编辑xcache.ini文件)
[xcache-common]
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so(zend扩展在什么地方,和安装xcache共享扩展路径相同)
;zend_extension_ts = c:/php/extensions/php_xcache.dll(给Windows用的,注释掉)
[xcache.admin](xcache的管理功能)
xcache.admin.enable_auth = On(认证是否打开)
xcache.admin.user = "mOo"(管理用户是什么)
; xcache.admin.pass = md5($your_password)(使用md5格式加密码)
xcache.admin.pass = ""(管理密码是什么)
[xcache]
xcache.shm_scheme = "mmap"(shm共享内存,使用那种方式来使用共享内存,来完成在各PHP进程之间共享模块,mmap内存映射,把一段内存让多个进程同时访问的)
xcache.size = 60M(用于缓存opcould代码空间有多大)
xcache.count = (设置CPU个数)
xcache.slots = 8K(在缓存当中有几个槽位来缓存多少个opcould)
xcache.ttl = 0(过期时间,0表示永久,由xcache自我管理)
xcache.gc_interval = 0(万一过期要回收回来,gc垃圾回收器,0表示不做任何扫描)
xcache.var_size = 4M(xcache变量缓存空间多大)
xcache.var_count = 1(缓存多少个)
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.cacher = On(缓存功能是否启用)
xcache.optimizer = Off(xcache自己的优化器,是否启用)
xcache.test = Off(测试功能)
[root@localhost xcache-2.0.0]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
提示:要想生效需要重启httpd服务,因为xcache是模块,被htppd加载的;
检测xcache是被加载:
[root@localhost xcache-2.0.0]# vim /usr/local/apache/htdocs/index.php(编辑index.php文件)
<html><body><h1>It works, my apache!</h1></body></html>
<?php
$conn=mysql_connect('localhost','root','');
if ($conn)
echo "Success...";
else
echo "Failure...";
phpinfo();
?>
测试:通过windows的ie浏览器输入172.16.100.1进行测试,xcache已经加载;

[root@localhost xcache-2.0.0]# vim /etc/php.d/xcache.ini(编辑xcache.ini文件)
; to disable: xcache.size=0(等于0禁用xcache功能)
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size = 60M
启用虚拟主机:
[root@localhost xcache-2.0.0]# cd(切换到用户家目录)
[root@localhost ~]# cd /etc/httpd/(切换到/etc/httpd目录)
[root@localhost httpd]# vim httpd.conf(编辑httpd.conf)
#DocumentRoot "/usr/local/apache/htdocs"(注释中心主机)
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf(启用虚拟主机配置文件)
/DocumentRoot
[root@localhost httpd]# pwd(查看当前所处的路径)
/etc/httpd
[root@localhost httpd]# ls(查看当前目录文件及子目录)
extra httpd.conf httpd.conf.bak magic mime.types original
[root@localhost httpd]# vim extra/httpd-vhosts.conf(编辑虚拟主机配置文件)
# Required modules: mod_log_config(需要启用mod_log_config模块)
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
[root@localhost httpd]# vim httpd.conf(编辑httpd.conf配置文件)
LoadModule log_config_module modules/mod_log_config.so(启用mod_log_config.so模块)
/LoadModule
/mod_log
[root@localhost httpd]# mkdir -pv /www/{a.org,b.net}(创建/www/a.org和/www/b.net目录,{}花括号展开,-p递归创建,-v显示创建过程)
mkdir: created directory `/www'
mkdir: created directory `/www/a.org'
mkdir: created directory `/www/b.net'
[root@localhost httpd]# vim extra/httpd-vhosts.conf(编辑虚拟主机配置文件)
<VirtualHost *:80>
ServerName www.a.org
DocumentRoot "/www/a.org"
ErrorLog "/var/log/httpd/a.org-error_log"
CustomLog "/var/log/httpd/a.org-access_log" combined
</VirtualHost>
<VirtualHost *:80>
Servername www.b.net
DocumentRoot "/www/b.net"
ErrorLog "/var/log/httpd/b.net-error_log"
CustomLog "/var/log/httpd/b.net-access_log" common
</VirtualHost>
[root@localhost httpd]# httpd -t(检查httpd配置文件语法)
(2)No such file or directory: AH02291: Cannot access directory '/var/log/httpd/' for error log of vhost defined at /etc/httpd/extra/
httpd-vhosts.conf:30
(2)No such file or directory: AH02291: Cannot access directory '/var/log/httpd/' for error log of vhost defined at /etc/httpd/extra/
httpd-vhosts.conf:23
AH00014: Configuration check failed
提示:日志目录不存在;
[root@localhost httpd]# mkdir /var/log/httpd(创建httpd目录)
[root@localhost httpd]# httpd -t(检查httpd配置文件语法)
Syntax OK
[root@localhost httpd]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@localhost httpd]# tail /var/log/httpd/a.org-error_log(查看a.org-error_log日志文件)
[root@localhost httpd]# echo "<h1>www.a.org</h1>" > /www/a.org/index.html(显示<h1>www.a.org</h1>输入到index.html文件)
测试:通过windows的ie浏览器访问www.a.org

[root@localhost httpd]# tail /var/log/httpd/a.org-error_log(查看a.org-error_log日志文件) [Wed Sep 16 02:38:09.620792 2015] [authz_core:error] [pid 13462:tid 3007630224] [client 172.16.100.254:12180] AH01630: client denied by server configuration: /www/a.org/ [Wed Sep 16 02:38:09.781874 2015] [authz_core:error] [pid 13462:tid 2997140368] [client 172.16.100.254:12180] AH01630: client denied by server configuration: /www/a.org/favicon.ico, referer: http://www.a.org/ 提示:用户访问被拒绝) [root@localhost httpd]# echo "<h1>www.b.net</h1>" > /www/b.net/index.html(将<h1>www.b.net</h1>输入到index.html文件)
测试:通过windows的ie浏览器访问www.b.net;

[root@localhost httpd]# vim httpd.conf(编辑httpd.conf配置文件)
#DocumentRoot "/usr/local/apache/htdocs"
<Directory "/usr/local/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted(允许所有人访问)
</Directory>
/DocumentRoot
[root@localhost httpd]# vim extra/httpd-vhosts.conf(编辑虚拟主机配置文件)
<VirtualHost *:80>
ServerName www.a.org
DocumentRoot "/www/a.org"
<Directory "/www/a.org">
Options none(不允许索引)
AllowOverride none
Require all granted(允许所有人访问)
</Directory>
ErrorLog "/var/log/httpd/a.org-error_log"
CustomLog "/var/log/httpd/a.org-access_log" combined
</VirtualHost>
<VirtualHost *:80>
Servername www.b.net
DocumentRoot "/www/b.net"
<Directory "/www/b.net">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/b.net-error_log"
CustomLog "/var/log/httpd/b.net-access_log" common
</VirtualHost>
[root@localhost httpd]# httpd -t(检查httpd配置文件语法)
Syntax OK
[root@localhost httpd]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
测试:通过windows的ie浏览器访问www.a.org

测试:通过windows的ie浏览器访问www.b.net;

压力测试:
[root@localhost httpd]# cd(切换到用户家目录)
[root@localhost apache]# ls(查看当前目录文件及子目录)
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost apache]# ls bin/(查看bin目录文件及子目录)
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve
apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs
提示:ab(apache benchmark)命令就是压力测试工具;
[root@localhost apache]# man ab(查看ab命令的man帮助文档)
ab - Apache HTTP server benchmarking tool
ab [ -A auth-username:password ] [ -b windowsize ] [ -B local-address ] [ -c concurrency ](并发量) [ -C cookie-
name=value ] [ -d ] [ -e csv-file ] [ -f protocol ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k
] [ -n requests ](一共请求多少个) [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -r ] [ -s timeout ] [ -S ] [ -t
timelimit ] [ -T content-type ] [ -u PUT-file ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X
proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [ -Z ciphersuite ] [http[s]://]hostname[:port]/path(请求那个服务器那个
主机那个文件)
[root@localhost apache]# vim /etc/hosts(编辑本地解析配置文件)
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
172.16.100.1 www.a.org
172.16.100.1 www.b.net
[root@localhost apache]# ab -c 10 -n 100 http://www.a.org/index.html(压力测试,-c并发量,-n总共发的请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient).....done
Server Software: Apache/2.4.4(对方服务器软件及版本)
Server Hostname: www.a.org(主机名称)
Server Port: 80(端口)
Document Path: /index.html(文件)
Document Length: 19 bytes(文件大小)
Concurrency Level: 10(并发级别)
Time taken for tests: 0.071 seconds(从第一个请求开始发出去连接建立开始到最后一个请求的响应报文响应回来结束之间的时长)
Complete requests: 100(成功得到请求数量)
Failed requests: 0(失败请求数量)
Write errors: 0(失败写入次数)
Total transferred: 27300 bytes(总共的传输量,服务器响应给我们整体的数据大小,包括数据和tcp/ip封装报文)
HTML transferred: 1900 bytes(数据大小)
Requests per second: 1412.97 [#/sec] (mean)(每秒请求数)
Time per request: 7.077 [ms] (mean)(每个请求所花费时间,一批请求花费时间)
Time per request: 0.708 [ms] (mean, across all concurrent requests)(每一个平均多长时间)
Transfer rate: 376.70 [Kbytes/sec] received(传输速率)
Connection Times (ms)(连接时间)
min mean[+/-sd] median max
Connect: 0 3 4.2 1 36(建立连接时间)
Processing: 0 2 2.3 1 11(处理过程)
Waiting: 0 1 2.0 1 9(等待时间)
Total: 1 5 5.0 2 38
Percentage of the requests served within a certain time (ms)
50% 2
66% 3
75% 9
80% 10
90% 11
95% 11
98% 12
99% 38
100% 38 (longest request)
[root@localhost ~]# ab -c 2 -n 100 http://www.a.org/index.html(压力测试,-c并发量,-n一共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient).....done
Server Software: Apache/2.4.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 2
Time taken for tests: 0.034 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 27300 bytes
HTML transferred: 1900 bytes
Requests per second: 2903.01 [#/sec] (mean)
Time per request: 0.689 [ms] (mean)
Time per request: 0.344 [ms] (mean, across all concurrent requests)
Transfer rate: 773.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 0 0 0.3 0 1
Waiting: 0 0 0.2 0 1
Total: 0 1 0.4 0 2
ERROR: The median and mean for the total time are more than twice the standard
deviation apart. These results are NOT reliable.
Percentage of the requests served within a certain time (ms)
50% 0
66% 1
75% 1
80% 1
90% 1
95% 1
98% 2
99% 2
100% 2 (longest request)
[root@localhost ~]# ab -c 100 -n 100 http://www.a.org/index.html(压力测试,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient).....done
Server Software: Apache/2.4.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 100
Time taken for tests: 0.034 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 27300 bytes
HTML transferred: 1900 bytes
Requests per second: 2934.10 [#/sec] (mean)
Time per request: 34.082 [ms] (mean)
Time per request: 0.341 [ms] (mean, across all concurrent requests)
Transfer rate: 782.24 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 19 8.4 22 31
Processing: 3 11 6.4 9 27
Waiting: 0 9 7.1 8 25
Total: 27 31 2.0 31 34
Percentage of the requests served within a certain time (ms)
50% 31
66% 32
75% 32
80% 33
90% 33
95% 34
98% 34
99% 34
100% 34 (longest request)
[root@localhost ~]# ab -c 100 -n 5000 http://www.a.org/index.html(压力测试,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: Apache/2.4.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 100
Time taken for tests: 1.049 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 1365000 bytes
HTML transferred: 95000 bytes
Requests per second: 4767.99 [#/sec] (mean)
Time per request: 20.973 [ms] (mean)
Time per request: 0.210 [ms] (mean, across all concurrent requests)
Transfer rate: 1271.15 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 10 7.4 10 75
Processing: 3 11 5.5 10 47
Waiting: 0 8 4.6 7 30
Total: 14 21 7.4 20 82
Percentage of the requests served within a certain time (ms)
50% 20
66% 21
75% 22
80% 23
90% 24
95% 28
98% 51
99% 61
100% 82 (longest request)
[root@localhost ~]# ab -c 500 -n 5000 http://www.a.org/index.html(压力测试,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: Apache/2.4.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 500
Time taken for tests: 1.292 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 1365000 bytes
HTML transferred: 95000 bytes
Requests per second: 3868.77 [#/sec] (mean)
Time per request: 129.240 [ms] (mean)
Time per request: 0.258 [ms] (mean, across all concurrent requests)
Transfer rate: 1031.42 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 59 42.6 54 237
Processing: 3 66 39.8 62 1086
Waiting: 0 49 44.3 44 1086
Total: 7 125 49.3 115 1285
Percentage of the requests served within a certain time (ms)
50% 115
66% 124
75% 130
80% 133
90% 215
95% 240
98% 255
99% 259
100% 1285 (longest request)
[root@localhost ~]# ab -r -c 500 -n 10000 http://www.a.org/index.html(压力测试,-r忽略错误,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (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.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 500
Time taken for tests: 2.227 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2730000 bytes
HTML transferred: 190000 bytes
Requests per second: 4489.91 [#/sec] (mean)
Time per request: 111.361 [ms] (mean)
Time per request: 0.223 [ms] (mean, across all concurrent requests)
Transfer rate: 1197.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 54 31.2 53 146
Processing: 3 56 30.7 55 1626
Waiting: 0 42 35.4 41 1625
Total: 10 109 32.2 109 1661
Percentage of the requests served within a certain time (ms)
50% 109
66% 117
75% 122
80% 124
90% 131
95% 135
98% 155
99% 164
100% 1661 (longest request)
[root@localhost ~]# ab -r -c 2000 -n 10000 http://www.a.org/index.html(压力测试,-r忽略错误,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
socket: Too many open files (24)
提示:报错,在linux上有限定,每个进程最多不允许打开1024个文件;
[root@localhost ~]# ulimit -n 10000(允许每个进程最多打开1万个文件)
[root@localhost ~]# ab -r -c 2000 -n 10000 http://www.a.org/index.html(压力测试,-r忽略错误,-c并发量,-n总共多少请求)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (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.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /index.html
Document Length: 19 bytes
Concurrency Level: 2000
Time taken for tests: 3.827 seconds
Complete requests: 10000
Failed requests: 2
(Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors: 0
Non-2xx responses: 2
Total transferred: 2730254 bytes
HTML transferred: 190386 bytes
Requests per second: 2613.30 [#/sec] (mean)
Time per request: 765.315 [ms] (mean)
Time per request: 0.383 [ms] (mean, across all concurrent requests)
Transfer rate: 696.78 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 50 111.4 0 475
Processing: 18 87 194.8 28 2965
Waiting: 0 81 192.4 28 2965
Total: 18 137 254.9 28 3345
Percentage of the requests served within a certain time (ms)
50% 28
66% 30
75% 36
80% 368
90% 458
95% 495
98% 518
99% 530
100% 3345 (longest request)
[root@localhost ~]# netstat -an(查看系统服务,-a所有服务,-n以数字显示)
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:60927 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:60671 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:60415 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:60159 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:59903 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:59647 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:58623 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:58367 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:58111 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:57855 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:57599 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:52479 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:52223 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:51967 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:51711 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:51455 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:51199 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:50943 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:50687 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:50431 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:50175 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:49919 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:49663 TIME_WAIT
tcp 0 0 ::ffff:172.16.100.1:80 ::ffff:172.16.100.1:49407 TIME_WAIT
提示:这些都是套接字文件,此前发起的每一个请求服务器都要维持一个套接字;
[root@localhost ~]# cd /www/a.org/(切换到/www/a.org目录)
[root@localhost a.org]# ll -h(查看当前目录文件及子目录详细信息,-h做单位换算)
total 8.0K
-rw-r--r-- 1 root root 19 Sep 16 02:32 index.html
[root@localhost a.org]# ls -lh /var/log/(查看/var/log目录文件及子目录详细信息,并做单位换算)
total 1.2M
-rw-r----- 1 root root 294 Nov 22 2014 acpid
-rw------- 1 root root 428K Nov 22 2014 anaconda.log
-rw------- 1 root root 31K Nov 22 2014 anaconda.syslog
-rw------- 1 root root 47K Nov 22 2014 anaconda.xlog
drwxr-x--- 2 root root 4.0K Nov 22 2014 audit
-rw------- 1 root root 363 Sep 15 14:24 boot.log
-rw------- 1 root utmp 0 Nov 22 2014 btmp
drwxr-xr-x 2 root root 4.0K Jun 28 2007 conman
drwxr-xr-x 2 root root 4.0K Jun 28 2007 conman.old
-rw------- 1 root root 2.9K Sep 16 05:01 cron
drwxr-xr-x 2 lp sys 4.0K Nov 22 2014 cups
-rw-r--r-- 1 root root 29K Nov 22 2014 dmesg
-rw------- 1 root root 7.2K Sep 15 16:04 faillog
drwxr-xr-x 2 root root 4.0K Nov 22 2014 gdm
drwxr-xr-x 2 root root 4.0K Sep 16 02:29 httpd
-rw-r--r-- 1 root root 143K Sep 16 05:08 lastlog
drwxr-xr-x 2 root root 4.0K Nov 22 2014 mail
-rw------- 1 root root 2.5K Sep 16 04:02 maillog
-rw------- 1 root root 136K Sep 16 05:10 messages
drwxr-xr-x 2 root root 4.0K Nov 22 2014 pm
drwx------ 2 root root 4.0K Aug 12 2008 ppp
drwxr-xr-x 2 root root 4.0K Sep 15 15:14 prelink
drwxr-xr-x 2 root root 4.0K Nov 22 2014 rhsm
-rw-r--r-- 1 root root 31K Sep 16 04:03 rpmpkgs
drwx------ 2 root root 4.0K Jan 19 2012 samba
-rw-r--r-- 1 root root 68K Nov 22 2014 scrollkeeper.log
-rw------- 1 root root 11K Sep 16 05:08 secure
drwxr-xr-x 2 root root 4.0K Nov 22 2014 setroubleshoot
-rw------- 1 root root 0 Nov 22 2014 spooler
-rw------- 1 root root 0 Nov 22 2014 tallylog
-rw-r--r-- 1 root root 579 Nov 22 2014 up2date
drwxr-xr-x 2 root root 4.0K Jun 9 2009 vbox
-rw-rw-r-- 1 root utmp 37K Sep 16 05:08 wtmp
-rw-r--r-- 1 root root 47K Nov 22 2014 Xorg.0.log
-rw-r--r-- 1 root root 8.8K Sep 15 14:32 yum.log
[root@localhost a.org]# cp /var/log/lastlog /www/a.org/test.html(复制lastlog文件到/www/a.org叫test.html)
[root@localhost ~]# netstat -an(查看系统服务,-a所有服务,-n以数字显示)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
tcp 0 0 172.16.100.1:22 172.16.100.254:8228 ESTABLISHED
tcp 0 0 172.16.100.1:22 172.16.100.254:8205 ESTABLISHED
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:6010 :::* LISTEN
tcp 0 0 ::1:6012 :::* LISTEN
udp 0 0 0.0.0.0:43547 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:846 0.0.0.0:*
udp 0 0 0.0.0.0:849 0.0.0.0:*
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 :::40122 :::*
udp 0 0 :::5353 :::*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 10579 @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 14995 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 15428 @/tmp/fam-root-
unix 2 [ ACC ] STREAM LISTENING 239704 /tmp/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 15170 /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 10563 @ISCSID_UIP_ABSTRACT_NAMESPACE
unix 2 [ ] DGRAM 2064 @/org/kernel/udev/udevd
unix 2 [ ACC ] STREAM LISTENING 12248 @/var/run/hald/dbus-tlAxJl9kYC
unix 2 [ ] DGRAM 12257 @/org/freedesktop/hal/udev_event
unix 2 [ ACC ] STREAM LISTENING 12249 @/var/run/hald/dbus-uwJtjvqVwh
unix 22 [ ] DGRAM 11421 /dev/log
unix 2 [ ACC ] STREAM LISTENING 14762 /dev/gpmctl
unix 2 [ ACC ] STREAM LISTENING 10731 /var/run/setrans/.setrans-unix
unix 2 [ ACC ] STREAM LISTENING 11345 /var/run/audispd_events
unix 2 [ ACC ] STREAM LISTENING 11933 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 12059 /var/run/sdp
unix 2 [ ACC ] STREAM LISTENING 12171 /var/run/pcscd.comm
unix 2 [ ACC ] STREAM LISTENING 12210 /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 13868 /var/run/setroubleshoot/setroubleshoot_server
unix 2 [ ACC ] STREAM LISTENING 14510 /var/run/cups/cups.sock
unix 2 [ ] STREAM CONNECTED 386348 /var/run/setrans/.setrans-unix
unix 2 [ ] DGRAM 340050
unix 2 [ ] DGRAM 312529
unix 2 [ ] DGRAM 238484
unix 2 [ ] DGRAM 90149
unix 2 [ ] DGRAM 49289
unix 3 [ ] STREAM CONNECTED 15431 @/tmp/fam-root-
unix 3 [ ] STREAM CONNECTED 15430
unix 3 [ ] STREAM CONNECTED 15417 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 15416
unix 3 [ ] STREAM CONNECTED 15173 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 15172
unix 3 [ ] STREAM CONNECTED 15167
unix 3 [ ] STREAM CONNECTED 15166
unix 2 [ ] DGRAM 15164
unix 2 [ ] DGRAM 14740
unix 2 [ ] DGRAM 14710
unix 2 [ ] DGRAM 14684
unix 2 [ ] DGRAM 14635
unix 2 [ ] DGRAM 14575
unix 2 [ ] DGRAM 14383
unix 2 [ ] DGRAM 14334
unix 2 [ ] DGRAM 14191
unix 3 [ ] STREAM CONNECTED 14155 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 14154
unix 3 [ ] STREAM CONNECTED 14128 @/var/run/hald/dbus-tlAxJl9kYC
unix 3 [ ] STREAM CONNECTED 14127
unix 3 [ ] STREAM CONNECTED 13953 @/var/run/hald/dbus-tlAxJl9kYC
unix 3 [ ] STREAM CONNECTED 13948
unix 3 [ ] STREAM CONNECTED 13910 /var/run/acpid.socket
unix 3 [ ] STREAM CONNECTED 13909
unix 3 [ ] STREAM CONNECTED 13880 /var/run/audispd_events
unix 3 [ ] STREAM CONNECTED 13879
unix 3 [ ] STREAM CONNECTED 13872 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 13871
unix 3 [ ] STREAM CONNECTED 13827 @/var/run/hald/dbus-tlAxJl9kYC
unix 3 [ ] STREAM CONNECTED 13826
unix 3 [ ] STREAM CONNECTED 12252 @/var/run/hald/dbus-uwJtjvqVwh
unix 3 [ ] STREAM CONNECTED 12251
unix 2 [ ] DGRAM 12170
unix 2 [ ] DGRAM 12047
unix 3 [ ] STREAM CONNECTED 12033 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 12032
unix 2 [ ] DGRAM 12030
unix 2 [ ] DGRAM 12000
unix 3 [ ] STREAM CONNECTED 11949
unix 3 [ ] STREAM CONNECTED 11948
unix 3 [ ] STREAM CONNECTED 11841
unix 3 [ ] STREAM CONNECTED 11840
unix 2 [ ] DGRAM 11708
unix 2 [ ] DGRAM 11429
unix 3 [ ] STREAM CONNECTED 11336
unix 3 [ ] STREAM CONNECTED 11335
[root@localhost a.org]# ab -r -c 2000 -n 10000 http://www.a.org/test.html(压力测试,-r忽略错误,-c并发量,-n请求总数)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (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.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /test.html
Document Length: 146292 bytes
Concurrency Level: 2000
Time taken for tests: 6.516 seconds
Complete requests: 10000
Failed requests: 24
(Connect: 0, Receive: 0, Length: 24, Exceptions: 0)
Write errors: 0
Non-2xx responses: 24
Total transferred: 1462022304 bytes
HTML transferred: 1459414056 bytes
Requests per second: 1534.58 [#/sec] (mean)
Time per request: 1303.287 [ms] (mean)
Time per request: 0.652 [ms] (mean, across all concurrent requests)
Transfer rate: 219100.87 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 243 783.0 23 3638
Processing: 13 693 1187.1 350 6366
Waiting: 1 385 1149.6 50 6366
Total: 13 937 1465.2 450 6507
Percentage of the requests served within a certain time (ms)
50% 450
66% 680
75% 969
80% 1163
90% 4219
95% 4280
98% 6473
99% 6474
100% 6507 (longest request)
[root@localhost ~]# ps aux | grep httpd(查看所有终端所有进程)
root 13653 0.0 1.0 100192 11084 ? Ss 02:48 0:00 /usr/local/apache/bin/httpd
daemon 15671 0.0 3.0 403448 31772 ? Sl 05:08 0:00 /usr/local/apache/bin/httpd
daemon 15673 0.0 2.4 395176 24964 ? Sl 05:08 0:00 /usr/local/apache/bin/httpd
daemon 15753 0.0 2.3 397268 24544 ? Sl 05:08 0:00 /usr/local/apache/bin/httpd
daemon 15781 0.0 2.3 392156 24300 ? Sl 05:08 0:00 /usr/local/apache/bin/httpd
daemon 15837 0.0 2.5 394272 26288 ? Sl 05:09 0:00 /usr/local/apache/bin/httpd
daemon 15865 0.0 3.6 410492 38176 ? Sl 05:09 0:00 /usr/local/apache/bin/httpd
daemon 15866 0.0 2.4 391504 25040 ? Sl 05:09 0:00 /usr/local/apache/bin/httpd
daemon 15921 0.0 4.2 428152 43928 ? Sl 05:09 0:00 /usr/local/apache/bin/httpd
daemon 16374 0.6 2.6 395644 26940 ? Sl 05:25 0:00 /usr/local/apache/bin/httpd
daemon 16404 0.0 0.9 366536 9732 ? Sl 05:25 0:00 /usr/local/apache/bin/httpd
root 16465 0.0 0.0 4220 608 pts/0 R+ 05:28 0:00 grep httpd
提示:因为是event模型,不是prefork模型,不是一个请求一个进程的,每一个进程可以有n个线程;
[root@localhost a.org]# cp test.html test2.html(复制test.html叫test2.html)
[root@localhost a.org]# vim test2.html(编辑test2.html文件)
[root@localhost a.org]# dd if=/dev/zero of=/www/a.org/test3.html bs=1M count=2(从/dev/zero设备最开头开始复制2M,bs复制1M,count复制两个bs大小)
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.00264362 seconds, 793 MB/s
[root@localhost a.org]# ab -r -c 2000 -n 10000 http://www.a.org/test3.html(压力测试,-r忽略错误,-c并发量,-n请求总数)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (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.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /test3.html
Document Length: 2097152 bytes
Concurrency Level: 2000
Time taken for tests: 63.256 seconds
Complete requests: 10000
Failed requests: 228
(Connect: 0, Receive: 76, Length: 76, Exceptions: 76)
Write errors: 0
Total transferred: 20814746460 bytes
HTML transferred: 20812136448 bytes
Requests per second: 158.09 [#/sec] (mean)
Time per request: 12651.294 [ms] (mean)
Time per request: 6.326 [ms] (mean, across all concurrent requests)
Transfer rate: 321341.06 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1754 4229.5 9 21015
Processing: 625 5669 10398.9 2065 54171
Waiting: 0 4237 10571.0 610 54165
Total: 704 7424 11259.1 2457 63182
Percentage of the requests served within a certain time (ms)
50% 2457
66% 4932
75% 7991
80% 10504
90% 22374
95% 27631
98% 52086
99% 52405
100% 63182 (longest request)
[root@localhost a.org]# cd(切换到用户家目录)
[root@localhost ~]# lftp 172.16.0.1/pub/Sources(连接ftp服务器)
cd ok, cwd=/pub/Sources
lftp 172.16.0.1:/pub/Sources> cd new_lamp(切换到new_lamp目录)
lftp 172.16.0.1/pub/Sources/new_lamp> get phpMyAdmin-3.5.1-all-languages.tar.bz2(下载phpMyAdmin)
4724343 bytes transferred
lftp 172.16.0.1/pub/Sources/new_lamp> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg install.log php-5.4.13
apr-1.4.6 install.log.syslog php-5.4.13.tar.bz2
apr-1.4.6.tar.bz2 libmcrypt-2.5.7-5.el5.i386.rpm phpMyAdmin-3.5.1-all-languages.tar.bz2
apr-util-1.4.1 libmcrypt-devel-2.5.7-5.el5.i386.rpm xcache-2.0.0
apr-util-1.4.1.tar.bz2 mhash-0.9.2-6.el5.i386.rpm xcache-2.0.0.tar.bz2
httpd-2.4.4 mhash-devel-0.9.2-6.el5.i386.rpm
httpd-2.4.4.tar.bz2 mysql-5.5.28-linux2.6-i686.tar.gz
[root@localhost ~]# tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2 -C /www/b.net/(解压phpMyAdmin文件,x解压,f后面跟文件名,-C指定解压目录)
[root@localhost ~]# cd /www/b.net/(切换到/www/b.net目录)
[root@localhost b.net]# mv phpMyAdmin-3.5.1-all-languages/ pma(修改phpMyAdmin叫pma)
[root@localhost b.net]# cd pma/(切换到pma目录)
[root@localhost pma]# ls(查看当前目录文件及子目录)
browse_foreigners.php favicon.ico RELEASE-DATE-3.5.1 tbl_gis_visualization.php
bs_disp_as_mime_type.php file_echo.php robots.txt tbl_import.php
bs_play_media.php gis_data_editor.php schema_edit.php tbl_indexes.php
ChangeLog import.php schema_export.php tbl_move_copy.php
changelog.php import_status.php server_binlog.php tbl_operations.php
chk_rel.php index.php server_collations.php tbl_printview.php
config.sample.inc.php js server_databases.php tbl_relation.php
db_create.php libraries server_engines.php tbl_replace.php
db_datadict.php LICENSE server_export.php tbl_row_action.php
db_events.php license.php server_import.php tbl_select.php
db_export.php locale server_plugins.php tbl_sql.php
db_import.php main.php server_privileges.php tbl_structure.php
db_operations.php navigation.php server_replication.php tbl_tracking.php
db_printview.php phpinfo.php server_sql.php tbl_triggers.php
db_qbe.php phpmyadmin.css.php server_status.php tbl_zoom_select.php
db_routines.php pmd_display_field.php server_synchronize.php themes
db_search.php pmd_general.php server_variables.php themes.php
db_sql.php pmd_pdf.php setup transformation_overview.php
db_structure.php pmd_relation_new.php show_config_errors.php transformation_wrapper.php
db_tracking.php pmd_relation_upd.php sql.php url.php
db_triggers.php pmd_save_pos.php tbl_addfield.php user_password.php
docs.css prefs_forms.php tbl_alter.php view_create.php
Documentation.html prefs_manage.php tbl_change.php view_operations.php
Documentation.txt print.css tbl_chart.php webapp.php
enum_editor.php querywindow.php tbl_create.php
examples README tbl_export.php
export.php README.VENDOR tbl_get_field.php
提示:pma是有主配置文件的叫config.sample.inc.php;
[root@localhost pma]# cp config.sample.inc.php config.inc.php(复制config.sample.inc.php叫config.inc.php)
[root@localhost pma]# vim config.inc.php(编辑config.inc.php文件)
$cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */(blowfish加密的密钥,随机码,可以自己生成)
[root@localhost pma]# openssl rand -hex 10(生存随机数,-hex十六进制)
Usage: rand [options] num
where options are
-out file - write to file
-engine e - use engine e, possibly a hardware device.
-rand file:file:... - seed PRNG from files
-base64 - encode output
[root@localhost pma]# whatis rand(查看rand命令有那些man帮助文档)
rand (3) - pseudo-random number generator
rand (3p) - pseudo-random number generator
rand [sslrand] (1ssl) - generate pseudo-random bytes
rand [sslrand] (3ssl) - pseudo-random number generator
[root@localhost pma]# man sslrand(查看sslrand的man帮助文档)
-base64
Perform base64 encoding on the output.
[root@localhost pma]# openssl rand -base64 10(生成随机数,-base64基于64位编码)
0+t8Cwti+aiyMg==
[root@localhost pma]# vim config.inc.php(编辑config.inc.php文件)
$cfg['blowfish_secret'] = '0+t8Cwti+aiyMg'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$cfg['Servers'][$i]['host'] = 'localhost';(mysql服务器)
测试:通过Windows的ie浏览器输入www.b.net/pma访问;

[root@localhost pma]# mysqladmin -uroot password 'redhat'(为root用户设定密码为redhat) [root@localhost pma]# mysqladmin -uroot -p flush-privileges(刷新root用户权限级别) Enter password:

[root@localhost pma]# ab -c 100 -n 1000 http://www.b.net/pma/index.php(压力测试,-c并发量,-n请求总数)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.b.net (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: www.b.net
Server Port: 80
Document Path: /pma/index.php
Document Length: 7038 bytes
Concurrency Level: 100
Time taken for tests: 9.995 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 7845554 bytes
HTML transferred: 7038000 bytes
Requests per second: 100.05 [#/sec] (mean)
Time per request: 999.535 [ms] (mean)
Time per request: 9.995 [ms] (mean, across all concurrent requests)
Transfer rate: 766.52 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 313 259.6 229 1153
Processing: 11 686 314.1 685 1675
Waiting: 0 506 341.2 468 1367
Total: 225 999 226.6 949 1680
Percentage of the requests served within a certain time (ms)
50% 949
66% 987
75% 1136
80% 1172
90% 1379
95% 1382
98% 1676
99% 1677
100% 1680 (longest request)
[root@localhost pma]# ab -c 500 -n 5000 http://www.b.net/pma/index.php(压力测试,-c并发量,-n请求总数)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.b.net (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests
Server Software: Apache/2.4.4
Server Hostname: www.b.net
Server Port: 80
Document Path: /pma/index.php
Document Length: 7038 bytes
Concurrency Level: 500
Time taken for tests: 76.299 seconds
Complete requests: 5000
Failed requests: 4
(Connect: 0, Receive: 0, Length: 4, Exceptions: 0)
Write errors: 0
Total transferred: 39196448 bytes
HTML transferred: 35161848 bytes
Requests per second: 65.53 [#/sec] (mean)
Time per request: 7629.932 [ms] (mean)
Time per request: 15.260 [ms] (mean, across all concurrent requests)
Transfer rate: 501.68 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1728 1734.0 1331 9476
Processing: 37 3790 4872.6 2488 49470
Waiting: 0 3747 4791.0 2469 49467
Total: 1116 5518 4809.9 5193 50459
Percentage of the requests served within a certain time (ms)
50% 5193
66% 5265
75% 5326
80% 5731
90% 7589
95% 13026
98% 23486
99% 29418
100% 50459 (longest request)
[root@localhost pma]# top(查看cpu使用率)
top - 06:23:34 up 16:16, 3 users, load average: 13.79, 14.91, 6.48
Tasks: 140 total, 1 running, 139 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 94.5%id, 0.0%wa, 4.8%hi, 0.0%si, 0.0%st
Mem: 1034676k total, 901836k used, 132840k free, 31584k buffers
Swap: 1052248k total, 124k used, 1052124k free, 145604k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16598 daemon 18 0 416m 59m 4532 S 0.3 5.9 0:03.94 httpd
1 root 15 0 2164 604 524 S 0.0 0.1 0:00.79 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root 10 -5 0 0 0 S 0.0 0.0 0:00.13 events/0
5 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khelper
6 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 kthread
9 root 10 -5 0 0 0 S 0.0 0.0 0:00.61 kblockd/0
10 root 20 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid
178 root 19 -5 0 0 0 S 0.0 0.0 0:00.00 cqueue/0
181 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khubd
183 root 20 -5 0 0 0 S 0.0 0.0 0:00.00 kseriod
启用https功能:
[root@localhost pma]# cd(切换到用户家目录)
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
LoadModule ssl_module modules/mod_ssl.so(启用mod_ssl.so功能)
Include /etc/httpd/extra/httpd-ssl.conf(启用httpd-ssl.conf配置文件)
/LoadModule
[root@localhost ~]# vim /etc/httpd/extra/httpd-ssl.conf(编辑httpd-ssl.conf配置文件)
Listen 443(监听端口)
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5(支持的加密算法)
SSLPassPhraseDialog builtin
DocumentRoot "/www/a.org"
ServerName www.a.org
ServerAdmin you@example.com
ErrorLog "/usr/local/apache/logs/error_log"
TransferLog "/usr/local/apache/logs/access_log"
SSLCertificateFile "/etc/httpd/server.crt"(证书)
SSLCertificateKeyFile "/etc/httpd/server.key"(私钥)
提示:ssl只能够一个IP地址建立一个主机,因为ssl会话是基于IP地址来实现的;
[root@localhost ~]# cd /etc/httpd/extra/(切换到/etc/httpd/extra目录)
[root@localhost extra]# ls(查看当前目录文件及子目录)
httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf
httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf
httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf
[root@localhost extra]# vim httpd-mpm.conf(编辑httpd-mpm.conf文件)
<IfModule mpm_event_module>
StartServers 3(进程个数)
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400(最大并发请求数)
MaxConnectionsPerChild 0
</IfModule>
提示:定义不同的MPM的工作参数,在rpm安装在主配置文件提供;
[root@localhost extra]# vmstat 1(查看系统进程、内存、I/O运行状态)
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 124 130604 32960 147416 0 0 17 57 225 153 1 5 93 1 0
0 0 124 130604 32960 147412 0 0 0 0 1680 186 0 5 95 0 0
2 0 124 130604 32968 147404 0 0 0 28 1656 183 0 5 94 1 0
0 0 124 130604 32968 147412 0 0 0 0 1678 191 0 7 93 0 0
0 0 124 130604 32968 147412 0 0 0 0 1670 182 0 6 94 0 0
[root@localhost ~]# ab -c 100 -n 1000 http://www.a.org/test.html(压力测试,-c并发量,-n请求总数)
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (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: www.a.org
Server Port: 80
Document Path: /test.html
Document Length: 146292 bytes
Concurrency Level: 100
Time taken for tests: 0.418 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 146553000 bytes
HTML transferred: 146292000 bytes
Requests per second: 2393.99 [#/sec] (mean)
Time per request: 41.771 [ms] (mean)
Time per request: 0.418 [ms] (mean, across all concurrent requests)
Transfer rate: 342624.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 12 7.5 12 35
Processing: 6 28 60.8 19 408
Waiting: 0 20 62.1 10 408
Total: 27 41 58.7 31 411
Percentage of the requests served within a certain time (ms)
50% 31
66% 32
75% 32
80% 32
90% 39
95% 42
98% 405
99% 408
100% 411 (longest request)
[root@localhost extra]# vmstat 1(查看系统进程、内存、I/O运行状态)
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 124 128584 33168 147520 0 0 17 57 229 153 1 5 93 1 0
0 0 124 128592 33176 147520 0 0 0 28 1668 235 0 5 93 2 0
0 0 124 126692 33176 147604 0 0 0 0 1732 15685 11 35 54 0 0
0 0 124 126816 33176 147620 0 0 0 0 1664 210 0 4 96 0 0
0 0 124 126816 33176 147620 0 0 0 0 1690 219 0 5 95 0 0
0 0 124 126816 33176 147620 0 0 0 0 1683 230 1 4 95 0 0
0 0 124 126816 33176 147620 0 0 0 0 1670 225 0 7 93 0 0
0 0 124 127088 33184 147620 0 0 0 200 1673 233 0 5 95 0 0
0 0 124 127240 33184 147732 0 0 0 0 1726 15684 13 33 54 0 0
0 0 124 127240 33184 147724 0 0 0 0 1678 201 0 4 96 0 0
0 0 124 127240 33184 147724 0 0 0 12 1686 203 0 6 94 0 0
0 0 124 127364 33184 147724 0 0 0 0 1663 191 0 5 95 0 0
0 0 124 127364 33192 147716 0 0 0 204 1678 201 0 5 95 0 0
httpd
fastcgi
2.4,fcgi
php
cgi
module
fastcgi(fpm)
编译安装php-5.4.13
首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp。
# tar xf php-5.4.13.tar.bz2
# cd php-5.4.13
# ./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 --enable-fpm --with-mcrypt --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开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make
# make intall
为php提供配置文件:
# cp php.ini-production /etc/php.ini
3、配置php-fpm
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
当PHP以fastcgi方式工作的时候,它也是自动启动一个服务器,而且这个服务器要监听众多进程,这个服务器要监听在127.0.0.1:9000端口,并且它会启动N个空闲进程,可以自己定义,刚开机的时候可以启动几个,默认最小有几个,最多有几个跟apache的prefork模型工作是一样的,需要修改php-fpm.cnf文件;
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 50(最多有几个子进程)
pm.start_servers = 5(刚开始启动几个空闲进程)
pm.min_spare_servers = 2(最少有几个空闲进程)
pm.max_spare_servers = 8(最多有几个空闲进程)
pid = /usr/local/php/var/run/php-fpm.pid(定义pid文件)
接下来就可以启动php-fpm了:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验正其是否已经监听在相应的套接字。
# netstat -tnlp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm
如果apache跟php在同一台主机上fpm监听在127.0.0.1的9000端口没问题,但是如果apache跟php不在同一台主机就必须要指定监听外网IP,能够外网连接进外部地址的IP地址,这时候apache完全可以工作在前端主机上,而php工作在后端主机上,它俩使用套接字,前端作为客户端向php发起连接请求,这php服务器端接收请求,php的解码请求都交由它来完成,由于php现在不是apache的模块了,它是fastcgi方式工作的,所以这时候还要配置apche,配置httpd能够以fcgi的方式跟后端的phpfpm结合起来工作;
配置httpd-2.4.4
1、启用httpd的相关模块
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2、配置虚拟主机支持使用fcgi
在相应的虚拟主机中添加类似如下两行。
ProxyRequests Off(关闭apache正向代理功能).100.2/imags/a.jpg
ProxyPass /images/a.jpg httpd://172.16.100.2/images/a.jpg(ProxyPass只能转换URI到另外一个URL路径)
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1(ProxyPassMatch能够支持正则表达式,中间的内容可以以正则表达式方式,当用户请求的是.php内容转交给fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1,$1前向引用,前一个括号中的内容)
http://172.1.100.1/images/a.jpg(反向代理,当客户端请求一个内容的时候,服务器自身没有,它到另外一台服务器上取得相应内容,并且在取得以后,先取到本地再返回给客户端,这种机制叫做反向代理)
例如:
<VirtualHost *:80>
DocumentRoot "/www/magedu.com"
ServerName magedu.com
ServerAlias www.magedu.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/magedu.com/$1
<Directory "/www/magedu.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
ProxyRequests Off:关闭正向代理
ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
3、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
补充:Apache httpd 2.4以前的版本中,要么把PHP作为Apache的模块运行,要么添加一个第三方模块支持PHP-FPM实现。
准备工作:已经编译好了apache2.4.4版本,跟此前的编译安装方法是一样的,而且现在已经启动起来了(请参考24_01_编译安装LAMP之httpd-2.4.4);
测试:通过windows的ie浏览器访问172.16.100.1;

使用通用二进制格式包安装MySQL 5.6版本:
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.4.tar.bz2 install.log.syslog
apr-1.4.6 apr-util-1.4.1 httpd-2.4.4 install.log mysql-5.6.10-linux-glibc2.5-i686.tar.gz
[root@localhost ~]# tar xf mysql-5.6.10-linux-glibc2.5-i686.tar.gz -C /usr/local(解压mysql-5.6.10,x解压,f后面跟文件名,-C更改解压节目里)
数据文件存放位置仍然沿用前面的位置,mysql用户已经建立好了,/mydata/data已经建立好了,逻辑卷mydata挂载已经完成,已经挂载到/mydata目录下,在/mydata目录下,
已经有个目录叫做data,并且属主属组已经是mysql(请参考24_02_编译安装LAMP之MySQL-5.5.28(通用二进制格);
[root@localhost ~]# id mysql(查看mysql用户信息)
uid=306(mysql) gid=306(mysql) groups=306(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@localhost ~]# lvs(查看系统上LV逻辑卷信息)
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mydata myvg -wi-ao 5.00G
[root@localhost ~]# mount(查看系统上所有已经挂载的文件系统)
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sr0 on /media type iso9660 (ro)
/dev/mapper/myvg-mydata on /mydata type ext3 (rw)
[root@localhost ~]# ls -l /mydata/(查看/mydata目录下文件及子目录详细信息)
total 24
drwxr-x--- 2 mysql mysql 4096 Sep 30 14:03 data
drwx------ 2 root root 16384 Sep 30 13:55 lost+found
[root@localhost ~]# cd /usr/local/(切换到/usr/local目录)
[root@localhost local]# ls(查看当前目录文件及子目录)
apache apr-util etc include libexec sbin src
apr bin games lib mysql-5.6.10-linux-glibc2.5-i686 share
[root@localhost local]# ln -sv mysql-5.6.10-linux-glibc2.5-i686/ mysql(为mysql-5.6.10创建软连接叫mysql,-s软连接,-v显示创建过程)
create symbolic link `mysql' to `mysql-5.6.10-linux-glibc2.5-i686/'
[root@localhost local]# cd mysql(切换到mysql目录)
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 root root 4096 Sep 30 13:48 bin
-rw-r--r-- 1 7161 wheel 17987 Jan 23 2013 COPYING
drwxr-xr-x 4 root root 4096 Sep 30 13:48 data
drwxr-xr-x 2 root root 4096 Sep 30 13:48 docs
drwxr-xr-x 3 root root 4096 Sep 30 13:48 include
-rw-r--r-- 1 7161 wheel 7468 Jan 23 2013 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 Sep 30 13:48 lib
drwxr-xr-x 4 root root 4096 Sep 30 13:48 man
drwxr-xr-x 10 root root 4096 Sep 30 13:48 mysql-test
-rw-r--r-- 1 7161 wheel 2552 Jan 23 2013 README
drwxr-xr-x 2 root root 4096 Sep 30 13:48 scripts
drwxr-xr-x 28 root root 4096 Sep 30 13:48 share
drwxr-xr-x 4 root root 4096 Sep 30 13:48 sql-bench
drwxr-xr-x 3 root root 4096 Sep 30 13:48 support-files
[root@localhost mysql]# chown -R mysql.mysql .(更改当前目录文件及子目录属主属组为mysql,-R递归更改)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 bin
-rw-r--r-- 1 mysql mysql 17987 Jan 23 2013 COPYING
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 data
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 include
-rw-r--r-- 1 mysql mysql 7468 Jan 23 2013 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 man
drwxr-xr-x 10 mysql mysql 4096 Sep 30 13:48 mysql-test
-rw-r--r-- 1 mysql mysql 2552 Jan 23 2013 README
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 scripts
drwxr-xr-x 28 mysql mysql 4096 Sep 30 13:48 share
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 sql-bench
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 support-files
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data(执行mysql_install_db脚本,--user=mysql指定
运行用户,--datadir=/mydata/data数据文件目录)
提示:在mysql5.6中,尤其是5.6.8以后版本中的mysql_install_db脚步,它会自动在mysql当前目录创建配置文件叫my.cnf,以后直接使用这个配置文件就可以了,
不用专门把它复制到/etc目录下去,直接编辑这个文件就可以,这个文件是叫做basedir下的文件,所以不再需要复制到/etc/my.cnf,复制也可以,而且mysql5.5的
配置文件这里照样可以使用;
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin data include lib my.cnf README share support-files
COPYING docs INSTALL-BINARY man mysql-test scripts sql-bench
[root@localhost mysql]# cd support-files/(切换到support-files目录)
[root@localhost support-files]# ls(查看当前目录文件及子目录)
binary-configure my-default.cnf mysql-log-rotate solaris
magic mysqld_multi.server mysql.server
提示:support-files下提供的文件及少了,mysql.server服务启动脚步;
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld(复制mysql.server到/etc/init.d叫mysqld)
[root@localhost support-files]# chkconfig --add mysqld(将mysqld假如到服务列表中)
[root@localhost support-files]# chkconfig --list mysqld(查看mysqld在不同系统级别启动情况)
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost support-files]# ls(查看当前目录文件及子目录)
binary-configure my-default.cnf mysql-log-rotate solaris
magic mysqld_multi.server mysql.server
提示:在这个目录下有my-default.cnf文件,没有my-small.cnf、my-large.cnf,只有my-default.cnf文件,而且这个配置文件非常简单;
[root@localhost support-files]# cat my-default.cnf(查看my-default.cnf文件内容)
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
提示:建议还是使用mysql5.5的提供的样例配置文件;
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf(复制my-default.cnf到/etc叫my.cnf)
[root@localhost support-files]# vim /etc/my.cnf(编辑my.cnf文件)
# datadir = .....
datadir = /mydata/data(数据文件目录)
[root@localhost support-files]# cd ..(切换到上级目录)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 140
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 bin
-rw-r--r-- 1 mysql mysql 17987 Jan 23 2013 COPYING
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 data
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 include
-rw-r--r-- 1 mysql mysql 7468 Jan 23 2013 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 lib
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 man
-rw-r--r-- 1 root root 943 Sep 30 14:14 my.cnf
drwxr-xr-x 10 mysql mysql 4096 Sep 30 13:48 mysql-test
-rw-r--r-- 1 mysql mysql 2552 Jan 23 2013 README
drwxr-xr-x 2 mysql mysql 4096 Sep 30 13:48 scripts
drwxr-xr-x 28 mysql mysql 4096 Sep 30 13:48 share
drwxr-xr-x 4 mysql mysql 4096 Sep 30 13:48 sql-bench
drwxr-xr-x 3 mysql mysql 4096 Sep 30 13:48 support-files
[root@localhost mysql]# chown -R root .(更改当前目录所有文件属主为root,-R递归更改)
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 140
drwxr-xr-x 2 root mysql 4096 Sep 30 13:48 bin
-rw-r--r-- 1 root mysql 17987 Jan 23 2013 COPYING
drwxr-xr-x 4 root mysql 4096 Sep 30 13:48 data
drwxr-xr-x 2 root mysql 4096 Sep 30 13:48 docs
drwxr-xr-x 3 root mysql 4096 Sep 30 13:48 include
-rw-r--r-- 1 root mysql 7468 Jan 23 2013 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Sep 30 13:48 lib
drwxr-xr-x 4 root mysql 4096 Sep 30 13:48 man
-rw-r--r-- 1 root root 943 Sep 30 14:14 my.cnf
drwxr-xr-x 10 root mysql 4096 Sep 30 13:48 mysql-test
-rw-r--r-- 1 root mysql 2552 Jan 23 2013 README
drwxr-xr-x 2 root mysql 4096 Sep 30 13:48 scripts
drwxr-xr-x 28 root mysql 4096 Sep 30 13:48 share
drwxr-xr-x 4 root mysql 4096 Sep 30 13:48 sql-bench
drwxr-xr-x 3 root mysql 4096 Sep 30 13:48 support-files
[root@localhost mysql]# service mysqld start(启动mysqld服务)
Starting MySQL. [ OK ]
编辑环境变量输出MySQL命令:
[root@localhost mysql]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# /usr/local/mysql/bin/mysql(连接mysql服务器)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.10 MySQL Community Server (GPL)(版本为5.6.10)
Copyright (c) 2000, 2013, 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> \q(退出mysql)
Bye
重新打开连接xhell终端,让重读PATH环境变量;
[root@localhost ~]# mysql(连接mysql服务器)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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> \q(退出mysql)
Bye
MySQL头文件输出、库文件输出、man文件输出不再演示(请参考24_02_编译安装LAMP之MySQL-5.5.28(通用二进制格);
编辑php-5.4.13:
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg apr-util-1.4.1 httpd-2.4.4.tar.bz2 mysql-5.6.10-linux-glibc2.5-i686.tar.gz
apr-1.4.6 apr-util-1.4.1.tar.bz2 install.log php-5.4.13.tar.bz2
apr-1.4.6.tar.bz2 httpd-2.4.4 install.log.syslog
[root@localhost ~]# tar xf php-5.4.13.tar.bz2(解压php-5.4.13)
[root@localhost ~]# cd php-5.4.13(切换到php-5.4.13目录)
配置前需要安装mhash-0.9.2-6.el5.i386.rpm mhash-devel-0.9.2-6.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el
5.i386.rpm等软件包,不然不能使用--with-mcrypt选项(请参考24_02_编译安装LAMP之MySQL-5.5.28(通用二进制格式));
[root@localhost php-5.4.13]# ./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 --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/p
hp.d --with-bz2(配置php)
提示:当编译安装完成这种方式的php之后,它会自动的在php的安装目录下给我们生成一个叫做fpm或者叫做phpfpm的二进制程序,而且还提供了配置文件,这个配置文件也
只有默认配置,需要给它复制为其所需要的配置文件才可以;
[root@localhost php-5.4.13]# make && make install(编译并安装php)
[root@localhost php-5.4.13]# cp php.ini-production /etc/php.ini(复制php.ini-production到/etc叫php.ini)
[root@localhost php-5.4.13]# ls(查看当前目录文件及子目录详细信息)
acinclude.m4 generated_lists Makefile.objects README.MAILINGLIST_RULES server-tests-config.php
aclocal.m4 genfiles makerpm README.namespaces server-tests.php
build header missing README.NEW-OUTPUT-API snapshot
buildconf include mkinstalldirs README.PARAMETER_PARSING_API stamp-h.in
buildconf.bat INSTALL modules README.PHP4-TO-PHP5-THIN-CHANGES stub.c
CODING_STANDARDS install-sh netware README.REDIST.BINS svnclean.bat
config.guess libs NEWS README.RELEASE_PROCESS tests
config.log libtool pear README.SELF-CONTAINED-EXTENSIONS TSRM
config.nice LICENSE php5.spec README.STREAMS UPGRADING
config.status ltmain.sh php5.spec.in README.SUBMITTING_PATCH UPGRADING.INTERNALS
config.sub main php.gif README.TESTING vcsclean
configure makedist php.ini-development README.TESTING2 win32
configure.in Makefile php.ini-production README.UNIX-BUILD-SYSTEM Zend
CREDITS Makefile.frag README.EXTENSIONS README.WIN32-BUILD-SYSTEM
ext Makefile.fragments README.EXT_SKEL run-tests.php
EXTENSIONS Makefile.gcov README.GIT-RULES sapi
footer Makefile.global README.input_filter scripts
[root@localhost php-5.4.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm(复制init.d.php-fpm到/etc/init.d目录叫php-fpm)
[root@localhost php-5.4.13]# chmod +x /etc/init.d/php-fpm(给php-fpm文件执行权限)
[root@localhost php-5.4.13]# chkconfig --add php-fpm(讲php-fpm添加到服务列表)
[root@localhost php-5.4.13]# chkconfig --list php-fpm(查看php-fpm在不同系统级别启动情况)
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost php-5.4.13]# cd /usr/local/php/etc/(切换到/usr/local/php/etc目录)
[root@localhost etc]# ls(查看当前目录文件及子目录)
pear.conf php-fpm.conf.default
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf(复制php-fpm.conf.default叫php-fpm.conf)
[root@localhost etc]# vim php-fpm.conf(编辑php-fpm.conf配置文件)
listen = 127.0.0.1:9000(指定监听端口)
pm = dynamic(动态创建多少个进程)
pm.max_children = 100(最多多少个进程同时在线)
pm.start_servers = 5(启动服务器时启动多少个进程)
pm.min_spare_servers = 5(最少有多少空闲进程)
pm.max_spare_servers = 8(最多有多少空闲进程)
;pm.max_requests = 500(同时允许连接多少请求)
[root@localhost etc]# service php-fpm start(启动php-fpm服务)
Starting php-fpm done
[root@localhost etc]# netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p显示服务名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3494/./hpiod
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7449/php-fpm
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3175/portmap
tcp 0 0 0.0.0.0:852 0.0.0.0:* LISTEN 3214/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3515/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3527/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3564/sendmail
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 7369/sshd
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3499/python
tcp 0 0 :::3306 :::* LISTEN 29073/mysqld
tcp 0 0 :::80 :::* LISTEN 32537/httpd
tcp 0 0 :::22 :::* LISTEN 3515/sshd
tcp 0 0 ::1:6011 :::* LISTEN 7369/sshd
配置PHP使用虚拟主机:
[root@localhost etc]# cd(切换到用户家目录)
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
#DocumentRoot "/usr/local/apache/htdocs"(注释中心主机)
Include /etc/httpd/extra/httpd-vhosts.conf(启用虚拟主机配置文件)
/DocumentRoot
[root@localhost ~]# vim /etc/httpd/extra/httpd-vhosts.conf(编辑虚拟主机配置文件)
<VirtualHost *:80>
DocumentRoot "/www/a.org/"
ServerName www.a.org
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/a.org/$1
<Directory "www/a.org">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
:.,$d
[root@localhost ~]# httpd -t(检查配置文件语法)
AH00526: Syntax error on line 26 of /etc/httpd/extra/httpd-vhosts.conf:
Invalid command 'ProxyRequests', perhaps misspelled or defined by a module not included in the server configuration
提示:报错ProxyRequests是什么东西,可能是一个模块,但是没有启用;
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
/LoadModule
/proxy
[root@localhost ~]# httpd -t(检查配置文件语法)
Syntax OK
[root@localhost ~]# vim /etc/httpd/httpd.conf(编辑httpd.conf配置文件)
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
/AddType
/DirectoryIndex
[root@localhost ~]# ls /www/a.org/(查看/www/a.org目录文件及子目录)
index.html
[root@localhost ~]# httpd -t(检查httpd语法)
Syntax OK
[root@localhost ~]# service httpd restart(重启httpd服务)
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
测试:通过windows的ie浏览器输入www.a.org访问,无法访问;

[root@localhost ~]# tail /usr/local/apache/logs/dummy-host.example.com-error_log(查看错误日志信息后10行) [Wed Sep 30 18:29:04.181948 2015] [proxy_fcgi:error] [pid 5856:tid 3075406736] [client 172.16.100.254:7546] AH01071: Got error 'Primary script unknown\n' [Wed Sep 30 18:29:06.944205 2015] [proxy_fcgi:error] [pid 5856:tid 3054427024] [client 172.16.100.254:7571] AH01071: Got error 'Primary script unknown\n' [root@localhost ~]# cd /www/a.org/(切换到/www/a.org目录) [root@localhost a.org]# ls(查看当前目录文件及子目录) index.html [root@localhost a.org]# vim index.html(编辑index.html文件) <h1>www.a.org</h1> [root@localhost a.org]# ls(查看当前目录文件及子目录) index.html [root@localhost a.org]# mv index.html index.php(更改index.html叫index.php) [root@localhost a.org]# vim index.php(编辑index.php文件) <h1>www.a.org</h1> <?php phpinfo(); ?>
测试:通过windows的ie浏览器输入www.a.org访问;

让FastCGI使用xcache:
[root@localhost a.org]# cd(切换到用户家目录) [root@localhost ~]# ls(查看当前目录文件及子目录) anaconda-ks.cfg libmcrypt-2.5.7-5.el5.i386.rpm apr-1.4.6 libmcrypt-devel-2.5.7-5.el5.i386.rpm apr-1.4.6.tar.bz2 mhash-0.9.2-6.el5.i386.rpm apr-util-1.4.1 mhash-devel-0.9.2-6.el5.i386.rpm apr-util-1.4.1.tar.bz2 mysql-5.6.10-linux-glibc2.5-i686.tar.gz httpd-2.4.4 php-5.4.13 httpd-2.4.4.tar.bz2 php-5.4.13.tar.bz2 install.log xcache-3.0.1.tar.bz2 install.log.syslog [root@localhost ~]# tar xf xcache-3.0.1.tar.bz2(解压xcache-3.0.1,x解压,f后面跟文件) [root@localhost ~]# cd xcache-3.0.1(切换到xcache-3.0.1) [root@localhost xcache-3.0.1]# /usr/local/php/bin/phpize(执行phpize脚本) Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@localhost xcache-3.0.1]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config(配置xcache,--enable-xc ache启用xcache,--with-php-config指定php配置文件) [root@localhost xcache-3.0.1]# make(编译) [root@localhost xcache-3.0.1]# make install(安装) Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ [root@localhost xcache-3.0.1]# mkdir /etc/php.d(创建php.d目录) [root@localhost xcache-3.0.1]# cp xcache.ini /etc/php.d/(复制xcache.ini到/etc/php.d目录) [root@localhost xcache-3.0.1]# vim /etc/php.d/xcache.ini(编辑xcache.ini文件) [root@localhost xcache-3.0.1]# service php-fpm restart(重启php-fpm服务) Gracefully shutting down php-fpm done Starting php-fpm done
测试:通过windows的ie浏览器输入www.a.org访问;

[root@localhost xcache-3.0.1]# cd /www/a.org/(切换到/www/a.org目录) [root@localhost a.org]# vim test.html(编辑test.html文件) html test
测试:通过windows的ie浏览器输入www.a.org/test.html访问

查看pma能否工作:
[root@localhost a.org]# cd(切换到用户家目录) [root@localhost ~]# ls(查看当前目录文件及子目录) anaconda-ks.cfg install.log php-5.4.13 apr-1.4.6 install.log.syslog php-5.4.13.tar.bz2 apr-1.4.6.tar.bz2 libmcrypt-2.5.7-5.el5.i386.rpm phpMyAdmin-3.5.1-all-languages.tar.bz2 apr-util-1.4.1 libmcrypt-devel-2.5.7-5.el5.i386.rpm xcache-3.0.1 apr-util-1.4.1.tar.bz2 mhash-0.9.2-6.el5.i386.rpm xcache-3.0.1.tar.bz2 httpd-2.4.4 mhash-devel-0.9.2-6.el5.i386.rpm httpd-2.4.4.tar.bz2 mysql-5.6.10-linux-glibc2.5-i686.tar.gz [root@localhost ~]# tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2 -C /www/a.org/(解压phpMyAdmin,x解压,f后面跟文件名,-C更改解压目录) cd[root@localhost ~]# cd /www/a.org/(切换到/www/a.org目录) [root@localhost a.org]# ls(查看当前目录文件及子目录) index.php phpMyAdmin-3.5.1-all-languages test.html [root@localhost a.org]# mv phpMyAdmin-3.5.1-all-languages/ pma(更改phpMyAdmin叫pma) [root@localhost a.org]# ls(查看当前目录文件及子目录) index.php pma test.html [root@localhost a.org]# cd pma/(切换到pma目录) [root@localhost pma]# cp config.sample.inc.php config.inc.php(复制config.sample.inc.php叫config.inc.php) [root@localhost pma]# vim config.inc.php(编辑config.inc.php文件) $cfg['blowfish_secret'] = 'fdsfdsaa8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
测试:通过windows的ie浏览器访问www.a.org/pma;

[root@localhost pma]# mysqladmin -uroot password 'redhat'(给root用户提供密码)
通过用户root密码redhat登录,执行;

浙公网安备 33010602011771号