CentOS 6 編譯LAMP 實現雙機FastCGI

來源:互聯網
上載者:User

標籤:wordpress   虛擬機器主機   二進位   mysql   模型   

需求:


    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其實是作為反向 Proxy來工作的,編譯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[[email protected] ~]# useradd -r mysql# 解壓二進位安裝包放置在`/usr/local/`目錄下[[email protected] ~]# tar -xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/[[email protected] ~]# cd /usr/local/# 連結為`mysql`目錄[[email protected] local]# ln -sv mariadb-5.5.46-linux-x86_64/ mysql`mysql‘ -> `mariadb-5.5.46-linux-x86_64/‘# 修改其屬主和屬組[[email protected] local]# chown -R root:mysql mysql/# 建立資料庫存放目錄`/data/mysql`[[email protected] local]# mkdir -pv /data/mysqlmkdir: created directory `/data‘mkdir: created directory `/data/mysql‘# 修改其屬主和屬組。[[email protected] local]# chown -R mysql:mysql /data/mysql/# 安裝[[email protected] local]# cd mysql/[[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/# 複製服務啟動指令碼至`/etc/rc.d/init.d`目錄[[email protected] 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


資料庫初始化:

# 啟動資料庫[[email protected] mysql]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS![[email protected] mysql]# ss -tunl | grep 3306tcp    LISTEN     0      50                     *:3306                  *:*# 匯出`/usr/local/mysql/bin/`目錄至`PATH`系統內容變數[[email protected] mysql]# export PATH=/usr/local/mysql/bin/:$PATH# 資料庫初始化設定[[email protected] mysql]# mysql_secure_installation


授權:

[[email protected] ~]# 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的用戶端。[[email protected] ~]# yum install -y mysql# 測試連接HostB資料庫[[email protected] ~]# 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[[email protected] 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


待續。。。





CentOS 6 編譯LAMP 實現雙機FastCGI

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.