RHCSA認證培訓+考試七天實錄(四)

第四天(722日)html

今天的主要內容是磁盤分區、管理邏輯卷以及管理計劃任務。
 
1、磁盤分區
老師推薦用圖形界面進行磁盤分區,我感受仍是用圖形結合命令一塊兒用的好。
1 、建立大小爲400 MB 的新分區和ext4 文件系統。該文件系統應永久掛載在/data 的下面。
我在虛擬機中新添加了一塊硬盤sdb,就用這塊硬盤完成這些操做。
[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n                       #n是新建分區
Command action
   e   extended
   p   primary partition (1-4)
p                                          #p是建立主分區
Partition number (1-4): 1                      #指定主分區編號
First cylinder (1-2610, default 1):                #指定分區開始柱面,這裏直接回車用默認值。
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +400M        #設置分區大小
 
Command (m for help): p                                             #查看分區狀況
   Device Boot      Start         End      Blocks    Id  System
/dev/sdb1          1           52     417658+   83   Linux
Command (m for help): w          #保存退出
The partition table has been altered!
這樣分區的操做就完成了,而後須要執行partx命令刷新一下
[root@localhost ~]# partx -a /dev/sdb
下面再將分區格式化,並指定使用ext4文件系統:
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
下面將分區掛載到/data:
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sdb1 /data
修改/etc/fstab將分區永久掛載:
[root@localhost ~]# vi /etc/fstab
/dev/sdb1                /data                  ext4     defaults        0 0

注意,若是要在圖形界面中建立邏輯分區,在建立好擴展分區以後,必須重啓系統,而後才能在其中繼續建立邏輯分區。
2 、永久添加大小爲500MB 的交換分區。
建立交換分區仍是用圖形界面更加簡單。

而後修改/etc/fstab文件,將分區永久掛載:web

[root@localhost ~]# vi /etc/fstab
/dev/sdb2                swap                   swap     defaults        0 0
修改完以後,繼續執行下面的命令:
[root@localhost ~]# swapon –a            #使交換分區生效
[root@localhost ~]# swapon –s            #查看交換分區狀況
3 、建立加密的設備,使其包含大小爲256 MB 的ext4 文件系統,並使用密碼testing123 。將文件系統掛載至/test
這個操做也用圖形界面來作,建立分區並勾選「加密底層設備」。

設置加密密碼:
apache

注意這個加密分區的設備名爲/dev/dm-2瀏覽器

 

掛載分區:服務器

[root@localhost ~]#mkdir /test
[root@localhost ~]#mount /dev/dm-2 /test
編輯/etc/fstab文件使之永久掛載。
[root@localhost ~]# vi /etc/fstab
/dev/dm-2                /test                   ext4     defaults        0 0
 
2、管理邏輯卷
1 、建立一個VG 和LV,PE 大小8M ,LV 中PE 個數10 ,自動掛載到/mnt/wshare/ 格式化爲vfat 文件系統,其中 Vg 名稱爲wgroup ,lv 名稱爲wshare
要建立邏輯卷,首先要分區。這裏先分出一個300MB的分區sdb4。

管理邏輯卷也最好用圖形界面,可是Linux中默認沒安裝邏輯卷管理器,因此首先要安裝: ssh

[root@localhost ~]#yum install system-config-lvm 編輯器

而後打開「系統\管理\邏輯卷管理器」進行邏輯卷的設置。 ide

首先在「未初始化的實例」中找到sdb4,點擊「初始化實例」將其初始化成物理卷PV 測試

而後在「未分配的卷」中選中物理卷,執行「建立新的卷組」,建立一個新的卷組VG網站

 

根據題目要求,VG的名字爲「wgroup」,PE大小爲8MB

而後在wgroup卷組中建立新的邏輯卷LV

 

按題目要求輸入LVwshareLV大小是10PE,題目要求用vfat文件系統,但這裏沒法設置,因此先設成ext4,等一會再改。由於要修改文件系統,因此這裏也先不掛載。

在命令行中執行lvdisplay命令能夠查看當前的邏輯卷,重點查看它的設備名。

[root@test ~]# lvdisplay
 --- Logical volume ---
 LV Name                 /dev/wgroup/wshare
 VG Name                 wgroup
 LV UUID                 SYJ6dO-sPsi-TYtS-He0e-CfhC-HAlf-dijoKf
 LV Write Access         read/write
 LV Status               available
 # open                  0
 LV Size                 80.00 MiB
 Current LE              10
 Segments                1
 Allocation              inherit
 Read ahead sectors      auto
 - currently set to      256
 Block device            253:3
將邏輯卷格式化:
[root@test ~]# mkfs -t vfat /dev/wgroup/wshare
建立目錄並掛載邏輯卷:
[root@test ~]# mkdir /mnt/wshare
[root@test ~]# mount /dev/wgroup/wshare /mnt/wshare
2 、將/home 分區LVM 從190M 縮小爲100M
這個操做很簡單,在邏輯卷編輯器中對邏輯卷直接編輯屬性就能夠,這裏就不作了。
 
3、計劃任務管理 crontab
1 、設置root 用戶的計劃任務
天天早上7:50 自動開啓sshd 服務,22:50 關閉。
首先建立計劃任務:
[root@test wshare]# crontab -e -u root
-e參數是編輯計劃任務,-u參數是指定用戶。而後會進入文本編輯狀態,輸入計劃任務,計劃任務的書寫格式以下圖:

因此根據題目要求能夠以下編寫計劃任務,注意其中用到的命令必需要加上絕對路徑,命令路徑能夠用which命令查看。

50 7 * * * /sbin/service sshd start
50 22 * * * /sbin/service sshd stop
每隔5 天清空一次FTP 服務器公共目錄/var/ftp/pub
[root@test wshare]# crontab -e -u root
0 0 */5 * * /bin/rm -rf /var/ftp/pub/*
每週六的7:30 時,從新啓動httpd 服務。
[root@test wshare]# crontab -e -u root
30 7 * * 6 /sbin/service httpd restart
每週1、3、五的17:30 ,打包備份/etc/httpd 目錄。
[root@test wshare]# crontab -e -u root
30 17 * * 1,3,5 /bin/tar czvf httpbak.tar.gz /etc/httpd/
天天晚上9:30 重啓Linux 系統,並刪除/var/www/usr1 下的全部文件。
[root@test wshare]# crontab -e -u root
30 21 * * * /bin/rm -rf /var/www/usr1/*;/sbin/reboot
最後能夠查看root用戶的計劃任務列表:
[root@test wshare]#crontab –l –u root
 
4、基本服務器的配置
服務器的配置與管理是RHCE考查的重點內容,RHCSA中涉及的很是簡單。
1 、架設基於apache 服務器的web 訪問,從ftp://192.168.0.254/pub/ 上下載station.html 到本地,做爲網站的首頁文件,並在本地訪問網站。
 [root@test wshare]# service httpd start                   #啓動httpd服務
[root@test wshare]# chkconfig --level 35 httpd on           #讓httpd服務開機自動運行
 [root@test ~]# wget ftp://192.168.0.254/pub/station.html     #從服務器下載網頁文件
[root@test ~]# cp station.html /var/www/html/index.html    #複製網頁文件到web服務器主目錄並更名
2 、架設FTP 服務器,容許匿名用戶下載。
[root@test wshare]# service vsftpd start                   #啓動vsftpd服務
[root@test wshare]# chkconfig vsftpd on                   #讓服務開機自動運行
[root@test wshare]#cd /var/ftp/pub                     #進入ftp的公共目錄
[root@test pub]#touch test                              #建立一個測試文件
最後能夠經過瀏覽器對上面兩個服務器進行訪問測試。
相關文章
相關標籤/搜索