CentOS項目實例之四--Apache配置

 

1. ZZSRV1上的WWW配置

1.1. 磁盤配置

1.1.1. 添加磁盤

添加80GB的磁盤。

# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00012974
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-root: 18.8 GB, 18798870528 bytes, 36716544 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

沒有找到新的磁盤,可以用一下命令刷新

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan
# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00012974
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-root: 18.8 GB, 18798870528 bytes, 36716544 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
可以看到/dev/sdb


1.1.2. LVM配置 

# fdisk  /dev/sdb
創建一個分區
# fdisk -l /dev/sdb
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x558160b8
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   167772159    83885056   8e  Linux LVM
創建PV
# pvscan
  PV /dev/sda2   VG centos   lvm2 [19.51 GiB / 0    free]
  Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0   ]
# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
# pvscan
PV /dev/sda2   VG centos          lvm2 [19.51 GiB / 0    free]
PV /dev/sdb1                      lvm2 [80.00 GiB]
Total: 2 [99.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [80.00 GiB]
創建VG
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "centos" using metadata type lvm2
# vgcreate DATAVG /dev/sdb1
  Volume group "DATAVG" successfully created
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "DATAVG" using metadata type lvm2
  Found volume group "centos" using metadata type lvm2
# vgdisplay DATAVG
  --- Volume group ---
  VG Name               DATAVG
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               80.00 GiB
  PE Size               4.00 MiB
  Total PE              20479  記下此數字
  Alloc PE / Size       0 / 0
  Free  PE / Size       20479 / 80.00 GiB
  VG UUID               Ff09cK-hwD0-hQMJ-hZX0-O9ju-ZaxL-0M6jCp
創建一個LV,使用VG的全部PE
# lvscan
  ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/centos/root' [17.51 GiB] inherit
LV的名稱爲LV1,使用全部空間
# lvcreate -n LV1 -l 20479 DATAVG
  Logical volume "LV1" created
# lvscan
  ACTIVE            '/dev/DATAVG/LV1' [80.00 GiB] inherit
  ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/centos/root' [17.51 GiB] inherit
# lvdisplay /dev/DATAVG/LV1
  --- Logical volume ---
  LV Path                /dev/DATAVG/LV1
  LV Name                LV1
  VG Name                DATAVG
  LV UUID                ru2n62-DgpE-B7Wx-cRgc-xu57-0hgu-ztezb2
  LV Write Access        read/write
  LV Creation host, time zzsrv1.bigcloud.local, 2014-08-11 14:37:08 +0800
  LV Status              available
  # open                 0
  LV Size                80.00 GiB
  Current LE             20479
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
# vgdisplay DATAVG
  --- Volume group ---
  VG Name               DATAVG
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               80.00 GiB
  PE Size               4.00 MiB
  Total PE              20479
  Alloc PE / Size       20479 / 80.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               Ff09cK-hwD0-hQMJ-hZX0-O9ju-ZaxL-0M6jCp

1.1.3. 文件系統配置

# mkfs.ext4 /dev/DATAVG/LV1
創建mount點,設置爲自動mount
# mkdir /wwwroot
# vi /etc/fstab
添加如下內容
/dev/DATAVG/LV1        /wwwroot    ext4    defaults      0 0
# mount /wwwroot/
# mount
會看到如下內容
/dev/mapper/DATAVG-LV1 on /wwwroot type ext4 (rw,relatime,data=ordered)

1.2. 安裝

# yum -y install httpd
安裝httpd會自動安裝依賴包:
apr
apr-util
httpd-tools
mailcap
# rpm -qi httpd
Name        : httpd
Version     : 2.4.6
Release     : 18.el7.centos
Architecture: x86_64
Install Date: Mon 11 Aug 2014 02:44:55 PM CST
Group       : System Environment/Daemons
Size        : 9793373
License     : ASL 2.0
Signature   : RSA/SHA256, Wed 23 Jul 2014 11:21:22 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-18.el7.centos.src.rpm
Build Date  : Wed 23 Jul 2014 10:49:10 PM CST
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible web server.

1.3. 配置

1.3.1. 默認配置

# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
# cd /etc/httpd/conf
# ls
httpd.conf  magic
# cp httpd.conf httpd.conf.origin
# more httpd.conf

查看配置文件,我們注意到以一配置:

DocumentRoot "/var/www/html"


特別是要注意這個配置

<Directory />

    AllowOverride none

    Require all denied

</Directory>

這是Apache 2.4的一個新的默認值,拒絕所有的請求!

設置爲自動啓動

# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

Windows計算機上使用瀏覽器訪問http://192.168.188.11/,成功


1.3.2. 生產WEB站點配置

創建兩個網站的目錄結構及測試用頁面文件

# mkdir /wwwroot/www
# echo "www.bigcloud.local" > /wwwroot/www/index.html
# mkdir /wwwroot/crm
# echo "crm.bigcloud.local" > /wwwroot/crm/index.html
配置虛擬機主機
# cd /etc/httpd/
# mkdir vhost-conf.d
# echo "Include vhost-conf.d/*.conf" >> conf/httpd.conf
# vi /etc/httpd/vhost-conf.d/vhost-name.conf

添加如下內容

<VirtualHost *:80>

   ServerName www.bigcloud.local

   DocumentRoot /wwwroot/www/

</VirtualHost>

<Directory  /wwwroot/www/>

    Require all granted

</Directory>


<VirtualHost *:80>

   ServerName crm.bigcloud.local

   DocumentRoot /wwwroot/crm/

</VirtualHost>

<Directory  /wwwroot/crm/>

   Require ip 192.168.188.0/24

</Directory>


Apache在系統日誌的信息很少,我們經常需要對其自有日誌進行分析。

# tail -f /var/log/httpd/error_log


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