- [root@localhost ~]#tar xf apr-1.4.6.tar.bz2
- [root@localhost ~]#cd apr-1.4.6
- [root@localhost apr-1.4.6]#./configure --prefix=/usr/local/apr
- #####软件包安装的路径统一放在第三方软件位置:/usr/local/
- [root@localhost apr-1.4.6]#make
- [root@localhost apr-1.4.6]#make install
- [root@localhost ~]#tar xf apr-util-1.5.2.tar.bz2
- [root@localhost ~]#cd apr-util-1.5.2
- [root@localhost apr-util-1.5.2]#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
- ####指定apr-util和apr安装路径
- [root@localhost ~]# yum install pcre-devel
- [root@localhost ~]# tar xf httpd-2.4.4.tar.bz2
- [root@localhost ~]# cd httpd-2.4.4
- [root@localhost httpd-2.4.4]#./configure --prefix=/usr/local/apache –sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event
- 说明:--prefix=/usr/local/apache ####httpd安装路径
- --sysconfdir=/etc/httpd ####系统配置文件目录路径
- --enable-so ######支持共享模块功能
- --enable-ssl #####支持ssl功能
- --enable-cgi ####支持cgi功能
- --enable-rewrite ####支持重写功能
- --with-zlib #####支持扩展库文件功能
- --with-pcre #####支持pcre功能
- --with-apr=/usr/local/apr ######指定apr安装路径
- --with-apr-util=/usr/local/apr-util #####指定apr-util安装路径
- --enable-mpms-shared=all #####表示此平台的mpm模块都会被安装
- --with-mpm=event #####特指定mpm模块为event,mpm模块可以在配置文件中修改
- [root@localhost httpd-2.4.4]#make
- [root@localhost httpd-2.4.4]#setenforce 0 #####由于web服务是受selinux控制会导致系统运行不起来,要把selinux的功能关掉
- [root@localhost httpd-2.4.4]#make install
- [root@localhost httpd-2.4.4]#vim /etc/httpd/httpd.conf
- 添加内容:PidFile “/var/run/httpd.pid”
- 保存退出
- [root@localhost ~]#vim /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 #####指定pid的配置文件
- # Source function library.
- . /etc/rc.d/init.d/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赋值给HTTPD_LANG
- # 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 ###指定apachectr文件路径
- httpd=${HTTPD-/usr/local/apache/bin/httpd} ####如果没有指定httpd,就把后面的路径赋值给httpd
- prog=httpd
- pidfile=${PIDFILE-/var/run/httpd.pid} ####如果没有指定pidfile路径,就把后面的路径赋值给pidfile文件
- lockfile=${LOCKFILE-/var/lock/subsys/httpd} ###如果没有指定lockfile路径,就把后面的路径赋值给lockfile文件
- 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 httpd-2.4.4]#chmod +x /etc/rc.d/init.d/httpd ####为脚本赋予执行权限
- [root@localhost ~]#tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
- [root@localhost ~]#cd /usr/local/
- [root@localhost local]# ln -sv mysql-5.5.28-linux2.6-i686 mysql ########为了保全mysql的路径、版本,要为此软件包创建链接
- [root@localhost local]# cd mysql
- [root@localhost mysql]#groupadd –r –g 306 mysql
- [root@localhost mysql]#useradd –g 306 –r –u 306 mysql
- [root@localhost mysql]#chown –R mysql.mysql /usr/local/mysql/*
- 在mysql目录下有个默认存放数据的目录,不过以后存储数据的规模会逐渐变大,建议使用逻辑卷挂载数据目录,我使用逻辑卷挂载数据目录,假设逻辑卷的挂载目录为/mydata;
- [root@localhost mysql]#fdisk /dev/sda
- #创建一个为20G的分区sda5,并把文件系统类型改为8e
- [root@localhost mysql]#partprobe /dev/sda
- [root@localhost mysql]#pvcreate /dev/sda5 #####创建物理卷
- [root@localhost mysql]#vgcreate myvg /dev/sda5 ####创建卷组
- [root@localhost mysql]#lvcreate -n mydata -L 5G myvg #####创建逻辑卷
- [root@localhost mysql]# lvs ####查看创建情况
- LV VG Attr LSize Origin Snap% Move Log Copy% Convert
- mydata myvg -wi-a- 5.00G
- home vol0 -wi-ao 4.88G
- root vol0 -wi-aob 29.28G
- [root@localhost mysql]#mke2fs -j /dev/myvg/mydata ####格式化
- [root@localhost mysql]#mkdir /mydata ######创建目录,让逻辑卷挂载到这个目录下
- [root@localhost mysql]#vim /etc/fstab #####让其在开机时自动挂载
- /dev/myvg/mydata /mydata ext3 defaults 0 0
- 保存退出
- [root@localhost mysql]#mount -a ###挂载
- [root@localhost mysql]#mkdir /mydata/data #####为了数据便于管理,再创建一个子目录用来作为数据目录
- [root@localhost mysql]#chown -R mysql.mysql /mydata/data #####将来mysql用户要在数据目录下添加数据,要把数据目录的属主、属组都改为mysql
- [root@localhost mysql]#chmod o-rx /mydata/data ####为了数据的安全性,把数据目录修改不让其它人有任何权限
- [root@localhost mysql]#scripts/mysql_install_db --user=mysql --datadir=/mydata/data #########初始化mysql脚本,并指定用户和数据目录路径
- [root@localhost mysql]#chown -R root /usr/local/mysql/* #####初始化完成后,要把mysql目录下的属主改为root,防止其他人使用mysql用户进入/mysql下修改数据
- [root@localhost mysql]#cp suppor-files/mysql.server /etc/init.d/mysqld ####把服务器提供的脚本重命名为/etc/init.d/mysqld
- [root@localhost mysql]#ls -l /etc/init.d/mysqld ####注意查看该文件的是否有执行权限,如果没有要修改有执行权限
- -rwxr-xr-x 1 root root 10650 Mar 31 20:06 /etc/init.d/mysqld
- [root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf ###把配置文件重命名为/etc/my.cnf
- [root@localhost mysql]#vim /etc/my.cnf
- [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
- [root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
8 重启服务并查看mysql进程的端口
9 执行mysql数据库操作
- [root@localhost mysql]#vim /etc/profile.d/mysql.sh ##mysql和mysqld系统默认都安装过,创建/etc/profile.d/mysql.sh并把执行路径添加进来
- export PATH=$PATH:/usr/local/mysql/bin
- 保存退出
- [root@localhost mysql]#vim /etc/man.config
- [root@localhost mysql]#ln –sv /usr/local/mysql/include /usr/include/mysql ####通过创建链接实现
- [root@localhost mysql]#echo ‘/usr/local/mysql/lib’ > /etc/ld.so.conf.d/mysql.conf ##把查找路径追加到配置文件中
- [root@localhost mysql]#ldcofig –v ###让系统重新载入系统库,并把过程显示出来
1 编译安装php-5.4.13
- [root@localhost ~]# tar xf php-5.4.13.tar.bz2
- [root@localhost ~]# cd php-5.4.13
- [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-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
- 说明:
- --prefix=/usr/local/php:php安装路径
- --with-mysql=/usr/local/mysql:mysql安装路径
- --with-openssl:支持openssl功能
- --with-mysqli=/usr/local/mysql/bin/mysql_config:mysql与apache访问的另一种接口,安装在二进制目录下
- --enable-mbstring:多字节string
- --with-freetype-dir:安装的字体库头文件
- --with-jpeg-dir:jpeg类型的库
- --with-png-dir:png类型的库
- --with-zlib:互联网上通用压缩库,先压缩再传送,减少带宽
- --with-libxml-dir=/usr:xml库文件的路径
- --enable-xml:支持xml功能
- --enable-sockets:php支持套接字功能
- --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使用worker或event这两个MPM,编译时使用该选项
- ###我在执行./configure时候,出现了错误,提示我没有安装libmcrypt库文件,可以有两种解决方式:1、去掉该模块 2、下载依赖于该库文件的软件包,mhash*.rpm libmcrypt-*.rpm
- [root@localhost php-5.4.13]#make
- [root@localhost php-5.4.13]#make install
- [root@localhost php-5.4.13]#cp php.ini-production /etc/php.ini ##php包中提供了配置文件,把配置文件重命名为/etc/php.ini,php的配置文件后缀名是以.ini结尾
- [root@localhost php-5.4.13]#vim /etc/httpd/httpd.conf
- [root@localhost php-5.4.13]#cd /usr/local/apache/htdocs/ #####进入apache页面目录下,把默认页面修改为php页面文件
- [root@localhost php-5.4.13]#mv index.html index.php
- [root@localhost php-5.4.13]#vim index.php
- <html><body><h1>It works! my test page</h1></body></html>
- <?php
- phpinfo();
- ?>
- 保存退出
- #####发起php页面测试
- #####生成的测试页面内容对我们还是会有帮助,可以留意一下里面的内容
- <html><body><h1>It works! my test page</h1></body></html>
- <?php
- $conn=mysql_connect('localhost','root','');
- if ($conn)
- echo "<h2>Success...</h2>";
- else
- echo "<h2>Failure...</h2>";
- ?>
- 保存退出
- [root@localhost ~]# tar xf xcache-3.0.1.tar.gz
- [root@localhost ~]# cd xcache-3.0.1 ###xcache是php的扩展,要使用php命令加载此扩展
- [root@localhost xcache]# /usr/local/php/bin/phpize ####phpize命令作用是要准备一个php扩展准备编译,所以扩展要先执行编译
- [root@localhostxcache]#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
- #######php-config表示能够获取php的配置信息以及编译时的选项信息;
- ######由于不在默认路径下,xcache要获取php安装时所启用的功能,否则xcache会找不到php的路径
- [root@localhost xcache]#make
- [root@localhost xcache]#make install
- 安装结束时,会出现类似如下行:
- Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
- #####安装共享扩展模块路径,先把这个路径复制下来,等一下复制到xcache的配置文件中
- [root@localhost xcache]# mkdir /etc/php.d
- [root@localhost xcache]# cp xcache.ini /etc/php.d ###将xcache提供的样例配置导入php.ini
- [root@localhost xcache]#vim /etc/php.d/xcache.ini
- [root@localhost xcache]# service httpd restart ####模块是要被web加载,要启动web服务
- [root@localhost xcache]# vim /usr/local/apache/htdocs/index.php
- 添加一行:phpinfo();
- 保存退出并刷新页面
- [root@localhost xcache]#vim /etc/httpd/httpd.conf
- #DocumentRoot "/usr/local/apache/htdocs" #####一定要注释中心主机配置
- Include /etc/httpd/extra/httpd-vhosts.conf #######开启虚拟主机配置文件,默认有样例
- LoadModule log_config_module modules/mod_log_config.so #####开启mod_log功能,默认是启用的
- 保存退出
- [root@localhost xcache]#vim /etc/httpd/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>
- 保存退出
5 创建域名和日志的目录
- [root@localhost xcache]# mkdir /www/{a.org,b.net} –pv
- [root@localhost xcache]#mkdir /var/log/httpd/
- [root@localhost xcache]#echo "<h1>www.a.org</h1>" > /www/a.org/index.html
- [root@localhost xcache]#echo "<h1>www.b.net</h1>" > /www/b.net/index.html
- [root@localhost xcache]#httpd –t
- 过程:点击硬盘c盘---> Windows---> System32---> drivers---> etc--->hosts文件
- 添加如下内容:
- 172.16.52.2 www.a.org
- 172.16.52.2 www.b.net
- ######注意:不要忘记保存,点击保存按钮
- [root@localhost xcache]#service httpd restart
- [root@localhost xcache]#ab -c 10 -n 100 http://www.a.org/index.html
- 安装phpMyAdmin-3.5.1-all-languages.tar.bz2软件包到/www/b.net下
- [root@localhost ~]#tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2/ -C /www/b.net
- [root@localhost ~]#cd /www/b.net
- [root@localhost b.net]#mv phpMyAdmin-3.5.1-all-languages / pma
- [root@localhost b.net]#cd pma
- [root@localhost pma]#cp config.sample.inc.php config.inc.php #####软件包提供默认配置文件,重命名配置文件名称
- [root@localhost pma]#openssl rand -base64 10 ####生成10位的随机数,把生成的随机数复制到配置文件中
- [root@localhost pma]#vim config.inc.php ####编辑配置文件,把生成的随机数写在下面的位置
- $cfg['blowfish_secret'] = 'QkMTw3ZlpJlBKA'
- [root@localhost pma]#mysqladmin -uroot password 'redhat' ######生成root用户的密码,登录站点www.b.net/pma不允许使用空密码
- [root@localhost pma]#ab -c 100 -n 1000 http://www.b.net/pma/index.html ###动态页面压力测试
- [root@localhost pma]#vim /etc/httpd/httpd.conf ####进入配置文件启用ssl模块
- LoadModule ssl_module modules/mod_ssl.so ####启用模块
- Include /etc/httpd/extra/proxy-html.conf
- 保存退出
- [root@localhost pma]#vim /etc/httpd/extra/httpd-ssl.conf ####编辑此配置文件,添加虚拟主机
- <VirtualHost 172.16.52.2:443>
- DocumentRoot "/www/a.org"
- ServerName www.a.org
- ErrorLog "/var/log/httpd/a.org-error_log"
- TransferLog "/var/log/httpd/a.org-access_log"
- SSLCertificateFile "/etc/httpd/ssl/httpd.crt" ###证书文件放置的位置
- SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key" ####证书文件密钥放置的位置
- [root@localhost ~]#cd /etc/pki/
- [root@localhost pki]#cd CA/
- [root@localhost CA]#(umask 077; openssl genrsa -out private/cakey.pem 2048)
- [root@localhost CA]#vim ../tls/openssl.cnf
- countryName_default =CN
- stateOrProvinceName_default =Henan
- localityName_default =Zhengzhou
- O.organizationName_default =MageEdu
- organizationalUnitName_default =Tech
- ######这些默认信息可以根据自己需求自定义
11.5 为签证的证书准备目录和文件
- [root@localhost CA]#mkdir certs crl newcerts
- [root@localhost CA]#touch index.txt
- [root@localhost CA]#echo 01 > serial
- [root@ localhost ~]#cd /etc/httpd/
- [root@ localhost httpd]#mkdir ssl
- [root@ localhost httpd]#cd ssl/
- [root@ localhost ssl]#(umask 077; openssl genrsa 1024 > httpd.key)
- [root@ localhost ssl]#openssl req –new –key httpd.key –out httpd.csr
- 输入几个信息,这些信息和颁发证书的内容相同,除了主机名不同,这里应该写虚拟主机的主机名称:www.a.org
- [root@ localhost ssl]#openssl ca -in httpd.csr -out httpd.crt -days 365
- [root@ localhost ssl]#ll ####签证完成,在当前目录下自动生成几个文件
- [root@ localhost ssl]#cd /etc/pki/CA
- [root@ localhost CA]#cat index.txt #####显示CA证书中签证的记录
- [root@ localhost CA]#service httpd restart
- 物理机hosts文件路径:点击“本地磁盘C”—>Windows—>System32—>drivers—>etc—>hosts
- 添加:172.16.52.2 www.a.org
- ######在IE浏览器上测试站点,对虚拟主机进行域名解析