Apache服務器的創建

搭建Apache服務器

1.要求:

ZZSRV1.BIGCLOUD.LOCAL使用Apache來提供Web服務。

此服務器上單獨安裝180GB的磁盤,使用LVM來進行卷管理:

  • VG名稱:DATAVG

  • 使用全部的80GB物理磁盤

  • 創建一個LVLV名稱爲LV1LV1使用VG的全部空間。

  • LV1文件系統爲EXT4Mount Point/wwwroot。要求服務器啓動時自動掛載

  • Web服務器上提供兩個網站服務/wwwroot/www


域名

Root目錄

備註

www.bigcloud.local

/wwwroot/www


crm.bigcloud.local

/wwwroot/crm

僅允許192.168.188.0/24的用戶來訪問

2.實驗步驟:

2.1.磁盤配置

2.1.1添加80G磁盤 

wKioL1P0OzOTDAxNAAJFdSeAavM414.jpg

查看一下磁盤信息,增加了sdb

# fdisk -l

 

Disk /dev/sda: 42.9 GB, 42949672960 bytes,83886080 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk label type: dos

Disk identifier: 0x0003c31b

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *        2048     1026047      512000  83  Linux

/dev/sda2         1026048    83886079   41430016   8e  Linux LVM

 

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 / 512bytes

 

 

sdb分區

# fdisk /dev/sdb

 

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux raidautodetect' to 'Linux LVM'

 

# 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 / 512bytes

Disk label type: dos

Disk identifier: 0x9fecc949

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1            2048   167772159   83885056   8e  Linux LVM

 

創建pv

# pvcreate /dev/sdb1

 Physical volume "/dev/sdb1" successfully created

創建vg--DATAVG

# vgcreate DATAVG /dev/sdb1

 Volume group "DATAVG" successfully created

顯示VG信息

# vgdisplay DATAVG

  ---Volume group ---

  VGName               DATAVG

 System ID

 Format                lvm2

 Metadata Areas        1

 Metadata Sequence No  1

  VGAccess             read/write

  VGStatus             resizable

  MAXLV                0

  CurLV                0

 Open LV               0

  MaxPV                0

  CurPV                1

  ActPV                1

  VGSize               80.00 GiB

  PESize               4.00 MiB

 Total PE              20479

 Alloc PE / Size       0 / 0

 Free  PE / Size       20479 / 80.00 GiB

  VGUUID              jwZL5m-TGmN-AGkh-PAxg-OEuZ-soie-l0Cbgk


創建lv--LV1,使用DATAVG的全部空間

# lvcreate -n LV1 -l 20479DATAVG

 Logical volume "LV1" created

展示LV具體信息

# lvdisplay /dev/DATAVG/LV1

  ---Logical volume ---

  LVPath                /dev/DATAVG/LV1

  LVName                LV1

  VGName                DATAVG

  LVUUID               EjNB6O-RD34-c01G-aDQY-n7oP-M7Jv-Y2VG54

  LVWrite Access        read/write

  LVCreation host, time zzsrv1.bigcloud.local, 2014-08-20 19:20:37 +0800

  LVStatus              available

  #open                 0

  LVSize                80.00 GiB

 Current LE             20479

 Segments               1

 Allocation             inherit

 Read ahead sectors     auto

  -currently set to     8192

 Block device           253:2


2.1.2 文件系統配置


格式化lv

# mkfs.ext4 /dev/DATAVG/LV1


創建掛載點/wwwroot

# mkdir /wwwroot


設置爲自動掛載

# vi /etc/fstab

在最後添加如下:

/dev/DATAVG/LV1        /wwwroot                 ext4    defaults        0 0


lv掛載

# mount /wwwroot

# mount

會看到如下內容:

/dev/mapper/DATAVG-LV1 on /wwwroot typeext4 (rw,relatime,data=ordered)

 

2.2 安裝包

# yum -y install httpd

 

# 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


2.3 web服務配置 

# cd /etc/httpd/conf

先對配置文件進行備份

# cp httpd.confhttpd.conf.origin

# ps aux |grep httpd

root     2608  0.0  0.0 112640  968 pts/0    R+   19:33  0:00 grep --color=auto httpd

 

啓動httpd服務

# systemctl start httpd

查看進程

# ps aux |grep httpd

root     2611  4.3  0.4 213688 4868 ?        Ss   19:33  0:00 /usr/sbin/http  -DFOREGROUND

apache   2612  0.0  0.2 213688 2856 ?        S    19:33  0:00 /usr/sbin/http  -DFOREGROUND

apache   2613  0.0  0.2 213688 2856 ?        S    19:33  0:00 /usr/sbin/http  -DFOREGROUND

apache   2614  0.0  0.2 213688 2856 ?        S    19:33  0:00 /usr/sbin/http  -DFOREGROUND

apache   2615  0.0  0.2 213688 2856 ?        S    19:33  0:00 /usr/sbin/http  -DFOREGROUND

apache   2616  0.0  0.2 213688 2856 ?        S    19:33  0:00 /usr/sbin/http  -DFOREGROUND

root     2618  0.0  0.0 112640  968 pts/0    R+   19:34  0:00 grep --color=auto httpd


在客戶端瀏覽器上輸入IP地址查看:

wKioL1P0PRDSrxiwAAMM2QdZZYs179.jpg 


創建兩個網站的目錄和測試頁面

# 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

[root@zzsrv1 httpd]# mkdir vhost-conf.d

[root@zzsrv1 httpd]# echo "Includevhost-conf.d/*.conf" >> conf/httpd.conf

[root@zzsrv1 httpd]#  vi 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>

修改完後重啓httpd服務

# systemctl restart httpd

在客戶端瀏覽器上輸入域名查看:

wKioL1P0PRHQ2WadAADnE9adLwM207.jpg

wKiom1P0O_nxptUKAADaXNav4d4685.jpg

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