1. 程式人生 > 實用技巧 >Linux入門(六)

Linux入門(六)

1、自建yum倉庫,分別為網路源和本地源 本地源: 1). 掛載iso檔案
]# mkdir /mnt/cd
]# mount -o loop /dev/cdrom /mnt/cd/
2). 編輯repo檔案
[local]
name=Local Cd
baseurl=file:///mnt/cd
enabled=1
gpgcheck=0

3). 測試

]# yum clean all
yum Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up list of fastest mirrors
Other repos take up 
172 M of disk space (use --verbose for details) ]# yum repolist Loaded plugins: fastestmirror Determining fastest mirrors local | 3.6 kB 00:00:00 (1/2): local/group_gz | 153
kB 00:00:00 (2/2): local/primary_db | 3.3 MB 00:00:00 repo id repo name status local Local Cd
4,071 repolist: 4,071

網路源(一): 1). 安裝http服務
yum -y install httpd
2). 掛載iso檔案
]# mkdir /var/www/html/centos7/
]# mv /root/CentOS-7-x86_64-DVD-2003.iso /var/www/html/
]# mount -o loop /var/www/html/CentOS-7-x86_64-DVD-2003.iso /var/www/html/centos7/

3). 編輯repo檔案

[centos7]
name=Centos7
baseurl=http://192.168.74.103/centos7/
enable=1
gpgcheck=0

4). 測試

]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
centos7                                                                                 | 3.6 kB  00:00:00     
(1/2): centos7/group_gz                                                                 | 153 kB  00:00:00     
(2/2): centos7/primary_db                                                               | 3.3 MB  00:00:00     
repo id                                             repo name                                            status
centos7                                             Centos7                                              4,071
local                                               Local Cd                                             4,071
repolist: 8,142

網路源(二): 可以搭建Nexus伺服器,通過代理的方式獲取最新的rpm包,可以配置yum源、apt源、pipy源等。

2、編譯安裝http2.4,實現可以正常訪問,並將編譯步驟和結果提交。 1). 下載編譯包
]# curl -o httpd-2.4.43.tar.gz https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9129k  100 9129k    0     0  7758k      0  0:00:01  0:00:01 --:--:-- 7762k
2). 解壓
]# tar zxf httpd-2.4.43.tar.gz
3). 環境準備
]# yum -y install apr-devel apr-util-devel gcc pcre-devel openssl-devel

4). configure指令碼

]# ./configure --prefix=/usr/local/httpd-2.4.43 --enable-ssl --enable-mpms-shared
5). make && make install 6). 安裝後配置
]# cd /usr/local
]# ln -s httpd-2.4.43/ httpd
]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/httpd/bin:$PATH
7). 測試
]# curl http://192.168.74.103
<html><body><h1>It works!</h1></body></html>


3、建立一個2G的檔案系統,塊大小為2048byte,預留1%可用空間,檔案系統 ext4,卷標為TEST,要求此分割槽開機後自動掛載至/test目錄,且預設有acl掛載選項 1). 建立塊裝置
]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
 
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe29fb483.
 
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +2G
Partition 1 of type Linux and of size 2 GiB is set
 
Command (m for help): p
 
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0xe29fb483
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

2). 格式化:預留1%可用空間,檔案系統 ext4,卷標為TEST

]# mkfs.ext4 -L TEST -m 1 /dev/sdb1
]# blkid /dev/sdb1
/dev/sdb1: LABEL="TEST" UUID="64a9946c-3c44-445a-9993-9edc57d61ba4" TYPE="ext4"
3). 掛載:開機後自動掛載至/test目錄,且預設有acl掛載選項
]# mkdir /test
編輯
/etc/fstab,新增: /dev/sdb1 /test ext4 defaults,acl 0 0 ]# mount -a
4). 驗證:
]# mount| grep test
/dev/sdb1 on /test type ext4 (rw,relatime,data=ordered)


4、建立一個至少有兩個PV組成的大小為20G的名為testvg的VG;要求PE大小 為16MB, 而後在卷組中建立大小為5G的邏輯卷testlv;掛載至/users目錄 1). 建立pv
]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.

2). 建立VG

]# vgcreate -s 16M testvg /dev/sdc1 /dev/sdd1
  Volume group "testvg" successfully created
3). 建立LV
]# lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.
4). 格式化
]# mkfs.ext4 /dev/testvg/testlv
5). 掛載
]# mkdir /users
]# mount /dev/testvg/testlv /users
]# mount | grep /users
/dev/mapper/testvg-testlv on /users type ext4 (rw,relatime,data=ordered)