LAMP安裝日常中十分常見。在CentOS 6中默認的php5.3.0以下的版本不支持fpm fastCGI機制;需要自行打補丁或編譯安裝;默認安裝的httpd 2.2沒有對fasCGI的支持模塊,所以在CentOS 6 中只能編譯安裝httpd2.4和php5.3.3+;在CentOS 7中默認安裝的httpd 2.4新特性中加入了fastCGI的支持模塊,php可以獨立安裝安裝php-fpm包即可。今天就弄下三種模式下的LAMP搭建:
(1)CentOS 7, lamp (module);
要求: (1) 三者分離於兩臺主機;httpd(php(module)) +mariadb-server
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
(4) 爲phpMyAdmin提供https虛擬主機;
(2)CentOS 7, lamp (php-fpm);
要求:(1) 三者分離於三臺主機;phpfpm httpd mariadb
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
(3)CentOS 6, lamp (編譯安裝,模塊或php-fpm);
要求:(1) 三者分離於兩臺或三臺主機;
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
(4) 嘗試mpm爲非prefork機制;
說明:由於總是需要域名解析,所以將172.18.20.12作爲DNS解析服務器;
lamp整合一
一、實驗內容
實驗要求: (1)三者分離於兩臺主機;httpd(php(module)) +mariadb-server
(2) 一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
(3) xcache
(4) 爲phpMyAdmin提供https虛擬主機;
試驗環境:172.18.20.10:httpd主機(包含php 模塊支持php) ;
172.18.20.11:mariadb-server
說明:1.這裏由於實在CentOS 7 上完成,httpd模塊支持php,沒什麼費事的,直接安裝軟件,另一臺安裝mariadb-server就可以了。
2.環境中需要私建CA,CA環境搭建於172.18.20.12 主機上。
二、httpd主機設置
httpd主機上:yum -y install httpd
mkdir /webs/{admin,wordpress}
echo "index page @www.admin10.net" >/webs/admin/index.html
echo "index page @www.wordpress10.com" >/webs/wordpress/index.html
vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName
DocumentRoot "/webs/admin"
<Directory "/webs/admin">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName
DocumentRoot "/webs/wordpress"
<Directory "/webs/wordpress">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
systemctl start httpd
分別訪問http://www.admin10.net和http://www.wordpress10.com 服務器可以了。
三、安裝php環境
yum -y install php php-mbstring php-mysql
# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib64/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session
可以看到安裝php已經把模塊放到了httpd的目錄中,這個模塊是支持prefork併發處理模式的:
做兩個域名路徑中的index.php試試!
cat "www.admin10.net
<?php
phpinfo();
?>" > /webs/admin/index.php
cat "www.wrodpress10.net
<?php
phpinfo();
?>" > /webs/wordpress/index.php
OK了!
下載phpmyadmin、wordpress安裝包;
四、安裝phpmyadmin和wordpress
1.在數據庫172.18.29.11上安裝對應數據庫:
yum -y install mariadb-server
systemctl start mariadb
mysql -uroot
2.建立對應數據庫和管理員:
create database pmdb;
grant all on pmdb.* to 'pmad'@'172.18.%.%' identified by '123456';
create database wpdb;
grant all on wpad.* to 'pmad'@'172.18.%.%' identified by '123456';
flush privileges;
3.解壓phpmyadmin到/webs/admin/pms並修改配置文件。
vim pms/libraries/config.default.php ,將其中的四個內容替換掉
查找$cfg['PmaAbsoluteUri'],將其值設置爲http://172.18.20.10/pms
查找$cfg['Servers'][$i]['host'],將其值設置爲172.18.20.11
查找$cfg['Servers'][$i]['user'],將其值設置爲pmad
查找$cfg['Servers'][$i]['password'],將其值設置爲123456
訪問成功!
解壓wordpress到/webs/admin/wp
拷貝wp-config-sample.php爲wp-config.php,修改其中的數據庫配置項。
訪問成功!
到這裏phpmyadmin和wordpress已經搞定了。
五、編譯安裝xcache:
xcache是php一款加速器,利用進程共享內存空間,並設置緩存空間,默認大小爲60M大小。
提前看看,當前的訪問情況,ab測試下:
看來動態資源和靜態資源大約慢了6倍左右。
下載對應的源碼包,yum -y install php-devel
tar xf xcache-3.2.0.tar.bz2 -C /root
cd /root/xcache
./phpize
./configure --enable-xcache --with-php-config=/etc/httpd/conf.d/php.conf
安裝成功!
六、爲phpmyadmin提供https虛擬主機
建立CA主機:
客戶端生成密鑰和證書請求:
# cd /etc/pki/CA/
# (umask 077;openssl genrsa -out private/cakey.pem 2048 )
Generating RSA private key, 2048 bit long modulus
................................................................................... ..........+++
...........................+++
e is 65537 (0x10001)
# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:admin10.net
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:ca.admin10.net
Email Address []:
將 admin10.csr發送到CA服務器端簽署證書:
scp admin10.csr 172.18.20.12:/opt
CA服務器端簽署證書:
# openssl ca -in /opt/admin10.csr -out certs/admin10.cert -days 365
敲兩個Y,簽署好了,簽好的證書發給httpd服務器端:
# scpo certs/admin10.cert 172.18.20.10:/etc/httpd/ssl
httpd服務器端修改/etc/httpd/conf.d/ssl.conf 文件主要下面的定義:
<VirtualHost www.admin10.net:443>
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/webs/admin"
ServerName www.admin10.net
<Directory "/webs/admin">
Options None
AllowOverride None
Require all granted
</Directory>
SSLCertificateFile /etc/httpd/ssl/admin10.cert
SSLCertificateKeyFile /etc/httpd/ssl/admin10.private
這樣 https://www.admin10.net/pms/就可以用https協議訪問了。
如果其中有問題,請不吝賜教!
51cto博客寫代碼嵌入代碼語言十分麻煩,可以參考該文自己搭建個LAMP,脫離此地。
下一篇《lamp整合三連發(2)》演示下一個LAMP環境搭建。