第四十三天: 新升级CentOS初始化脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
rm -rf /etc/yum.repos.d/*
#pipy
#index-url = http://mirrors.aliyun.com/pypi/simple/
#trusted-host=mirrors.aliyun.com
#index-url = http://pypi.douban.com/simple
#trusted-host = pypi.douban.com
if [[ $1 == "net" ]]; then
    echo '[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
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/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
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/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
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/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
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/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
'
> /etc/yum.repo.d/centos.repo
echo "Aliyun mirrors added ... "
elif [[ $1 == "-h" ]]; then
    echo " -h : for help
    net : create repo for  Aliyun
    cd : using cd
    epel : create repo for epel in Aliyun"

    #statements
elif [[ $1 == "epel" ]]; then
    echo '[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
        http://mirrors.aliyuncs.com/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
        http://mirrors.aliyuncs.com/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
        http://mirrors.aliyuncs.com/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
'
> /etc/yum.repo.d/epel.repo
elif [[ $1 == "cd" ]]; then
    mkdir /cdrom
    echo "[cdrom]
name=CDROM
baseurl=file:///cdrom
gpgcheck=0
enable=1"
> /etc/yum.repos.d/cdrom.repo
    echo "set ai
set nu"
>>/root/.vimrc
    mount /dev/cdrom /cdrom
    read -p "automatic mount cdrom ?[Y/n]" cho
    if [[ cho == [yY] ]];then
    UUIDCD=`blkid | grep -o "UUID=.*iso9660" | cut -d" " -f1`
    echo "$UUIDCD   /cdrom  iso9660 default     0   0" >> /etc/fstab
    fi
fi
echo "wait ... now is going to intall some softwares"
sleep 5
yum makecache
yum install -y vim
yum install -y tree
yum install -y gcc
yum install -y finger
yum install -y wget

第四十二天: 简化数据结构的初始化过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
'python strip'


class Structure:
    """docstring for Structure."""
    _fields = []

    def __init__(self, *args):
        '将输入的数据作为元组保存到args中'
        if len(args) != len(self._fields):
            raise TypeError('Excepted { } arguments'.format(len(self._fields)))
        '对内置对象和args中的数据进行绑定, '
        '就不用每次创建类的时候, 输入新的__init__进行初始化'
        for name, value in zip(self._fields, args):
            'setattr(object, name, value)等同于 name = value'
            setattr(self, name, value)

if __name__ == '__main__':
    class Stock(Structure):
        _fields = ['name', 'shares', 'price']

    class Point(Structure):
        _fields = ['x', 'y']

    class Circle(Structure):
        _fields = ['radius']
        '使用的时候, 通过调用Circle(23), 将数据输入到类中的函数进行处理'

        def area(self):
            return math.pi * self.radius ** 2

第四十一天: 高级磁盘管理&RAID&LVM

配置配额系统

综述

  •   在内核中执行
  •   以文件系统为单位启用
  •   对不同组或者用户的策略不同

根据块或者节点进行限制

执行软限制( soft limit)
硬限制( hard limit)

初始化

分区挂载选项: usrquota、 grpquota

在创建好分区后, 对/etc/fstab 进行修改 , 加入 后加进来的分区的UUID和其他选项, 在挂载选项加入usrquota,grpquota两项, 加入后, 使用mount -a 通过读取/etc/fstab文件来挂载新的分区..

201608292041001201608292040001
初始化数据库: quotacheck

为用户设定配额

执行

开启或者取消配额: quotaon、 quotaoff
直接编辑配额: edquota username
在shell中直接编辑:

setquota usename 4096 5120 40 50 /foo

 

定义原始标准用户

edquota -p user1 user2

报告配额状态

报告

  •   用户调查: quota username
  •   配额概述: repquota /mountpoint
  •   其它工具: warnquota

201608292047001

什么是RAID

RAID:Redundant Arrays of Inexpensive(Independent) Disks
1988年由加利福尼亚大学伯克利分校( University ofCalifornia-Berkeley) “ A Case for Redundant Arrays of Inexpensive Disks”。多个磁盘合成一个“阵列”来提供更好的性能、冗余,或者两者都提供

RAID

提高IO能力:

  • 磁盘并行读写
  • 提高耐用性
  • 磁盘冗余来实现

级别:多块磁盘组织在一起的工作方式有所不同

 RAID实现的方式:

外接式磁盘阵列:通过扩展卡提供适配能力
内接式RAID:主板集成RAID控制器
安装OS前在BIOS里配置

软件RAID:通过OS实现
RAID级别

RAID-0:条带卷, strip
RAID-1: 镜像卷, mirror
RAID-2
..
RAID-5
RAID-6
RAID-10
RAID-01

RAID级别

RAID-0(条带卷, 将数据以chrunk为单位进行分割存放至不同的磁盘上):

读、写性能提升;
可用空间: N*min(S1,S2,…)
无容错能力
最少磁盘数: 2, 2

RAID-1(镜像卷,将一份数据备份存放到多个磁盘上):

读性能提升、写性能略有下降;
可用空间: 1*min(S1,S2,…)
有冗余能力
最少磁盘数: 2, 2N

RAID-4:

多块数据盘异或运算值,存于专用校验盘

 RAID-5:

读、写性能提升
可用空间: (N-1)*min(S1,S2,…)<