RHCE試題+答案(2017-10-30)

RHCE_pdf下載: 下載地址
兩臺虛擬機,請認準機器再做。
本域是domainX.example.com,172.25.X.0/24;敵對域my133t.org,172.26.X.0/24
***************開始練習前先運行,預備環境(考試時無需做這個)
練習準備lab teamdesk setup , desktop上做,創建eno1和eno2網卡
練習準備lab teambridge setup, server上做,創建eno1和eno2網卡
練習準備lab storageshares setup , server和desktop都需要做,將機器加入域,能作krb5p


考試準備工作:
一次性放開本域的所有訪問(server,desktop)

firewall-cmd --permanent --list-all
[root@server16 ~]# firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address="172.25.16.0/24" accept'
success
[root@server16 ~]# firewall-cmd --reload 
success
[root@server16 ~]# firewall-cmd --list-all
  rich rules: 
    rule family="ipv4" source address="172.25.16.0/24" accept

如遇到阻止需求,明確reject即可。

正式答題:

1.配置 SELinux(server,desktop)
SELinux 必須在兩個系統server 和 desktop中運行於 Enforcing 模式

[root@server16 ~]# setenforce 1
[root@server16 ~]# vim /etc/selinux/config
SELINUX=enforcing

在兩個虛機都做

2.配置SSH訪問(server,desktop)

按以下要求配置SSH訪問:
用戶能夠從域 domainX.example.com內的客戶端通過SSH遠程訪問您的兩個虛擬機系統,在域 my133t.org 內的客戶端不能訪問您的兩個虛擬機系統

[root@server16 ~]# firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address="172.26.16.0/24" service name="ssh" reject'
success
[root@server16 ~]# firewall-cmd --reload 
success
[root@server16 ~]# firewall-cmd --list-all
  rich rules: 
    rule family="ipv4" source address="172.26.16.0/24" service name="ssh" reject

在兩個虛機都做

3.自定義用戶環境(server,desktop)
在系統 server 和 desktop上創建自定義命令名爲 qstat 此自定義命令將執行以下命令:
/bin/ps -Ao pid,tt,user,fname,rsz
此命令對系統中所有用戶有效。

[root@server16 ~]# vim /etc/bashrc
末尾加 alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz'
[root@server16 ~]# . /etc/bashrc
[root@server16 ~]# qstat

在兩個虛機都做

4.配置端口轉發
在系統 server 配置端口轉發, 要求如下:
在 172.25.X.0/24 網絡中的系統, 訪問 server 的本地端口 5423 將被轉發到80
此設置必須永久有效

[root@server16 ~]# firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address="172.25.16.0/24" forward-port port=5423 protocol=tcp to-port=80'
success
[root@server16 ~]# firewall-cmd --reload 
success
[root@server16 ~]# firewall-cmd --list-all
    rule family="ipv4" source address="172.25.16.0/24" forward-port port="5423" protocol="tcp" to-port="80"

5.配置聚合鏈路(server,desktop)
在 server.domainX.example.com 和 desktop.domainX.example.com之間按以下要求配置一個鏈路:
此鏈路使用接口 eno1 和 eno2
此鏈路在一個接口失效時仍然能工作
此鏈路在 server 使用下面的地址 172.16.X.25/255.255.255.0
此鏈路在 desktop 使用下面的地址 172.16.X.35/255.255.255.0
此鏈路在系統重啓之後依然保持正常狀態
[server]

[root@server16 ~]# nmcli con show --active 
NAME         UUID                                  TYPE            DEVICE 
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  eth0   
[root@server16 ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'
[root@server16 ~]# nmcli con modify team0 ipv4.method manual ipv4.addresses "172.16.16.25/24"
[root@server16 ~]# nmcli con add type team-slave con-name team0-port1 ifname eno1 master team0
[root@server16 ~]# nmcli con add type team-slave con-name team0-port2 ifname eno2 master team0 
[root@server16 ~]# teamdctl team0 state
setup:
  runner: activebackup
ports:
  eno2
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
  eno1
    link watches:
      link summary: up
      instance[link_watch_0]:
        name: ethtool
        link: up
runner:
  active port: eno1
[root@server16 ~]#

[desktop]
desktop端只改變ip其他相同。
6.配置IPv6地址(server,desktop)
在您的考試系統上配置接口 eth0 使用下列IPv6地址:
server 上的地址應該是 200e:ac18::e0a/64
desktop 上的地址應該是 200e:ac18::e14/64
兩個系統必須能與網絡 200e:ac18/64 內的系統通信。
地址必須在重啓後依舊生效。
兩個系統必須保持當前的IPv4地址並能通信。

[root@server16 ~]# nmcli con modify "System eth0" ipv6.method manual ipv6.addresses '200e:ac16::e0a/64'
[root@server16 ~]# nmcli con down "System eth0"; nmcli con up "System eth0"

兩臺都做,複製時注意修改ip;

7.配置本地郵件服務(server,desktop)
在系統server 和 desktop 上 配置郵件服務,滿足以下要求:
這些系統不接收外部發送來的郵件
在這些系統上本地發送的任何郵件都會自動路由到 classroom.example.com
從這些系統上發送的郵件顯示來自於 domainX.example.com
您可以通過發送郵件到本地用戶 ‘dave’ 來測試您的配置, 系統 classroom.example.com 已經配置把此用戶的郵件轉到下列URL http://classroom.example.com/received_mail/X

[root@server16 ~]# postconf -e "relayhost= classroom.example.com"
[root@server16 ~]# postconf -e "inet_interfaces=loopback-only"
[root@server16 ~]# postconf -e "mynetworks=127.0.0.0/8 [::1]/128"
[root@server16 ~]# postconf -e "myorigin= domainX.example.com"
[root@server16 ~]# postconf -e "mydestination="
[root@server16 ~]# postconf -e "local_transport=error: local delivery disabled"
[root@server16 ~]# systemctl restart postfix
[root@server16 ~]# systemctl enable postfix
[root@server16 ~]# mail -s "Hello" [email protected]
aaaaaaaaaaaaaaaaa
EOT  [ctrl+D]
[root@server16 ~]#

兩臺都做

8.通過 SMB 共享目錄
在server上配置SMB服務
您的 SMB 服務器必須是 STAFF 工作組的一個成員
共享 /common 目錄 共享名必須爲 common
只有 domainX.example.com 域內的客戶端可以訪問 common 共享
common 必須是可以瀏覽的
用戶 andy 必須能夠讀取共享中的內容,如果需要的話,驗證的密碼是 sestiver
[server]

[root@server16 ~]# yum -y install samba samba-client
[root@server16 ~]# vim /etc/samba/smb.conf 
        workgroup = STAFF

        hosts allow = 127. 172.25.16.
        hosts deny = 172.26.16.
#============================ Share Definitions ==============================
[common]
        path = /common
        browseable = yes
        read list = andy

[root@server16 ~]# mkdir /common
[root@server16 ~]# semanage fcontext -a -t samba_share_t '/common(/.*)?'
[root@server16 ~]# restorecon -vRF /common/
[root@server16 ~]# systemctl start nmb smb 
[root@server16 ~]# systemctl enable nmb smb
[root@server16 ~]# useradd andy
[root@server16 ~]# smbpasswd -a andy 
New SMB password:
Retype new SMB password:
Added user andy.
[root@server16 ~]# pdbedit -L
andy:1001:

[desktop]

[root@desktop16 ~]# yum install samba-client cifs-utils
[root@desktop16 ~]# smbclient -L //172.25.16.11
    Sharename       Type      Comment
    ---------       ----      -------
    common          Disk
[root@desktop16 ~]# smbclient //172.25.16.11/common -U andy%sestiver
Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]
smb: \>
smb: \> ls
  .                                   D        0  Sun Oct 29 14:51:24 2017
  ..                                  D        0  Sun Oct 29 15:07:49 2017

        40913 blocks of size 262144. 28568 blocks available
smb: \> quit

9.配置多用戶SMB 掛載

在server 共享通過SMB目錄 /miscellaneous 滿足以下要求:
共享名爲 miscellaneous
共享目錄 miscellaneous 只能被 domainX.example.com 域中的客戶端使用
共享目錄 miscellaneous 必須可以被瀏覽
用戶 silene 必須能以讀的方式訪問此共享, 訪問密碼是 sestiver
用戶 akira 必須能以讀寫的方式訪問此共享, 訪問密碼是 sestiver
此共享永久掛載在 desktop.domainX.example.com 上的 /mnt/multi 目錄, 並使用用戶 silene 作爲認證 任何用戶可以通過用戶 akira 來臨時獲取寫的權限
[server]

[root@server16 ~]# vim /etc/samba/smb.conf 
[miscellaneous]
        path = /miscellaneous
        browseable = yes
        read list = silene
        write list = akira
[root@server16 ~]# mkdir /miscellaneous
[root@server16 ~]# chcon -R -t samba_share_t /miscellaneous/
[root@server16 ~]# chmod o+w /miscellaneous/
[root@server16 ~]# ll -d /miscellaneous/
drwxr-xrwx. 2 root root 6 Oct 29 15:07 /miscellaneous/
[root@server16 ~]# systemctl restart nmb smb
[root@server16 ~]# useradd silene
[root@server16 ~]# useradd akira
[root@server16 ~]# smbpasswd -a silene
New SMB password:
Retype new SMB password:
Added user silene.
[root@server16 ~]# smbpasswd -a akira
New SMB password:
Retype new SMB password:
Added user akira.
[root@server16 ~]# systemctl restart nmb smb
[root@server16 ~]# 

[desktop]

[root@desktop16 ~]# touch a b c
[root@desktop16 ~]# smbclient //172.25.16.11/miscellaneous -U silene%sestiver
Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]
smb: \> put a
NT_STATUS_ACCESS_DENIED opening remote file \a
smb: \> quit
[root@desktop16 ~]# smbclient //172.25.16.11/miscellaneous -U akira%sestiver
Domain=[STAFF] OS=[Unix] Server=[Samba 4.1.1]
smb: \> put a
putting file a as \a (0.0 kb/s) (average 0.0 kb/s)
smb: \> ls
  .                                   D        0  Sun Oct 29 15:25:29 2017
  ..                                  D        0  Sun Oct 29 15:07:49 2017
  a                                   A        0  Sun Oct 29 15:25:29 2017

        40913 blocks of size 262144. 28568 blocks available
smb: \>quit
[root@desktop16 ~]# vim /etc/fstab 
[root@desktop16 ~]# vim /etc/fstab 
//172.25.16.11/miscellaneous  /mnt/multi cifs  credentials=/root/a.txt,multiuser,sec=ntlmssp  0 0
[root@desktop16 ~]# mkdir /mnt/multi 
[root@desktop16 ~]# vim a.txt
username=silene
password=sestiver
username=akira
password=sestiver
[root@desktop16 ~]# mount -a
[root@desktop16 ~]# df -h
//172.25.16.11/miscellaneous   10G  3.1G  7.0G  31% /mnt/multi

[root@desktop16 ~]# useradd aaa
[root@desktop16 ~]# useradd bbb
[root@desktop16 ~]# su - aaa
[aaa@localhost ~]$ cd /mnt/
[aaa@localhost mnt]$ ll
ls: cannot access multi: Permission denied
total 0
drwxr-xr-x. 2 root root 6 Oct 29 11:21 data
??????????? ? ?    ?    ?            ? multi
[aaa@localhost mnt]$ cifscreds add server16 -u silene
Password:  
[aaa@localhost mnt]$ ll
total 0
drwxr-xr-x. 2 root root 6 Oct 29 11:21 data
drwxr-xrwx. 2 root root 0 Oct 29 15:25 multi
[aaa@localhost mnt]$ cd multi/
[aaa@localhost multi]$ ls
a
[aaa@localhost multi]$ touch aaa
touch: cannot touch ‘aaa’: Permission denied
[aaa@localhost multi]$ exit
logout
[root@desktop16 ~]# su - bbb
[bbb@localhost ~]$ cd /mnt/
[bbb@localhost mnt]$ ll
ls: cannot access multi: Permission denied
total 0
drwxr-xr-x. 2 root root 6 Oct 29 11:21 data
??????????? ? ?    ?    ?            ? multi
[bbb@localhost mnt]$ cifscreds add server16 -u akira
Password: 
[bbb@localhost mnt]$ ll
total 0
drwxr-xr-x. 2 root root 6 Oct 29 11:21 data
drwxr-xrwx. 2 root root 0 Oct 29 15:25 multi
[bbb@localhost mnt]$ cd multi/
[bbb@localhost multi]$ touch aaa
[bbb@localhost multi]$ ll
total 0
-rwxr--r--. 1 aaa aaa 0 Oct 29 15:25 a
-rw-r--r--. 1 aaa aaa 0 Oct 29 15:55 aaa
[bbb@localhost multi]$ 

11.配置NFS服務
在 server 配置NFS服務,要求如下:
以只讀的方式共享目錄 /public 同時只能被 domainX.example.com 域中的系統訪問
以讀寫的方式共享目錄 /protected 能被 domainX.example.com 域中的系統訪問
訪問 /protected 需要通過Kerberos安全加密, 您可以使用下面URL提供的密鑰 http://host.domainX.example.com/pub/materials/nfs_server.keytab.
目錄 /protected 應該包含名爲 confidential 擁有人爲deepak 的子目錄
域用戶 deepak 能以讀寫方式訪問 /protected/confidential
***************練習準備lab storageshares setup,server和desktop都需要做

[root@server16 ~]# mkdir /public
[root@server16 ~]# mkdir -p /protected/confidential
[root@server16 ~]# vim /etc/exports
/public 172.25.16.0/24(ro)
/protected 172.25.16.0/24(rw,sec=krb5p)
[root@server16 ~]# exportfs -r
[root@server16 ~]# cd /protected/
[root@server16 protected]# ll
total 0
drwxr-xr-x. 2 root root 6 Oct 29 16:10 confidential
[root@server16 protected]# chown ldapuser16:root confidential/
[root@server16 protected]# ll
total 0
drwxr-xr-x. 2 ldapuser16 root 6 Oct 29 16:10 confidential
[root@server16 protected]# cd
[root@server16 ~]# vim /etc/sysconfig/nfs 
RPCNFSDARGS="-V 4.2"
[root@server16 ~]# wget -O /etc/krb5.keytab http://172.25.254.254/pub/keytabs/server16.keytab
[root@server16 ~]# systemctl start nfs-server
[root@server16 ~]# systemctl start nfs-secure-server
[root@server16 ~]# systemctl enable nfs-server.service 
[root@server16 ~]# systemctl enable nfs-secure-server.service 

12.nfs客戶端
開機自動掛載
public /mnt/nfsmount
protected /mnt/nfssecure

[root@desktop16 ~]# wget -O /etc/krb5.keytab http://172.25.254.254/pub/keytabs/desktop16.keytab
[root@desktop16 ~]# vim /etc/fstab
172.25.16.11:/public /mnt/nfsmount  nfs defaults  0 0
172.25.16.11:/protected  /mnt/nfssecure  nfs  defaults,v4.2,sec=krb5p 0 0
[root@desktop16 ~]# systemctl start nfs-secure
[root@desktop16 ~]# systemctl enable nfs-secure.
[root@desktop16 ~]# mkdir /mnt/{nfsmount,nfssecure}
[root@desktop16 ~]# mount -a
[root@desktop16 ~]# df -h
172.25.16.11:/public           10G  3.1G  7.0G  31% /mnt/nfsmount
172.25.16.11:/protected        10G  3.1G  7.0G  31% /mnt/nfssecure
[root@desktop16 ~]#

13.配置web站點
server 上配置一個站點 http://server.domainX.example.com 然後執行下述步驟:
http://172.25.254.254/content/rhce/web/station.html
下載文件,並且將文件重命名爲 index.html 不要修改此文件的內容
將文件 index.html 拷貝到您的 web 服務器的 DocumentRoot 目錄下
來自於 domainX.example.com 域的客戶端可以訪問此Web服務
來自於 my133t.org 域的客戶端拒絕訪問此Web服務

[root@server16 ~]# yum -y install httpd
[root@server16 ~]# cd /var/www/html/
[root@server16 html]# wget -O index.html http://172.25.254.254/content/rhce/web/station.html
[root@server16 html]# ls
index.html
[root@server16 html]# cat index.html 
stationX
[root@server16 html]# cd /usr/share/doc/httpd-2.4.6/
[root@server16 httpd-2.4.6]# ls
[root@server16 httpd-2.4.6]# cp httpd-vhosts.conf /etc/httpd/conf.d/13.conf
[root@server16 httpd-2.4.6]# cd /etc/httpd/conf.d
[root@server16 conf.d]# vim 13.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName server16.example.com
</VirtualHost>
[root@server16 ~]# systemctl start httpd
[root@server16 ~]# systemctl enable httpd.service
[root@server16 ~]# netstat -ntlp
[root@server16 ~]# firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=172.26.16.0/24 service name="http" reject'
[root@server16 ~]# firewall-cmd --reload 
[root@server16 ~]# firewall-cmd --list-all


[desktop]
[root@localhost ~]# firefox http://server16.example.com
[root@localhost ~]# curl http://server16.example.com
stationX

14 配置安全web服務
爲站點 http://server.domainX.example.com 配置TLS加密 一個已簽名證書從 http://host.domainX.example.com/pub/materials/server.crt 獲取 此證書的密鑰從 http://host.domainX.example.com/pub/materials/server.key 獲取 此證書的簽名授權信息從 http://host.domainX.example.com/pub/materials/domainX.crt 獲取
[server]

[root@server16 ~]# yum -y install mod_ssl
[root@server16 ~]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/html"     (59)
ServerName www.example.com:443   (60)
SSLCertificateFile /etc/pki/tls/certs/server16.crt    (100)
SSLCertificateKeyFile /etc/pki/tls/private/server16.key    (107)

[root@server16 ~]# cd /etc/pki/tls/
[root@server16 tls]# ls
[root@server16 tls]# cd certs/
[root@server16 certs]# wget http://172.25.254.254/pub/tls/certs/server16.crt
[root@server16 certs]# cd ../private/
[root@server16 private]# wget http://172.25.254.254/pub/tls/private/server16.key
[root@server16 certs]# cd
[root@server16 ~]# systemctl restart httpd.service 

[desktop]

[root@localhost ~]# firefox https://server16.example.com
[root@localhost ~]# curl -k https://server16.example.com
stationX

15.配置虛擬主機
在 server 上擴展您的 web 服務器,爲站點 http://www.domainX.example.com創建一個虛擬主機,然後執行下述步驟:
設置 DocumentRoot 爲 /var/www/virtual
http://classroom.example.com/pub/materials/www.html
下載文件並重命名爲 index.html 不要對文件 index.html 的內容做任何修改
將文件 index.html 放到虛擬主機的 DocumentRoot 目錄下
確保 andy 用戶能夠在 /var/www/virtual 目錄下創建文件

注意:原始站點 http://server.domainX.example.com 必須仍然能夠訪問, 名稱服務器 rhmgr.domainX.example.com 提供對主機名 www.domainX.example.com 的域名解析
[server]

[root@server16 ~]# cd /etc/httpd/conf.d/
[root@server16 conf.d]# ls
13.conf  autoindex.conf  README  ssl.conf  userdir.conf  welcome.conf
[root@server16 conf.d]# cp 13.conf 15.conf
[root@server16 conf.d]# vim 15.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/virtual"
    ServerName www16.example.com
</VirtualHost>
[root@server16 conf.d]# cd /var/www/
[root@server16 www]# mkdir virtual
[root@server16 www]# setfacl -m u:andy:rwx virtual/
[root@server16 www]# setfacl -m d:u:andy:rwx virtual/
[root@server16 www]# cd virtual/
[root@server16 virtual]# wget -O index.html http://172.25.254.254/content/rhce/web/www.html
[root@server16 virtual]# cd
[root@server16 ~]# systemctl restart httpd.service

[desktop]

[root@localhost ~]# firefox http://www16.example.com
[root@localhost ~]# curl http://www16.example.com
wwwX

16 配置 web 內容的訪問

在您的server 上的 web 服務器的 DocumentRoot 目錄下 創建一個名爲 secret 的目錄,要求如下:
http://classroom.example.com/pub/materials/private.html 下載一個文件副本到這個目錄,並且重命名爲 index.html。
不要對這個文件的內容做任何修改。
從 server 上,任何人都可以瀏覽 secret 的內容, 但是從其它系統不能訪問這個目錄的內容

[root@server ~]# mkdir /var/www/html/secret
[root@server ~]# mkdir /var/www/virtual/secret
[root@server ~]# cd /var/www/html/secret
[root@server16 secret]# wget  -O index.html http://172.25.254.254/content/rhce/web/secret1.html
[root@server secret]# cd /var/www/virtual/secret
[root@server16 secret]# wget  -O index.html http://172.25.254.254/content/rhce/web/secret2.html
[root@server16 ~]# vim /etc/httpd/conf/httpd.conf
[root@server16 ~]# cd /etc/httpd/conf.d/
[root@server16 conf.d]# vim 16.conf
<Directory /var/www/html/secret>
    Require local
    Require all denied
</Directory>

<Directory /var/www/virtual/secret>
    Require local
    Require all denied
</Directory>
[root@server16 conf.d]# httpd -t
[root@server16 conf.d]# cd
[root@server16 ~]# systemctl restart httpd.service
[root@server16 ~]# firefox http://server16.example.com/secret
[root@server16 ~]# curl  http://server16.example.com/secret/
secret1/
[root@server16 ~]# firefox http://www16.example.com/secret
[root@server16 ~]# curl  http://www16.example.com/secret/
secret2/

[desktop]

[root@desktop16 ~]# firefox http://server16.example.com/secret/
[root@desktop16 ~]# firefox http://www16.example.com/secret/

17 實現動態Web內容
在 server 上配置提供動態Web內容,要求如下:
動態內容由名爲dynamic.domainX.example.com的虛擬主機提供 ###########教室練習請用webappX.example.com##########
虛擬主機偵聽在端口 8998
http://classroom.example.com/pub/materials/webapp.wsgi 下載一個腳本,然後放在適當的位置, 無論如何不要求修改此文件的內容
客戶端訪問 http://dynamic.domainX.example.com:8998/ 時 應該接收到動態生成的web頁面
http://dynamic.domainX.example.com:8998/ 必須能被 domainX.example.com 域內的所有系統訪問
[server]

[root@server16 ~]# yum install mod_wsgi
[root@server16 ~]# cd /etc/httpd/conf.d/
[root@server16 conf.d]# cp 13.conf 17.conf
[root@server16 conf.d]# vim 17.conf
Listen 8998
<VirtualHost *:8998>
    DocumentRoot "/var/www/html"
    ServerName server16.example.com
    WSGIScriptAlias / /var/www/html/webapp.wsgi
</VirtualHost>
[root@server16 conf.d]# httpd -t
[root@server16 ~]# cd /var/www/html/
[root@server16 html]# wget http://172.25.254.254/content/rhce/web/webapp.wsgi
[root@server16 ~]# semanage port -l |grep http
[root@server16 ~]# semanage port -a -t http_port_t -p tcp 8998
[root@server16 ~]# systemctl restart httpd.service

[desktop]

[root@localhost ~]# firefox http://webapp16.example.com:8998

18 shell編程
    文件名/root/script
參數foo顯示bar,參數bar顯示foo,
沒有參數或錯誤顯示“/root/script foo|bar”錯誤信息

[root@server ~]# vim /root/script 
#!/bin/bash
if [ "$#" -eq 1 ]
then
if [ "$1" == "bar" ]
then
echo "foo"
elif [ "$1" == "foo" ]
then
echo "bar"
else
echo "/root/script foo|bar" >&2
fi
else
echo "/root/script foo|bar" >&2
fi
[root@server16 ~]# chmod a+x /root/script

[root@server16 ~]# ./script foo
bar
[root@server16 ~]# ./script bar
foo
[root@server16 ~]# ./script 
/root/script foo|bar

19.創建一個添加用戶的腳本
在server上創建一個腳本,名爲/root/mkusers,此腳本能實現爲server創建本地用戶,並且這些用戶的用戶名來自一個包含用戶名列表的文件。同時滿足下列要求:
此腳本要求提供一個參數,此參數就是包含用戶名列表的文件
如果沒有提供參數,此腳本應該給出下面的提示信息Usage:/root/mkusers filename然後退出並返回相應的值。
如果提供一個不存在的文件名,此腳本應該給出下面的提示信息 Input file not found然後退出並返回相應的值
創建的用戶登錄shell是/bin/false
此腳本不需要爲用戶設置密碼
您可以從下面的URL獲取用戶名列表作爲測試用http://classroom.example.com/pub/materials/userlist

[root@server ~]# vim /root/mkusers
#!/bin/bash
if [ "$#" -ne  1 ] 
then echo 'Usage:/root/mkusers  filename' >&2
exit 1
elif [ -f  $1  ]
then  
for i in `cat $1`
do
useradd –s  /bin/fales  $i
done
else
echo 'Input file not found' >&2
exit 1
fi
[root@server ~]# chmod a+x /root/mkusers

20.配置iscsi服務器
配置server提供一個iscsi服務磁盤名爲iqn.2014-09.com.example.domain0:server,並符合下列要求:
服務端口爲3260
使用iscsi_vol作其後端卷,其大小爲3G
此服務只能被desktop.domain0.example.com訪問
需要先創建名字叫做iscsi_vol的邏輯卷。(分區至少3050M)

[server]

[root@desktop16 ~]# fdisk /dev/vdb
[root@desktop16 ~]# pvcreate /dev/vdb5
[root@desktop16 ~]# vgcreate vg0 /dev/vdb5
[root@desktop16 ~]# lvcreate -L 3G -n iscsi_vol vg0
[root@desktop16 ~]# lvs
[root@server16 ~]# yum install -y targetcli
[root@server16 ~]# systemctl start target
[root@server16 ~]# systemctl enable target.service 
[root@server16 ~]# targetcli
/> /backstores/block create server16.disk1 /dev/vg0/iscsi_vol 
/> /iscsi create iqn.2014-09.com.example.domain0:server16
/> /iscsi/iqn.2014-09.com.example.domain0:server16/tpg1/acls create iqn.2014-06.com.example:desktop16
/> iscsi/iqn.2014-09.com.example.domain0:server16/tpg1/luns create /backstores/block/server16.disk1 
/> /iscsi/iqn.2014-09.com.example.domain0:server16/tpg1/portals create 172.25.16.11
/> saveconfig 
/> exit

21 配置iscsi客戶端
配置desktop使其能連接在server的上提供的iqn.2014-09.com.example.domain2:server並符合下列要求:
塊設備iSCSI上包含一個大小爲1700 MiB的分區,並格式化爲xfs
此分區掛載在/mnt/data上同時在系統啓動的期間自動掛載
[desktop]

[root@desktop16 ~]# vim /etc/iscsi/initiatorname.iscsi  
InitiatorName=iqn.2014-06.com.example:desktop16
[root@desktop16 ~]# iscsiadm -m discovery -t st -p server16.example.com
172.25.16.11:3260,1 iqn.2014-09.com.example.domain0:server16
[root@desktop16 ~]# systemctl restart iscsid
[root@desktop16 ~]# systemctl restart iscsi
[root@desktop16 ~]# systemctl enable iscsid
[root@desktop16 ~]# systemctl enable iscsi
[root@desktop16 ~]# iscsiadm -m discovery -t st -p server16.example.com
172.25.16.11:3260,1 iqn.2014-09.com.example.domain0:server16
[root@desktop16 ~]# iscsiadm -m node -T iqn.2014-09.com.example.domain0:server16
[root@desktop16 ~]# iscsiadm -m node -T iqn.2014-09.com.example.domain0:server16 -l

[root@desktop16 ~]# fdisk -l
Disk /dev/sda: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
[root@desktop16 ~]# fdsik /dev/sda   (sda1 1700M)
[root@desktop16 ~]# mkfs.xfs /dev/sda1
[root@desktop16 ~]# blkid /dev/sda1
[root@desktop16 ~]# cp /etc/fstab .
[root@desktop16 ~]# blkid /dev/sda1 >> /etc/fstab
[root@desktop16 ~]# vim /etc/fstab
UUID="9471c035-d171-4c48-bc53-d877ef9bf001" /mnt/data xfs  defaults,_netdev 0 0
[root@desktop16 ~]# mkdir /mnt/data
[root@desktop16 ~]# mount -a
[root@desktop16 ~]# df -h
/dev/sda1       1.7G   33M  1.7G   2% /mnt/data

22.配置一個數據庫
在server上創建一個MariaDB 數據庫,名爲了Contacts,並符合以下條件:
數據庫應該包含來自數據庫複製的內容,複製文件的URL爲http://classroom.example.com/pub/materials/users.mdb
數據庫只能被localhost訪問
除了root用戶,此數據庫只能被Luigi查詢。此用戶密碼爲mishigs
root密碼mishings,同時不允許空密碼登錄。

[root@server16 ~]# yum install mariadb-server
[root@server16 ~]# vim /etc/my.cnf
skip-networking=1  (2+)
[root@server16 ~]# systemctl start mariadb
[root@server16 ~]# systemctl enable mariadb.service
[root@server16 ~]# mysql
MariaDB [(none)]> \q
Bye
[root@server16 ~]# mysql_secure_installation 
Enter current password for root (enter for none): [enter]
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
[root@server16 ~]# mysql -uroot -pmishings
MariaDB [(none)]> create database Contacts;
MariaDB [(none)]> grant select on Contacts.* Luigi@localhost identified by 'mishigs';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
[root@server16 ~]# mysql -uLuigi -pmishigs
MariaDB [(none)]> exit
[root@server16 ~]# wget http://172.25.254.254/pub/materials/mariadb/mariadb.dump
[root@server16 ~]# file mariadb.dump 
mariadb.dump: ASCII text
[root@server16 ~]# vim mariadb.dump
[root@server16 ~]# mysql -uroot -pmishings Contacts < mariadb.dump 
[root@server16 ~]# mysql -uLuigi -pmishigs Contacts
MariaDB [Contacts]> show databases
MariaDB [Contacts]> \q
[root@server16 ~]#

23.數據庫中的數據查詢,填空
數據庫中有三張表,“User_Names User_Logins User_Contacts”
在密碼錶當中查出密碼是forsook的用戶叫什麼名字
查出first name(看英文題)是Alan用戶住址在Cupertino的用戶個數

select User_Names.first_name from User_Names,User_Logins where User_Names.user_id=User_Logins.id and User_Logins.User_Pass="forsook";
或select user.name from user inner join infor on user.id=infor.id where infor.pass="tapacalaya";

select count(*) from User_Contacts,User_Names where User_Contacts.Location="Cupertino" and User_Names.first_name="Alan" and User_Contacts.id=User_Names.user_id;
或select count(*)  from user inner join address on user.id=address.id where user.name="john" and address.addr="Washion";
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章