您好,登錄后才能下訂單哦!
小編給大家分享一下一臺centos7主機如何部署LAMP并提供https服務,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
在一臺centos7上部署LAMP以及xcache并安裝分別在2個虛擬主機上部署wordpress和php-myadmin且為phpmyadmin提供https服務;
#用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服務是否可以啟動成功,以及php頁面是否能夠成功開啟:
檢查httpd服務是否能夠成功開啟以及80端口是否開啟后啟動:
systemctl start htppd.service 啟動服務
systemctl status httpd.service 檢查服務開啟狀態
ss -tnl 查看80端口
ps -aux 檢查進程
httpd -M | grep mpm :查看是否是prefork 模塊以及是否是開啟狀態(shared)
#確認httpd服務啟動成功
[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
#確認80端口開啟狀態
[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
#確認進程啟動
[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
#確認默認啟動模塊prefok是shared狀態
[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)
#確認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數據庫,并啟動起來;
systemctl start mariadb.service
#然后授權創建用戶
先進mysql 然后如下
mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.%.%' IDENTIFIED BY 'wppass';
mysql> FLUSH PRIVILEGES;
mysql> CREATE DATABASE wpdb;
#建2個目錄作為虛擬主機FQDN的資源映射路徑,
[root@1 ~]# mkdir -pv /data/vhost/www{1,2}
#配置默認測試頁面
[root@1 ~]# vim /data/vhost/www1/index.php
<h2>第一臺虛擬主機</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>第二臺虛擬主機</h2>
<?php
$conn = mysql_connect('172.16.100.34','wpuser','wppass');
if($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
#配置2個FQDN虛擬主機的配置文件
[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>
#臨時修改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頁面是否可以正常連接 以及數據庫連接是否正常
#用www2.wufeng.com訪問也沒問題 而且加速器也成功安裝了
#下面我們就剩下搞定wordpress 以及php-myadmin
#因為我是本地ftp服務器所以直接下載下來解壓縮了;
[root@1~]# unzip wordpress-4.3.1-zh_CN.zip
#并移動至第一個虛擬主機的資源映射路徑下
[root@1~]# mv wordpress /data/vhost/www1
#cd進入該目錄下并且修改配置文件
#修改配置文件名并修改之;
[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 設置 - 具體信息來自您正在使用的主機 ** //
/** WordPress數據庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數據庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數據庫密碼 */
define('DB_PASSWORD', 'wppass');
/** MySQL主機 */
define('DB_HOST', '172.16.100.34'); 這里的地址是指向數據庫地址
/** 創建數據表時默認的文字編碼 */
define('DB_CHARSET', 'utf8');
/** 數據庫整理類型。如不確定請勿更改 */
define('DB_COLLATE', '');
那么wordpress基本上已經配置好了 不急于測試 下面把php-myadmin也一起安裝了
#php-myadmin也是在ftp服務器上下載的所以直接解壓了
[root@1 ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
#并且放在第2臺主機上的第2個虛擬主機資源映射路徑下;
[root@1 myadmin]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost/www2/myadmin
#cd進該目錄下并且修改文件名修改配置
[root@1 www2]# cd myadmin/ 進入目標目錄
[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個單引號中間加上隨機碼 用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數據庫主機的地址
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
#下面就測試這2個程序是否可以連接
#需要安裝以及創建賬戶密碼然后登陸即可
#測試第2臺虛擬主機上的myadmin
#到這里測試全部成功,然后我們最后要為myadmin提供https服務
#簽署CA證書并為phpmyadmin提供https服務;
#在主機上安裝mod_ssl模塊 因為需要http來加載模塊并啟動443端口我們前面已經安裝了
[root@localhost CA]# yum install mod_ssl.x86_64
#找一臺主機做CA比如第一臺主機
#然后在第1臺主機上生成CA自簽名證書;
1、生成密鑰
#首先進入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
補充文件
[root@1 CA]# touch index.txt
[root@1 CA]# echo 01 > serial
、
#然后在去第2臺主機上生成請求簽署文件以及密鑰
在/etc/httpd/目錄下創建一個目錄
~]# 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)
生成簽署請求文件:
[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 這個要和客戶訪問要加密的主機名一樣
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 []:
復制給CA主機簽署證書
[root@ ssl]# scp httpd.csr 172.16.100.32:/tmp
然后到centos7主機上簽署文件
[root@1 CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt
連續2個yes 簡寫y
簽署完成后 復制給請求主機
[root@1 CA]# scp certs/httpd.crt 172.16.100.31:/etc/httpd/ssl/
在請求主機上也就是第2臺centos7上
編輯這個文件
[root@1 ~]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/data/vhost/www2/myadmin" 這2個啟用起來 把前面的#號去掉 改成自己的資源映射路徑
ServerName www2.wufeng.com:443 主機名也改成自己的
SSLCertificateFile /etc/httpd/ssl/httpd.crt 指明簽署的證書文件路徑
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 指明私鑰文件的路徑
然后reload一下
然后ss -tnl 查看一下443端口起來沒
在centos7 主CA機器上 測試基于https訪問相應的主機;
[root@localhost CA]# openssl s_client -connect 172.16.100.31:443 -CAfile /etc/pki/CA/cacert.pem
#然后打開瀏覽器輸入myadmin地址訪問看看是否提供了https服務
在主配置文件里把這個給禁了 免得沖突
#DocumentRoot "/var/www/html"
成功了 下面我們做個ab壓力測試
并且比較2個架構性能的差別
單臺主機部署LAMP
三臺主機分別部署LAMP
以上是“一臺centos7主機如何部署LAMP并提供https服務”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。