CentOS 6 编译LAMP 实现双机FastCGI
需求:
CenOS 6平台搭建LAMP,其中php作为独立的服务工作
(1)三者分离于两台主机
(2)一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机提供wordpress
(3)安装下cache,为php提供加速
(4)mpm为prefork模型
注意:
(1)由于httpd是cpu密集型,php是io密集型,而mariadb即是cpu密集型又是io密集型。所以我们将httpd和php放在一台主机上,mariadb单独放在一台主机上
(2)由于CentOS 6平台仅提供了mysql的rpm包,这里我们使用mariadb二进制安装包安装
(3)由于php要作为单独服务进程运行,因此编译php时要启用php-fpm特性
(4)由于CentOS 6提供的各应用的rpm安装包版本都比较老,所以都需要通过编译源码来安装
(5)httpd与php之间需要通过FastCGI协议来连接,httpd其实是作为反向代理来工作的,编译httpd时需要启用proxy和proxy_cgi特性
(6)如要求mpm问哦event模型,同时php作为httpd的模块工作时,因为event为线程模型,所以php必须启用线程安全功能--enable-maintainer-zts
环境:
关闭iptables和SELinux
Host1:作为前端web服务器 IP:10.0.0.61
Host2:作为后端DB服务器 IP:10.0.0.62
Linux修改/etc/hosts/
Windows修改C:\Windows\System32\drivers\etc
10.0.0.61 www.wordpress.com
10.0.0.61 www.phpadmin.com
配置:
Host2:
安装二进制的mariadb
# 增加一个系统用户mysql[root@localhost ~]# useradd -r mysql# 解压二进制安装包放置在`/usr/local/`目录下[root@localhost ~]# tar -xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/[root@localhost ~]# cd /usr/local/# 链接为`mysql`目录[root@localhost local]# ln -sv mariadb-5.5.46-linux-x86_64/ mysql`mysql' -> `mariadb-5.5.46-linux-x86_64/'# 修改其属主和属组[root@localhost local]# chown -R root:mysql mysql/# 创建数据库存放目录`/data/mysql`[root@localhost local]# mkdir -pv /data/mysqlmkdir: created directory `/data'mkdir: created directory `/data/mysql'# 修改其属主和属组。[root@localhost local]# chown -R mysql:mysql /data/mysql/# 安装[root@localhost local]# cd mysql/[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/# 复制服务启动脚本至`/etc/rc.d/init.d`目录[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
复制配置文件,并进行配置
# cp support-files/my-large.cnf /etc/my.cnf# vim /etc/my.cnf[client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]datadir=/data/mysqlcharacter-set-server=utf8collation-server=utf8_general_cidefault-storage-engine=InnoDBinnodb-file-per-table=TRUEskip-name-resolve=TRUE
数据库初始化:
# 启动数据库[root@localhost mysql]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS![root@cb9326a6 mysql]# ss -tunl | grep 3306tcp LISTEN 0 50 *:3306 *:*# 导出`/usr/local/mysql/bin/`目录至`PATH`系统环境变量[root@localhost mysql]# export PATH=/usr/local/mysql/bin/:$PATH# 数据库初始化设置[root@localhost mysql]# mysql_secure_installation
授权:
[root@localhost ~]# mysql -u root -p# 授权root可从10.0.0.0/8网段内的主机登录操作所有数据库。MariaDB [(none)]> grant all privileges on *.* to 'root'@'10.0.0.%' identified by '123456';# 给wordpress创建数据wpdb。MariaDB [(none)]> create database wordpress;# 给wordpress创建用户wordpress。MariaDB [(none)]> create user 'wordpress'@'172.18.71.%' identified by 'wordpress';# 授权wordpress可从10.0.0.0/8网段内的主机登录操作wordpress数据库。MariaDB [(none)]> grant all privileges on wpdb.* to 'wordpress'@'10.0.0.%' identified by 'wordpress';# 重载权限表MariaDB [(none)]> flush privileges;
Host1
测试能否链接数据库服务器
# 因为CentOS-6不提供mariadb,所以安装mysql的客户端。[root@localhost ~]# yum install -y mysql# 测试连接HostB数据库[root@localhost ~]# mysql -u root -h 10.0.0.62 -p
新增一个系统用户
# useradd -r apache
准备开发环境
# yum groupinstall -y "Development tools" "Server Platform Development"# yum install -y pcre-devel libxml2-devel libmcrypt-devel bzip2-devel libcurl-devel
准备好源码包:
apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 httpd-2.4.10.tar.bz2 php-5.4.40.tar.bz2 xcache-3.2.0.tar.bz2
编译安装apr:
# tar xf apr-1.5.0.tar.bz2# cd apr-1.5.0# ./configure --prefix=/usr/lcoal/apr# make && make install
编译安装apr-util
# tar xf apr-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
编译安装httpd-2.4.9
# tar -xf httpd-2.4.10.tar.bz2# cd httpd-2.4.10# ./configure --prefix=/usr/local/apache2 \--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-modules=most \--enable-mpms-shared=all \--enable-proxy \--enable-proxy-fcgi \--with-mpm=prefork[root@localhost httpd-2.4.10]# make && make install
编译安装php,启用fpm功能--enable-fpm
# tar -xf php-5.4.40.tar.bz2# cd php-5.4.40# ./configure --prefix=/usr/local/php \--with-config-file-path=/etc \--with-config-file-scan-dir=/etc/php.d \--with-libxml-dir=/usr \--with-mysql \--with-mysqli \--with-openssl \--with-mcrypt \--with-png-dir \--with-jpeg-dir \--with-freetype-dir \--with-zlib \--with-bz2 \--with-curl \--enable-zip \--enable-fpm \--with-fpm-user=apache \--with-fpm-group=apache \--enable-mbstring \--enable-xml \--enable-sockets \# make && make test && make install
待续。。。