首页 > 代码库 > CentOS项目实例之四--Apache配置
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=http://www.mamicode.com/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
本文出自 “刘琼@天道酬勤” 博客,请务必保留此出处http://lqiong.blog.51cto.com/8170814/1559064
CentOS项目实例之四--Apache配置