全程第7周

一、自建yum仓库,分别为网络源和本地源
网络源
以阿里云为例
1.访问https://developer.aliyun.com/mirror/

 

2.点击系统名称,如centos,进入配置方法说明界面
3.将阿里提供的yum源repo文件下载至本地,以centos7为例,替换或删除原来的CentOS-Base.repo
4.运行 yum makecache 生成缓存
5.cat CentOS-Base.repo

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

本地源
1. 系统安装光盘作为本地yum仓库:
(1) 挂载光盘至某目录,例如/mnt/cdrom
mount /dev/cdrom /mnt/cdrom
(2) 创建配置文件
[CentOS7]
name=CentOS7
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
2. 创建yum仓库:
createrepo [options] <directory>
3.挂载iso镜像文件作为本地yum仓库:
mount -o loop xxx.iso /mnt/cdrom

二、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。

1. 解决依赖关系

httpd-2.4.9需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。

(1) 编译安装apr

# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install

(2) 编译安装apr-util

# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install

(3) httpd-2.4.9编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。

 

2、编译安装httpd-2.4.9

 

# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install

3. 提供SysV服务脚本/etc/rc.d/init.d/httpd

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac

exit $RETVAL

# chmod +x /etc/rc.d/init.d/httpd
# chkconfig --add httpd

三、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

[root@zlc ~]# mke2fs -t ext4 -b 2048 -m 1 -L TEST /dev/sda1

[root@zlc ~]# vim /etc/fatab

# 最后一行添加

/dev/sda1 /test ext4 acl 0 0

[root@zlc ~]# mount -a

四、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

(1)创建分区磁盘
  新加一块SCSI硬盘,新建两个分区:

  #fdisk  /dev/sda

  Command (m for help):n //创建新分区
  e extended //输入e为创建扩展分区
  p primary partition (1-4) //输入p为创建主分区,这里我们选择p
  Partion number(1-4):1 //第一个扩展分区,按你需求可以最多分4个主分区
  First Cylinder(1-1014,default 1): 1 //第一个主分区起始的磁盘块数
  Last cylindet or +siza or +sizeM or +sizeK: +10G
  Hex code (type L to list codes):8e //分区类型,Linux LVM
  Command (m for help): w
  The partition table has been altered!

  #partprobe  //不用重启可使以上操作生效。  
  这样我们就创建完一个分区/dev/sda1,根据上述步骤创建第二个10G的分区/dev/sda2。
(2)创建物理卷
    [root@station1 ~]# pvcreate /dev/sda{1,2} 
    [root@station1 ~]# pvs -- 查看物理卷信息
    [root@station1 ~]# pvdisplay /dev/sda{1,2}   --查看物理卷详细参数
(3)创建卷组
    [root@station1 ~]# vgcreate -s 16M  testvg  /dev/sda{1,2}
    [root@station1 ~]# vgs     --查看卷组信息
    [root@station1 ~]# vgdisplay  testvg   --查看卷组详细参数
(4)创建逻辑卷
    [root@station1 ~]# lvcreate -L 5G -n testlv testvg
    [root@station1 ~]# lvs    --查看逻辑卷信息
    [root@station1 ~]# lvdisplay  /dev/testvg/testlv  --查看逻辑卷详细参数
(5)格式化
    [root@station1 ~]# mke2fs -t ext4  -b 2048 -m 1 -L TEST /dev/testvg/testlv
(6)挂载
   [root@station1 ~]# mount /dev/testvg/testlv /users
    永久挂载
    [root@station1 ~]# vi /etc/fstab
    /dev/testvg/testlv     /users    ext4      defaults  0  0

 


附:逻辑卷扩展,缩减及创建快照方法

 一、扩展逻辑卷lv:(必须先扩展逻辑卷的物理边界,再扩展逻辑边界)
     lvextend 扩展逻辑卷的物理边界
    -L [+]# /PATH/TO/LV_NAME  --指定扩展后的容量,+表示在目前容量上直接增加#容量
                                                    不用+表示,扩展后的容量为#
     resize2fs  扩展逻辑卷的逻辑边界
         resize2fs /PATH/TO/LV 5G  扩展逻辑边界到5G,该值不能超过物理边界
         resize2fs -p /PATH/TO/LV :-p表示扩展逻辑边界跟物理边界一样大。

 二、缩减逻辑卷lv:(必须先缩减逻辑卷的逻辑边界,再缩减物理边界)
  注意:(1)不能在线缩减,得先卸载;
             (2)确保缩减后的空间大小依然能存储原有的所有数据;
             (3)在缩减之前应该先强行检查文件,以确保文件系统处于一致性状态。
   缩减步骤:
 1、先查看已经使用的lv大小,以便保证缩减后的容量大小能够容纳现有的数据。
     df -lh 查看容量大小
    [root@xuelinux ~]# df -lh
    Filesystem               Size  Used Avail Use% Mounted on
    .........
   /dev/mapper/myvg-testlv  3.0G  4.5M  2.8G   1% /mnt       此选项表示lv目前只使用了4.5M

2、必须先卸载挂载,不能在线缩减。
  [root@xuelinux ~]# umount /mnt    卸载挂载的lv
  [root@xuelinux ~]# mount            查看挂载的lv是否卸载成功

3、强行对lv执行文件系统检测
 [root@xuelinux ~]# e2fsck -f /dev/myvg/testlv    对lv强制执行文件系统检测
 e2fsck 1.41.12 (17-May-2010)
 第1步: 检查inode,块,和大小
 第2步: 检查目录结构
 第3步: 检查目录连接性
 第4步: Checking reference counts
 第5步: 检查簇概要信息
 /dev/myvg/testlv: 11/196608 files (0.0% non-contiguous), 13500/786432 blocks

4、使用resize2fs对lv逻辑卷的逻辑边界空间大小调整为缩减后的大小
resize2fs /dev/myvg/testlv2G 对lv逻辑卷的逻辑边界空间大小调整为2G
[root@xuelinux ~]# resize2fs /dev/myvg/testlv 2G  调整逻辑卷的逻辑边界大小为2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/testlv to 524288 (4k) blocks.
The filesystem on /dev/myvg/testlv is now 524288 blocks long.

5、使用lvreduce对lv逻辑卷的物理边界进行缩减
 lvreduce -L 2G /dev/myvg/testlv  对逻辑卷的物理边界缩减为2G
 [root@xuelinux ~]# lvreduce -L 2G /dev/myvg/testlv  对逻辑卷的物理边界缩减为2G  
  WARNING: Reducing active logical volume to 2.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce testlv? [y/n]: y
  Reducing logical volume testlv to 2.00 GiB
  Logical volume testlv successfully resized

6、然后继续对lv进行挂载操作
[root@xuelinux ~]# mount /dev/myvg/testlv /mnt  挂载lv逻辑卷
[root@xuelinux ~]# df -lh  查看已经挂载的分区信息
Filesystem               Size  Used Avail Use% Mounted on
......
/dev/mapper/myvg-testlv  2.0G  4.5M  1.9G   1% /mnt   此处lv逻辑卷缩减为2G

三、快照卷
    (1)生命周期为整个数据时长,在这段时间内,数据的增长量不能超出快照卷大小(即创建快照卷所指定的容量大小-L指定的大小);
     (2)快照卷应该是只读的;
     (3)快照卷必须跟原卷在同一卷组内;
lvcreate 
     -s:表示创建快照卷  snapshot快照
     -p r|w :指定快照卷权限 r为只读 w为写
格式:lvcreate -L # -n SLV_NAME -s -p r /dev/myvg/testlv 
Usage: lvcreate -L 1G -n testlv-snap -s -p r /dev/myvg/testlv
对/dev/myvg/testlv 逻辑卷创建一个1G的只读快照卷,名称为testlv-snap
[root@xuelinux ~]# lvcreate -L 1G -n testlv-snap -s -p r /dev/myvg/testlv
 Logical volume "testlv-snap" created
挂载该snap设备
[root@xuelinux ~]# mount /dev/myvg/testlv-snap /user
mount: block device /dev/mapper/myvg-testlv--snap is write-protected, mounting read-only
然后对该snap挂载目录里面的文档进行备份即可,如遇到被删除可以直接从snap中恢复。
 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值