您好,登錄后才能下訂單哦!
小編給大家分享一下一臺(tái)centos7主機(jī)如何部署LAMP并提供https服務(wù),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
在一臺(tái)centos7上部署LAMP以及xcache并安裝分別在2個(gè)虛擬主機(jī)上部署wordpress和php-myadmin且為phpmyadmin提供https服務(wù);
#用rpm包快速部署 :LAMP
1、yum安裝:
yum install -y httpd php php-mysql php-gd php-mbstring php-xml mariadb-server mod_ssl
Installed:
httpd.x86_64 0:2.4.6-40.el7.centos mariadb-server.x86_64 1:5.5.44-2.el7.centos php.x86_64 0:5.4.16-36.el7_1 php-gd.x86_64 0:5.4.16-36.el7_1 php-mbstring.x86_64 0:5.4.16-36.el7_1
php-mysql.x86_64 0:5.4.16-36.el7_1 php-xml.x86_64 0:5.4.16-36.el7_1
2、 檢查httpd服務(wù)是否可以啟動(dòng)成功,以及php頁面是否能夠成功開啟:
檢查httpd服務(wù)是否能夠成功開啟以及80端口是否開啟后啟動(dòng):
systemctl start htppd.service 啟動(dòng)服務(wù)
systemctl status httpd.service 檢查服務(wù)開啟狀態(tài)
ss -tnl 查看80端口
ps -aux 檢查進(jìn)程
httpd -M | grep mpm :查看是否是prefork 模塊以及是否是開啟狀態(tài)(shared)
#確認(rèn)httpd服務(wù)啟動(dòng)成功
[root@1 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2016-07-16 15:32:43 CST; 4min 18s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 6535 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─6535 /usr/sbin/httpd -DFOREGROUND
├─6537 /usr/sbin/httpd -DFOREGROUND
├─6538 /usr/sbin/httpd -DFOREGROUND
├─6539 /usr/sbin/httpd -DFOREGROUND
├─6540 /usr/sbin/httpd -DFOREGROUND
└─6541 /usr/sbin/httpd -DFOREGROUND
#確認(rèn)80端口開啟狀態(tài)
[root@1~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25
#確認(rèn)進(jìn)程啟動(dòng)
[root@1 ~]# ps -aux
root 6535 0.0 0.8 450548 15064 ? Ss 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 6537 0.0 0.4 452632 7888 ? S 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 6538 0.0 0.4 452632 7888 ? S 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 6539 0.0 0.4 452632 7888 ? S 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 6540 0.0 0.4 452632 7888 ? S 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
apache 6541 0.0 0.4 452632 7888 ? S 15:32 0:00 /usr/sbin/httpd -DFOREGROUND
#確認(rèn)默認(rèn)啟動(dòng)模塊prefok是shared狀態(tài)
[root@1 ~]# httpd -M | grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.0.1. Set the 'ServerName' directive globally to suppress this message
mpm_prefork_module (shared)
#確認(rèn)ssl模塊是否啟用成功
[root@1 ~]# httpd -M |grep ssl
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.0.1. Set the 'ServerName' directive globally to suppress this message
ssl_module (shared)
#配置mysql數(shù)據(jù)庫,并啟動(dòng)起來;
systemctl start mariadb.service
#然后授權(quán)創(chuàng)建用戶
先進(jìn)mysql 然后如下
mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.%.%' IDENTIFIED BY 'wppass';
mysql> FLUSH PRIVILEGES;
mysql> CREATE DATABASE wpdb;
#建2個(gè)目錄作為虛擬主機(jī)FQDN的資源映射路徑,
[root@1 ~]# mkdir -pv /data/vhost/www{1,2}
#配置默認(rèn)測試頁面
[root@1 ~]# vim /data/vhost/www1/index.php
<h2>第一臺(tái)虛擬主機(jī)</h2>
<?php
$conn = mysql_connect('172.16.100.34','wpuser','wppass');
if($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
[root@1 ~]# vim /data/vhost/www2/index.php
<h2>第二臺(tái)虛擬主機(jī)</h2>
<?php
$conn = mysql_connect('172.16.100.34','wpuser','wppass');
if($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
#配置2個(gè)FQDN虛擬主機(jī)的配置文件
[root@1 ~]# vim /etc/httpd/conf.d/vhost1.conf
<VirtualHost 172.16.100.34:80>
ServerName www1.wufeng.com
DocumentRoot "/data/vhost/www1"
ProxyRequests on
DirectoryIndex index.php
<Directory "/data/vhost/www1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
[root@1 ~]# vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 172.16.100.34:80>
ServerName www2.wufeng.com
DocumentRoot "/data/vhost/www2"
ProxyRequests on
DirectoryIndex index.php
<Directory "/data/vhost/www2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
#臨時(shí)修改DNS指向自己
[root@1 ~]# vim /etc/resolv.conf
# Generated by NetworkManager
DNS=172.16.100.34
#本地域名解析增加條目
[root@1 ~]# vim /etc/hosts
172.16.100.31 www1.wufeng.com www2.wufeng.com
#測試php頁面是否可以正常連接 以及數(shù)據(jù)庫連接是否正常
#用www2.wufeng.com訪問也沒問題 而且加速器也成功安裝了
#下面我們就剩下搞定wordpress 以及php-myadmin
#因?yàn)槲沂潜镜豧tp服務(wù)器所以直接下載下來解壓縮了;
[root@1~]# unzip wordpress-4.3.1-zh_CN.zip
#并移動(dòng)至第一個(gè)虛擬主機(jī)的資源映射路徑下
[root@1~]# mv wordpress /data/vhost/www1
#cd進(jìn)入該目錄下并且修改配置文件
#修改配置文件名并修改之;
[root@localhost ~]# cd /data/vhost/www1/wordpress/
[root@localhost wordpress]# ln -s wp-config-sample.php wp-config.php
[root@localhost wordpress]# vim wp-config.php
// ** MySQL 設(shè)置 - 具體信息來自您正在使用的主機(jī) ** //
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', 'wppass');
/** MySQL主機(jī) */
define('DB_HOST', '172.16.100.34'); 這里的地址是指向數(shù)據(jù)庫地址
/** 創(chuàng)建數(shù)據(jù)表時(shí)默認(rèn)的文字編碼 */
define('DB_CHARSET', 'utf8');
/** 數(shù)據(jù)庫整理類型。如不確定請(qǐng)勿更改 */
define('DB_COLLATE', '');
那么wordpress基本上已經(jīng)配置好了 不急于測試 下面把php-myadmin也一起安裝了
#php-myadmin也是在ftp服務(wù)器上下載的所以直接解壓了
[root@1 ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
#并且放在第2臺(tái)主機(jī)上的第2個(gè)虛擬主機(jī)資源映射路徑下;
[root@1 myadmin]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost/www2/myadmin
#cd進(jìn)該目錄下并且修改文件名修改配置
[root@1 www2]# cd myadmin/ 進(jìn)入目標(biāo)目錄
[root@1 myadmin]# mv config.sample.inc.php config.inc.php 修改配置文件名
[root@1 myadmin]# vim config.inc.php 修改配置文件
$cfg['blowfish_secret'] = '4pfPnJU4R8pA4WMWaQxD'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
上面這2個(gè)單引號(hào)中間加上隨機(jī)碼 用openssl rand -base64 15 生成 用于傳輸加密
/*
* Servers configuration
*/
$i = 0;
/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '172.16.100.34'; 這里這指向mysql數(shù)據(jù)庫主機(jī)的地址
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
#下面就測試這2個(gè)程序是否可以連接
#需要安裝以及創(chuàng)建賬戶密碼然后登陸即可
#測試第2臺(tái)虛擬主機(jī)上的myadmin
#到這里測試全部成功,然后我們最后要為myadmin提供https服務(wù)
#簽署CA證書并為phpmyadmin提供https服務(wù);
#在主機(jī)上安裝mod_ssl模塊 因?yàn)樾枰猦ttp來加載模塊并啟動(dòng)443端口我們前面已經(jīng)安裝了
[root@localhost CA]# yum install mod_ssl.x86_64
#找一臺(tái)主機(jī)做CA比如第一臺(tái)主機(jī)
#然后在第1臺(tái)主機(jī)上生成CA自簽名證書;
1、生成密鑰
#首先進(jìn)入CA目錄下
[root@1 wordpress]# cd /etc/pki/CA/
#在CA目錄下生成密鑰
[root@1 CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
............................................................................+++
...............+++
e is 65537 (0x10001)
2、生成自簽證書
[root@1 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
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]:wufeng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:ca.wufeng.com
Email Address []:admin@wufeng.com
補(bǔ)充文件
[root@1 CA]# touch index.txt
[root@1 CA]# echo 01 > serial
、
#然后在去第2臺(tái)主機(jī)上生成請(qǐng)求簽署文件以及密鑰
在/etc/httpd/目錄下創(chuàng)建一個(gè)目錄
~]# mkdir ssl
~]# cd ssl
生成密鑰
[root@ ssl]# (umask 077; openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.++++++
........................................++++++
e is 65537 (0x10001)
生成簽署請(qǐng)求文件:
[root@ ssl]# openssl req -new -key httpd.key -out httpd.csr
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]:wufeng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www2.wufeng.com 這個(gè)要和客戶訪問要加密的主機(jī)名一樣
Email Address []:www1admin@wufeng.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
復(fù)制給CA主機(jī)簽署證書
[root@ ssl]# scp httpd.csr 172.16.100.32:/tmp
然后到centos7主機(jī)上簽署文件
[root@1 CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt
連續(xù)2個(gè)yes 簡寫y
簽署完成后 復(fù)制給請(qǐng)求主機(jī)
[root@1 CA]# scp certs/httpd.crt 172.16.100.31:/etc/httpd/ssl/
在請(qǐng)求主機(jī)上也就是第2臺(tái)centos7上
編輯這個(gè)文件
[root@1 ~]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/data/vhost/www2/myadmin" 這2個(gè)啟用起來 把前面的#號(hào)去掉 改成自己的資源映射路徑
ServerName www2.wufeng.com:443 主機(jī)名也改成自己的
SSLCertificateFile /etc/httpd/ssl/httpd.crt 指明簽署的證書文件路徑
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 指明私鑰文件的路徑
然后reload一下
然后ss -tnl 查看一下443端口起來沒
在centos7 主CA機(jī)器上 測試基于https訪問相應(yīng)的主機(jī);
[root@localhost CA]# openssl s_client -connect 172.16.100.31:443 -CAfile /etc/pki/CA/cacert.pem
#然后打開瀏覽器輸入myadmin地址訪問看看是否提供了https服務(wù)
在主配置文件里把這個(gè)給禁了 免得沖突
#DocumentRoot "/var/www/html"
成功了 下面我們做個(gè)ab壓力測試
并且比較2個(gè)架構(gòu)性能的差別
單臺(tái)主機(jī)部署LAMP
三臺(tái)主機(jī)分別部署LAMP
以上是“一臺(tái)centos7主機(jī)如何部署LAMP并提供https服務(wù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。