LAMP架構部署和動態網站環境的配置

安全劍客發表於2019-02-03

實驗環境:

作業系統:centos 7.5

伺服器IP:192.168.10.5

執行使用者:root

連線工具:xshell工具

web環境:Linux+apache+php+mariadb(LAMP架構)

 

大型動態應用系統平臺主要是針對於大流量、高併發網站建立的底層系統架構。大型網站的執行需要一個可靠、安全、可擴充套件、易維護的應用系統平臺做為支撐,以保證網站應用的平穩執行。這些東西都需要依靠web伺服器來支撐,裡面應用到的技術有單節點web伺服器系統、負載均衡系統、資料叢集系統、快取系統、分散式儲存系統、分散式伺服器管理系統、程式碼釋出系統等,現在企業一般都流行使用自動化系統部署,可以把web業務全部跑在docker容器中,簡化了運維配置流程,下面我們簡單的介紹下web伺服器單節點的部署及使用。

 

本文屬於原創,比較適合企業應用,具體詳細的介紹可以參考 裡邊教程的第20章,裡面詳細的介紹了LNMP架構,而我這裡是介紹LAMP架構,LAMP、LNMP在企業都應用比較廣泛,一般大型企業網站都會在Linux伺服器上面跑,節約資源、提高web伺服器效能及安全性。

 

單節點web伺服器

透過系統自帶的yum源安裝,也可以透過本地映象配置本地yum源,還可以透過rpm包或者tar.gz原始碼包編譯後再安裝;透過yum安裝是比較方便的,安裝過程會自動把依賴包自動安裝上去;透過rpm包安裝過程中需要根據提示尋找依賴包,這種安裝方式比較麻煩;下面我們來透過yum源安裝方式來演示給大家看。

 

apache是一款開源的web伺服器,它可以執行在幾乎所有廣泛使用的 計算機平臺 上,由於其 跨平臺 和安全性被廣泛使用,是最流行的Web伺服器端軟體之最,apache在企業應用也是比較廣泛的。特別是結合Linux作業系統發揮最優的效能。

 

1、install apache

# yum install httpd.x86_64 httpd-devel.x86_64 -y  //安裝apache

# rpm -qa httpd   //檢視apache是否安裝成功

# httpd -v    //檢視apache版本

Server version: Apache/2.4.6 (CentOS)

Server built:   Jun 27 2018 13:48:59

# systemctl start httpd.service    //啟動apache服務

# systemctl status httpd.service   //檢視apache服務狀態

# systemctl stop httpd.service    //停止apache服務

# systemctl enable httpd.service   //設定開機自動啟動apache服務

apache預設配置檔案路徑:/etc/httpd/

apache預設web路徑:/var/www/html ,預設裡面是空目錄

 

PHP 是一種建立動態互動性站點的強有力的伺服器端指令碼語言;PHP 是開源的,並且使用非常廣泛;同時,對於像微軟 asp、asp.net伺服器指令碼語言競爭者來說,PHP 無疑是另一種高效率的選項,PHP有點:開源性、處理快、易上手、跨平臺,效率高、適用於大型網站架構,一般PHP都是結合 apache nginx mysql;iis+php極少,配置複雜、效能差。下面就簡單介紹下php的安裝及配置。

 

2、install php

# yum install php php-common php-fpm php-gd php-soap php-json php-ldap php-mbstring php-mysqlnd php-mysqld php-xml php-xmlrpc php-opcache php-simplexml php-bcmath -y

# rpm -qa php*  //檢視安裝的PHP模組

# php -v   //檢視php版本

# ll /etc/php.ini    //php預設配置檔案,配置檔案裡面詳細引數這裡就不一一介紹了。

MySQL最初也是開源的,後來被Oracle公司收購後5.5後的版本開始收費了,後來又有了MariaDB資料庫,MariaDB資料庫管理系統是MySQL的一個分支,主要由開源社群在維護,採用GPL授權許可 MariaDB的目的是完全相容MySQL,包括API和命令列,使之能輕鬆成為MySQL的代替品,MariaDB開源、跨平臺、效能強、易擴充套件、應用廣。

 

3、install mariadb

# yum install mariadb.x86_64 mariadb-server.x86_64 mariadb-devel.x86_64 -y

# rpm -qa mariadb  //檢視mariadb是否安裝成功

# systemctl start mariadb.service   //啟動資料庫服務

# systemctl stop mariadb.service   //停止資料庫服務

# systemctl status mariadb.service   //檢視資料庫服務狀態

# systemctl enable mariadb.service  //設定開機自動啟動資料庫服務

mariadb安裝後啟動服務,資料庫root使用者是沒有密碼的,需要進行初始化並設定密碼,配置如下:

 

# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):   //直接回車

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] y   //y設定root使用者密碼

New password:      //輸入密碼

Re-enter new password:    //確定密碼

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] y    //y刪除匿名使用者

 ... Success!

 

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] y   //y禁止root遠端登入

 ... Success!

 

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] n  //n不刪除test資料庫,根據自己需求定。

 ... skipping.

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] y   //重新整理資料表

 ... Success!

 

Cleaning up...

 

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

 

# mysql -h 127.0.0.1 -u root -p   //連線資料庫

 

4、test web service,apache + php +mariadb安裝啟動服務後就開始測試。

4.1、透過瀏覽器訪問web伺服器出現如下解密說明apache安裝成功。

http://192.168.10.5

 

4.2、測試apache+php

# vim /var/www/html/index.php

<?php

        phpinfo();

?>

 

http://192.168.10.5/index.php

 

4.3、測試apache+php+mariadb

# vim /var/www/html/mysqld.php

 

<?php

$servername = " localhost " ;

$username = " root " ;

$password = " password " ;

// 建立連線

$conn = new mysqli ( $servername , $username , $password ) ;

// 檢測連線

if ( $conn -> connect_error ) {

die ( " 連線失敗: " . $conn -> connect_error ) ;

}

echo " 連線成功 " ;

?>

 

http://192.168.10.5/mysqld.php

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31559985/viewspace-2565440/,如需轉載,請註明出處,否則將追究法律責任。

相關文章