网络拓扑图
Web服务器
系统/内核/IP: CentOS release 6.6 (Final) uname -r
2.6.32-504.el6.x86_64eth0: 172.16.6.61 ech1 : 192.168.6.61
Apache版本 : Apache/2.4.10
Php应用服务器
系统/内核/IP: CentOS release 6.6 (Final) uname -r
2.6.32-504.el6.x86_64eth0: 192.168.6.62
Php : php-5.4.40
xcache版本:xcache-3.2.0
数据库版本:mariadb-5.5.43-linux-x86_64.tar.gz
数据库服务器
系统/内核/IP: CentOSrelease 6.6 (Final) uname -r
2.6.32-504.el6.x86_64eth1: 192.168.6.63
数据库版本:mariadb-5.5.43-linux-x86_64.tar.gz
#添加运行mysql的用户和用户组
groupadd -g 306 mysql
useradd -r -u 306 -g 306 -s/sbin/nologin mysql
id mysql
#uid=306(mysql)gid=306(mysql) groups=306(mysql)
安装mariadb
tar xvfmariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
#创建符号链接
ln -smariadb-5.5.43-linux-x86_64 mysql
ls -lh mysql
#lrwxrwxrwx 1 root root 27May 3 19:54 mysql ->mariadb-5.5.43-linux-x86_64
#为mysql提供服务器控制脚本
cp support-files/mysql.server/etc/init.d/mysqld
chmod u+X /etc/init.d/mysqld
#授权mysql 为mysql数据目录的的属主
chown -R root.mysql/usr/local/mariadb-5.5.43-linux-x86_64/
chown mysql.root /data/mydata
初始化MySQL数据库
/usr/local/mysql/scripts/mysql_install_db--user=mysql --datadir=/data/mydata/
#为mysql提供主配置文件
cd mysql/
cpsupport-files/my-large.cnf /etc/my.cnf
#修改my.cnf 添加数据目录的位置
[root@localhost mysql]# vim/etc/my.cnf
....
[mysqld]
datadir = /data/mydata
...
启动mysql
/etc/init.d/mysqld start
添加mysqld至服务列表
# chkconfig --add mysqld
# chkconfig mysqld on
php应用服务器需要安装MySQL 安装方法如 mysql服务器一样 #也可以使用yum安装mysql
安装开发环境
yum groupinstall"Development tools" "Server Platform Development""Desktop Platform Development" "Debug Tools" -y
PHPrpm包的依赖关系
yum install bzip2-devel -y
yum install -ylibmcrypt-devel
安装php
tar xvf php-5.4.40.tar.bz2
cd php-5.4.40
./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
make && make install
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
为php提供配置文件 #cp 解压的源代码树下的php.ini-production
cp php.ini-production/etc/php.ini
为php-fpm提供配置文件
cd /usr/local/php/etc/
cp -a php-fpm.conf.defaultphp-fpm.conf
修改php-fpm.conf
...
listen = 192.168.6.62:9000 #监听在外网地址接受前端httpd服务器的请求
...
为php-fpm提供服务控制脚本,并将其添加至服务列表
cpsapi/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
/etc/init.d/php-fpm start
验正php进程是否启动成功
# ps aux | grep php-fpm #用于查看php进程
# netstat -tnlp | grep php-fpm #用于查看php是否监听在响应的套接字上
#安装apr
tar xvf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure--prefix=/usr/local/apr
make && make install
cd ..
安装apr-util
tar xvfapr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
cd ../
安装httpd-2.4.10
#解决pcre的依赖关系
yum install pcre-devel �Cy
tar xvf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure--prefix=/usr/local/httpd24 --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-modules=most--enable-mpms-shared=all --with-mpm=event
make && make install
cd ../
加载代理模块配置修改httpd.conf
LoadModule proxy_modulemodules/mod_proxy.so
LoadModule proxy_fcgi_modulemodules/mod_proxy_fcgi.so
#配置虚拟主机
修改httpd.conf
/usr/local/httpd24/conf/httpd.conf
# Virtual hosts
Includeconf/extra/httpd-vhosts.conf
#配置httpd-vhosts.conf
<Directory"/data/web">
Options none
AllowOverride none
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/data/web/a.com"
ServerName www.a.com
ServerAlias a.com
ErrorLog "logs/a.com-error_log"
CustomLog "logs/b.com-access_log"common
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$fcgi://192.168.6.62:9000/data/web/a.com/$1
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/web/b.com"
ServerName www.b.com
ServerAlias b.com
ErrorLog "logs/b.com-error_log"
CustomLog "logs/b.com-access_log"common
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$fcgi://192.168.6.62:9000/data/web/b.com/$1
</VirtualHost>
#分别在web服务器 和 php应用服务上创建网站根目录
mkdir /data/web/{a.com,b.com}
#在mysql服务器创建用户并授权
MariaDB [(none)]> createdatabase pmdb;
Query OK, 1 row affected(0.00 sec)
MariaDB [(none)]> create databasedzdb;
Query OK, 1 row affected(0.00 sec)
MariaDB [(none)]> grantall on pmdb.* to 'pmuser'@'192.168.662'identified by '123456';
Query OK, 0 rows affected(0.00 sec)
MariaDB [(none)]> grantall on dzdb.* to 'dzuser'@'192.168.6.%'identified by '123456';
Query OK, 0 rows affected(0.00 sec)
MariaDB [(none)]> flushprivileges;
Query OK, 0 rows affected(0.00 sec)
在php应用服务器上提供php连接mysql的测试页
cat >/data/web/a.com/testmysql.php <<EOP
<?php
$link =mysql_connect('192.168.6.63','pmuser','123456');
if ($link)
echo " pmuser Success...";
else
echo "Failure...";
mysql_close();
?>
<<EOP
cat >/data/web/b.com/testmysql.php <<EOP
<?php
$link =mysql_connect('192.168.6.63','dzuser','123456');
if ($link)
echo " dzuser Success...";
else
echo "Failure...";
mysql_close();
?>
<<EOP
访问
tar xvf xcache-3.2.0.tar.bz2
cd xcache-3.2.0
/usr/local/php/bin/phpize
./configure --enable-xcache -with-php-config=/usr/local/php/bin/php-config
make && make install
#在编译安装最后
###
#Installing sharedextensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
###
提供xcache.ini
mkdir /etc/php.d
cp xcache.ini /etc/php.d/ #在xcache源代码书目录下
修改xcache.ini
[[email protected]]# vim /etc/php.d/xcache.ini
修改extension = xcache.so 为
extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
访问测试
部署 phpmyadmin到www.a.com
部署 discuz到www.b.com