第十八章 APACHE及LAMP-CENTOS7.5知識

一、Apache簡介
• 主要特點
– 開放源代碼、跨平臺應用
– 支持多種網頁編程語言
– 模塊化設計 、運行穩定、良好的安全性
• 軟件版本
– 1.X
• 目前最高版本是1.3,運行穩定
• 向下兼容性較好,但缺乏一些較新的功能
– 2.X
• 目前最高版本是2.4
• 具有更多的功能特性
• 與1.X相比,配置管理風格存在較大差異
部署安裝apache
注:一定關閉SELINUX及iptables防火牆

lamp架構:linux,apache,mysql,php

Apache:3000人,更大的併發量:使用負載均衡功能LB,如:LVS,HAPROXY,NGINX。

http://www.apache.org

發佈靜態網站的。
應用量高,跨平臺應用,不收費,支持多種編程語言,模塊化設計運行穩定

相對比的是nginx:10000人,兼容性和穩定性差一些。
可通過rpm或yum
rpm -ivh httpd-2.4.6-80.el7.centos.1.x86_64
yum install httpd –y

systemctl start httpd
systemctl enable httpd

APACHE配置文件選項

服務目錄 /etc/httpd
主配置文件 /etc/httpd/conf/httpd.conf
網站數據目錄 /var/www/html
訪問日誌 /var/log/httpd/access_log
錯誤日誌 /var/log/httpd/error_log

默認主頁文件存放目錄(默認站點路徑)爲
/var/www/html/
vi index.html

日誌文件存放路徑爲
/var/log/httpd/

主配置文件爲
/etc/httpd/conf/httpd.conf
基本內容:

ServerRoot “/etc/httpd” 服務主目錄
Listen 80 監聽端口
User apache 啓動用戶
Group apache 啓動組
ServerAdmin root@localhost 管理員郵箱
ServerName www.wang.com 域名主機名
DocumentRoot “/var/www/html“ 默認主頁存放目錄
DirectoryIndex index.html 引所文件(設置主頁)
ErrorLog logs/error_log 錯誤日誌
CustomLog logs/access_log combined 訪問日誌

– CustomLog:訪問日誌文件的位置
– PidFile:保存httpd進程PID號的文件
– AddDefaultCharset:設置站點中的網頁默認使用的字符集編碼
– Timeout:網絡連接超時,默認爲300秒
– KeepAlive:是否保持連接,可選On或Off
– MaxKeepAliveRequests:每次連接最多請求文件數
– KeepAliveTimeout:保持連接狀態時的超時時間
– Include:需要包含進來的其他配置文件
httpd服務的訪問控制
– 作用
– 控制對網站資源的訪問
– 爲特定的網站目錄添加訪問授權
– 常用訪問控制方式
– 客戶機地址限制
– 用戶授權限制
使用Require配置項實現訪問控制,按先後順序限制
可用於<Location>、<Directory>、<Files>、<Limit>配置段中
Require配置項的常見語法

Require all granted
Require all denied
Require local
Require [not] host <主機名或域名列表>
Require [not] ip <ip地址或網段列表>
使用not禁止訪問時要將其置於<RequireAll> </RequireAll>容器中並在容器中指定相應的限制策略

虛擬web主機的概念
在同一臺服務器上建立多個web站點,每一個站點不獨立佔用一臺真正的服務器

虛擬主機的分類
1.基於域名的虛擬主機 生產環境常用
2.基於IP的虛擬主機 基本不用
3.基於端口的虛擬主機 一般測試環境,Listen:8080

NameVirtualHost 172.18.199.63:80
<VirtualHost 172.18.199.63:80>
ServerAdmin [email protected]
DocumentRoot /var/www/aa
ServerName www.aa.com
ErrorLog logs/aa-error_log
CustomLog logs/aa-access_log common
</VirtualHost>
<VirtualHost 172.18.199.63:80>
ServerAdmin [email protected]
DocumentRoot /var/www/bb
ServerName www.bb.com
ErrorLog logs/bb-error_log
CustomLog logs/bb-access_log common
</VirtualHost>

Listen 8081
Listen 8082
<VirtualHost 172.18.199.63:8081>
ServerAdmin [email protected]
DocumentRoot /var/www/cc
ServerName www.wang.com
ErrorLog logs/cc-error_log
CustomLog logs/cc-access_log common
</VirtualHost>
<VirtualHost 172.18.199.63:8082>
ServerAdmin [email protected]
DocumentRoot /var/www/dd
ServerName www.wang.com
ErrorLog logs/dd-error_log
CustomLog logs/dd-access_log common
</VirtualHost>

<VirtualHost 172.18.199.163:80>
ServerAdmin [email protected]
DocumentRoot /var/www/ee
ServerName www.wang.com
ErrorLog logs/ee-error_log
CustomLog logs/ee-access_log common
</VirtualHost>
<VirtualHost 172.18.199.164:80>
ServerAdmin [email protected]
DocumentRoot /var/www/ff
ServerName www.wang.com
ErrorLog logs/ff-error_log
CustomLog logs/ff-access_log common
</VirtualHost>

二、LAMP及DISCUZ論壇
1、lamp介紹
LAMP:linux apache mariadb php

Yum remove httpd
Yum install httpd php php-mysql mariadb-server mariadb php-mbstring -y

開啓apache、mysql服務
systemctl start httpd , systemctl start mariadb
開機啓動httpd和mariadb服務
systemctl enable httpd , systemctl enable mariadb

輸入命令mysql
mysql>show databases;
mysql> grant all privileges on . to bbsadmin@'localhost' identified by '123456';
im /etc/php.ini
211行 short_open_tag = On 支持php語言的短標記功能
上傳discuz包
修改權限
論壇安裝
觀察一下數據庫
mysql> use ultrax;
mysql> show tables;
mysql> select from pre_common_usergroup ;
mysql> select
from pre_ucenter_members;用戶名密碼錶

下載並運行phpmyadmin
下載,解壓,移動,重命名
FTP下載
cd soft
tar zxvf phpMyAdmin-4.0.10.10-all-languages.tar.gz
mv phpMyAdmin-4.0.10.10-all-languages /var/www/aa/phpmyadmin
cd /var/www/aa/phpmyadmin/

http://www.wang.com/phpmyadmin/

輸入數據庫的用戶名和密碼
管理數據庫

作業:
1、LAMP下建立論壇。

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