漫漫運維路——基於rpm包安裝實現LAMP

LAMP早期即爲Linux+Apache+MySQL+PHP,以基於Linux平臺的三個軟件搭建出動態網頁站點,而現在的LAMP不僅僅代表以上幾個軟件,因爲現在的開源軟件種類較多,網站的構建人員的選擇也較多,所以現在的M可以爲MySQL,也可以爲maria DB或者是其他的數據庫管理系統。而P則也不僅可代表PHP,在實際應用中還可能是Python、Perl、JSP等語言。

本文將基於rpm包安裝的形式實現Linux+Apache+MySQL+PHP的LAMP平臺,並且實現以下功能:

1.創建兩個虛擬主機,分別用於wordpress和phpmyadmin,要求能使用wordpress創建自己的博客,能使用phpmyadmin管理本機上的數據庫。

2.使用HTTPD+SSL配置worpress的那臺虛擬主機成HTTPS服務器,實現加密通信。

準備實驗環境介紹:

物理機是基於Windows 7的系統,在物理機上安裝Vmware 9,然後再在虛擬機上安裝CentOS 6.6系統,並配置好YUM源等。準備好後檢查YUM倉庫是否可用,如下圖所示:


wKioL1VEs9Wxj4oBAAJQtbJ86y0640.jpg


實驗過程:

一.安裝配置虛擬主機

1.安裝httpd,

在確定未安裝httpd的情況下使用如下命令安裝即可:

[root@LAMP /]# yum install httpd -y

2.配置虛擬主機

切換目錄在/etc/httpd/conf.d/新建虛擬主機配置文件virtualhost.conf,如下所示


wKiom1VEsrDAwUPCAADnM_j2PI4695.jpg


註釋掉/etc/httpd/conf/httpd.conf配置文件中的Section 2 部分內的DocumentRoot


wKioL1VEtE-A2DAqAAKlYXrxYMA937.jpg


1.爲虛擬主機新建目錄並提供測試頁面

新建虛擬主機目錄

[root@LAMP conf.d]# mkdir -pv /data/{wordpress,Myadmin}

mkdir: created directory `/data'

mkdir: created directory `/data/wordpress'

mkdir: created directory `/data/Myadmin'

[root@LAMP conf.d]# 

提供臨時測試頁面index.html

[[email protected]]#echo"HIwordpress">/data/wordpress/index.html

[root@LAMP conf.d]# echo "HI Myadmin">/data/Myadmin/index.html

[root@LAMP conf.d]# 

2.重啓測試

重啓服務並關閉iptables和SElinux

[root@LAMP conf.d]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

[root@LAMP conf.d]# service iptables stop

[root@LAMP conf.d]# setenforce 0

      [root@LAMP conf.d]# 


wKiom1VEs4HD65MtAAGaMwlexPo766.jpg


二、安裝phpph-mysqlmysql-server,配置phpMyadminwordpress

1.直接使用yum安裝好以上軟件,

[root@LAMP wordpress]# yum install php php-mysql mysql-server -y

2.下載phpMyadmin和wordpress並解壓到/data/Myadmin和/data/wordpress目錄下,刪除以前存在的Myadmin和wordpress目錄並直接將phpMyadmin和wordpress解壓後更名爲Myadmin和wordpress

[root@LAMP data]# ls

Myadmin  wordpress

3.重啓服務,並測試

能看到如下信息,則表示配置沒問題

[root@LAMP data]# elinks -dump www.myadmin.com

ELinks: Host not found

[root@LAMP data]# vim /etc/hosts

[root@LAMP data]# elinks -dump www.myadmin.com

   [1]phpMyAdmin

 

               Welcome to phpMyAdmin

 

   Language [[2]________________________________] [3][ Go ]

   Log in[4]phpMyAdmin documentation

   Username: [5]_________________________

   Password: [6]_________________________

   [7][ Go ]

   Cannot load [8]mcrypt extension. Please check your PHP configuration.

   Cookies must be enabled past this point.

 

References

 

   Visible links

   1. http://www.phpmyadmin.net/

   4. http://www.myadmin.com/Documentation.html?phpMyAdmin=vvpak8172gftl0hi3fqkkpiu036he9vh

   8. http://php.net/mcrypt

[root@LAMP data]# elinks -dump www.wordpress.com

   看起來似乎沒有 wp-config.php 文件。開始之前,我們需要這個文件。需要幫助?

   您可查看[1]這篇幫助文檔。您可以通過本網頁界面來編輯 wp-config.php 文件,但

   並非所有主機都支持這種方法。最安全的做法仍是手動創建。

 

   [2]試試創建一個配置文件

 

References

 

   Visible links

   1. http://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php

   2. http://www.wordpress.com/wp-admin/setup-config.php

4.啓動並配置mysql,創建wordpress數據庫,爲用戶wuxiaotao授權。

創建wordpress數據庫

mysql> CREATE DATABASE wordpress;

Query OK, 1 row affected (0.00 sec)

 

mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

| wordpress          |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> 

爲用戶wuxiaotao授權

mysql> GRANT ALL ON wordpress.* TO 'wuxiaotao'@'127.0.0.1' IDENTIFIED BY 'hello mage';#因爲mysql和http是安裝在同一主機上,配置其可在本地登錄即可

Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL ON wordpress.* TO 'wuxiaotao'@'localhost' IDENTIFIED BY 'hello mage';#配置其反解

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;#通知mysql重讀授權信息

Query OK, 0 rows affected (0.00 sec)

5.配置wordpress,測試

切換目錄至/data/wordpress目錄,並複製wp-config-sample.php 爲wp-config.php

[root@LAMP data]# cd wordpress/

[root@LAMP wordpress]# ls

index.php        wp-admin            wp-comments-post.php  wp-cron.php        wp-load.php   wp-rdf.php       wp-settings.php

license.txt      wp-app.php          wp-commentsrss2.php   wp-feed.php        wp-login.php  wp-register.php  wp-signup.php

readme.html      wp-atom.php         wp-config-sample.php  wp-includes        wp-mail.php   wp-rss2.php      wp-trackback.php

wp-activate.php  wp-blog-header.php  wp-content            wp-links-opml.php  wp-pass.php   wp-rss.php       xmlrpc.php

[root@LAMP wordpress]# cp wp-config-sample.php wp-config.php

修改wp-config.php文件,更改內容如下


wKioL1VEtUqigi5cAAIsKkVYHW4900.jpg


重啓服務並測試

    www.myadmin.com


    

wKioL1VEtaiB_jWHAAG0Hov7mxc241.jpg


登錄mysql


wKioL1VEteyzVQp_AATVwLiDP40926.jpg


        www.mywordpress.com


wKiom1VEtNrjpdagAAMg4iZbnT4257.jpg


如上顯示,成功!

三、配置wordpress稱爲HTTPS

  1.另起一臺虛擬機,設置其IP爲172.16.35.3,改主機用作CA

     生成CA私鑰

[root@CA CA]# (umask 077;openssl genrsa -out private/pam.key 1024)

Generating RSA private key, 1024 bit long modulus

..........++++++

............++++++

e is 65537 (0x10001)

   生成簽證書

[root@CA CA]# openssl req -new -x509 -key private/pam.key -out server.pem -days 36000

根據提示鍵入相關信息

   修改openssl配置文件(/etc/pki/tls/openssl.cf),併爲CA提供配置文件


wKioL1VEtxmhRMU1AAOB37SRUgc032.jpg


[root@CA CA]# echo "01">serial

 

2.客戶端生成證書

客戶端生成私鑰

[root@LAMP ssl]# (umask 077;openssl genrsa -out httpd.key 1024)

Generating RSA private key, 1024 bit long modulus

.........++++++

...++++++

e is 65537 (0x10001)

客戶端生成證書

[root@LAMP ssl]# openssl req -new -key httpd.key -out httpd.csr

根據提示鍵入相關信息

3.複製客戶端證書到CA服務器端,並簽署

複製客戶端證書到CA服務器

[root@LAMP ssl]# scp /etc/httpd/ssl/httpd.csr [email protected]:/etc/pki/CA/

根據提示輸入密碼等驗證信息

CA服務器端簽署請求

[root@CA CA]# openssl ca -in httpd.csr -out httpd.crt -days 3650

把簽署號的證書發回http服務器

[root@CA CA]#scp/etc/pki/CA/[email protected]:/etc/httpd/ssl/httpd.csr 

4.在主機LAMP上安裝mod_ssl模塊並配置。

安裝mod_ssl

[root@LAMP ssl]# yum install mod_ssl

配置/etc/httpd/conf.d/ssl.conf


wKiom1VEtg7yhov1AAHgLfLr1Dg525.jpg


把之前在virtualhost.conf文件中的關於wordpress的虛擬主機刪除。

2.爲網卡子接口配置第地址,並測試:

配置網卡子接口

[root@LAMP ~]# ifconfig eth0:1 172.16.35.4/16

在windows主機中修改C:\Windows\System32\drivers\etc\hosts文件爲其添加如下條目


wKioL1VEt9mTDklZAABsUAB4S4w854.jpg


重啓服務並測試

[root@LAMP ~]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

[Thu Apr 30 23:55:41 2015] [warn] NameVirtualHost *:80 has no VirtualHosts

[  OK  ]

測試www.mywordpress.com


wKiom1VEtsKQyWwwAAZnDHtea-0842.jpg


測試www.myadmin.com


wKioL1VEuHrSPJZ5AAI1WDFct7U229.jpg



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章