【红帽认证系列笔记之RHCE】RHCE认证考试题库(下)

2020-06-15 17:48:32 浏览数 (1)

RHCE考试参考试题及答案(下):

17、创建一个脚本

在server0上创建一个名为/root/foo.sh的脚本,让其提供下列特性:

当运行/root/foo.sh redhat,输出fedora 当运行/root/foo.sh fedora,输出redhat

当没有任何参数或者参数不是redhat或者fedora时,其错误输出产生以下的信息:

/root/foo.sh redhat|fedora

代码语言:javascript复制
[root@server0 ~]# touch /root/foo.sh
[root@server0 ~]# chmod a x foo.sh
[root@server0 ~]# vim foo.sh
[root@server0 ~]# cat foo.sh
#!/bin/bash
case $1 in
redhat)
echo "fedora"
;;
fedora)
echo "redhat"
;;
*)
echo "$0 redhat|fedora"
esac
[root@server0 ~]#

测试:
[root@server0 ~]# ./foo.sh redhat
fedora
[root@server0 ~]# ./foo.sh fedora
redhat
[root@server0 ~]# ./foo.sh ffewfewf
./foo.sh redhat|fedora
[root@server0 ~]#

18、创建一个添加用户的脚本

在server0上创建一个名为/root/batchusers,此脚本能够实现为系统system1创建本地用户,并且这些用户的用户名来自一个包含用户名列表的文件。

同时满足下列要求: 此脚本要求提供一个参数,此参数就是包含用户名列表的文件。如果没有提供参数,此脚本应该给出下面的提示信息Usage: /root/batusers userfile ,并且退出返回相应的值。如果提供一个不存在的文件名,此脚本应该给出下面的提示信息 Input file not found然后退出并返回相应的值。创建的用户登录shell为/bin/false。

此脚本不需要为用户设置密码 (注意:有得时候需要设置统一密码为redhat) 您可以从下面的URL获取用户列表作为测试用 http://classroom.example.com/materials/userlist

回答:

代码语言:javascript复制
server0:
[root@server0 ~]# pwd
/root
[root@server0 ~]# wget http://classroom.example.com/materials/userlist
[root@server0 ~]# touch /root/batchusers
[root@server0 ~]# chmod a x /root/batchusers
[root@server0 ~]# vim batchusers
[root@server0 ~]# cat batchusers
#!/bin/bash
if [ $# -eq 1 ]
then
      if [ -e $1 ]
         then
           for username in $(cat $1)
           do
              /usr/sbin/useradd -s /bin/false $username &> /dev/null
              /usr/bin/echo "redhat" | passwd --stdin $username &> /dev/null  
           done
           exit 0
         else
             echo "Input file not found"
             exit 1
        fi
else
        echo "Usage: /root/batusers userfile"
        exit 2
fi
[root@server0 ~]#

19、配置iSCSI服务端

配置server0提供一个iSCSI服务磁盘名为iqn.2014-11.com.example:server0,并符合下列要求:服务端口为3260。使用iscsi_store作为其后端卷,其大小为3G(题意含糊,其实iscsi_store是一个逻辑卷,需要自己建立。此服务只能被desktop0.example.com访问。

回答:

代码语言:javascript复制
[root@server0 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@server0 ~]# vgcreate vg1 /dev/sdb
  Volume group "vg1" successfully created
[root@server0 ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  vg1    1   0   0 wz--n- 10.00g 10.00g
[root@server0 ~]# 

[root@server0 ~]# lvcreate -n iscsi_store -L 3G vg1
  Logical volume "iscsi_store" created
[root@server0 ~]# 

安装:

[root@server0 ~]# yum -y install targetd targetcli

[root@server0 ~]# 
[root@server0 ~]# systemctl enable targetd
ln -s '/usr/lib/systemd/system/targetd.service' '/etc/systemd/system/multi-user.target.wants/targetd.service'
[root@server0 ~]# 

工具:targetcli

[root@server0 ~]# targetcli 
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: ]
  | o- fileio .................................................................... [Storage Objects: ]
  | o- pscsi ..................................................................... [Storage Objects: ]
  | o- ramdisk ................................................................... [Storage Objects: ]
  o- iscsi ............................................................................... [Targets: ]
  o- loopback ............................................................................ [Targets: ]
/> cd backstores/
/backstores> cd block 
/backstores/block> create dev=/dev/vg1/iscsi_store name=iscsi_store
Created block storage object iscsi_store using /dev/vg1/iscsi_store.
/backstores/block> cd ..
/backstores> ls
o- backstores ................................................................................... [...]
  o- block ....................................................................... [Storage Objects: ]
  | o- iscsi_store ............................. [/dev/vg1/iscsi_store (3.0GiB) write-thru deactivated]
  o- fileio ...................................................................... [Storage Objects: ]
  o- pscsi ....................................................................... [Storage Objects: ]
  o- ramdisk ..................................................................... [Storage Objects: ]
/backstores> cd ..
/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: ]
  | | o- iscsi_store ........................... [/dev/vg1/iscsi_store (3.0GiB) write-thru deactivated]
  | o- fileio .................................................................... [Storage Objects: ]
  | o- pscsi ..................................................................... [Storage Objects: ]
  | o- ramdisk ................................................................... [Storage Objects: ]
  o- iscsi ............................................................................... [Targets: ]
  o- loopback ............................................................................ [Targets: ]
/> cd iscsi 
/iscsi> ls
o- iscsi ................................................................................. [Targets: ]
/iscsi> create iqn.2014-11.com.example:server0
Created target iqn.2014-11.com.example:server0.
Created TPG 1.
/iscsi> ls
o- iscsi ................................................................................. [Targets: ]
  o- iqn.2014-11.com.example:server0 ........................................................ [TPGs: ]
    o- tpg1 .................................................................... [no-gen-acls, no-auth]
      o- acls ............................................................................... [ACLs: ]
      o- luns ............................................................................... [LUNs: ]
      o- portals ......................................................................... [Portals: ]
/iscsi> cd iqn.2014-11.com.example:server0/
/iscsi/iqn.20...ample:server0> ls
o- iqn.2014-11.com.example:server0 .......................................................... [TPGs: ]
  o- tpg1 ...................................................................... [no-gen-acls, no-auth]
    o- acls ................................................................................. [ACLs: ]
    o- luns ................................................................................. [LUNs: ]
    o- portals ........................................................................... [Portals: ]
/iscsi/iqn.20...ample:server0> cd tpg1/luns 
/iscsi/iqn.20...er0/tpg1/luns> create 
/backstores/block/iscsi_store   lun=                            
add_mapped_luns=                storage_object=                 
......................................storage_object|keyword=
/iscsi/iqn.20...er0/tpg1/luns> create /backstores/block/iscsi_store 
Created LUN 0.
/iscsi/iqn.20...er0/tpg1/luns> ls
o- luns ..................................................................................... [LUNs: ]
  o- lun0 .................................................. [block/iscsi_store (/dev/vg1/iscsi_store)]
/iscsi/iqn.20...er0/tpg1/luns> cd ..
/iscsi/iqn.20...:server0/tpg1> ls
o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  o- acls ................................................................................... [ACLs: ]
  o- luns ................................................................................... [LUNs: ]
  | o- lun0 ................................................ [block/iscsi_store (/dev/vg1/iscsi_store)]
  o- portals ............................................................................. [Portals: ]
/iscsi/iqn.20...:server0/tpg1> cd acls 
/iscsi/iqn.20...er0/tpg1/acls> ls
o- acls ..................................................................................... [ACLs: ]
/iscsi/iqn.20...er0/tpg1/acls> create iqn.1994-05.com.redhat:9e96ff23da37  ##在desktop服务器中initiatorname.iscsi 
Created Node ACL for iqn.1994-05.com.redhat:9e96ff23da37
Created mapped LUN 0.
/iscsi/iqn.20...er0/tpg1/acls> ls
o- acls ..................................................................................... [ACLs: ]
  o- iqn.1994-05.com.redhat:9e96ff23da37 ............................................. [Mapped LUNs: ]
    o- mapped_lun0 ...................................................... [lun0 block/iscsi_store (rw)]
/iscsi/iqn.20...er0/tpg1/acls> cd ..
/iscsi/iqn.20...:server0/tpg1> ls
o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  o- acls ................................................................................... [ACLs: ]
  | o- iqn.1994-05.com.redhat:9e96ff23da37 ........................................... [Mapped LUNs: ]
  |   o- mapped_lun0 .................................................... [lun0 block/iscsi_store (rw)]
  o- luns ................................................................................... [LUNs: ]
  | o- lun0 ................................................ [block/iscsi_store (/dev/vg1/iscsi_store)]
  o- portals ............................................................................. [Portals: ]
/iscsi/iqn.20...:server0/tpg1> cd portals 
/iscsi/iqn.20.../tpg1/portals> create ip_address=0.0.0.0 ip_port=
Using default IP port 
Binding to INADDR_ANY (0.0.0.0)
Created network portal 0.0.0.0:3260.
/iscsi/iqn.20.../tpg1/portals> cd ..
/iscsi/iqn.20...:server0/tpg1> ls
o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  o- acls ................................................................................... [ACLs: ]
  | o- iqn.1994-05.com.redhat:9e96ff23da37 ........................................... [Mapped LUNs: ]
  |   o- mapped_lun0 .................................................... [lun0 block/iscsi_store (rw)]
  o- luns ................................................................................... [LUNs: ]
  | o- lun0 ................................................ [block/iscsi_store (/dev/vg1/iscsi_store)]
  o- portals ............................................................................. [Portals: ]
    o- 0.0.0.0: .............................................................................. [OK]
/iscsi/iqn.20...:server0/tpg1> cd ..
/iscsi/iqn.20...ample:server0> ls
o- iqn.2014-11.com.example:server0 .......................................................... [TPGs: ]
  o- tpg1 ...................................................................... [no-gen-acls, no-auth]
    o- acls ................................................................................. [ACLs: ]
    | o- iqn.1994-05.com.redhat:9e96ff23da37 ......................................... [Mapped LUNs: ]
    |   o- mapped_lun0 .................................................. [lun0 block/iscsi_store (rw)]
    o- luns ................................................................................. [LUNs: ]
    | o- lun0 .............................................. [block/iscsi_store (/dev/vg1/iscsi_store)]
    o- portals ........................................................................... [Portals: ]
      o- 0.0.0.0: ............................................................................ [OK]
/iscsi/iqn.20...ample:server0> cd ..
/iscsi> ls
o- iscsi ................................................................................. [Targets: ]
  o- iqn.2014-11.com.example:server0 ........................................................ [TPGs: ]
    o- tpg1 .................................................................... [no-gen-acls, no-auth]
      o- acls ............................................................................... [ACLs: ]
      | o- iqn.1994-05.com.redhat:9e96ff23da37 ....................................... [Mapped LUNs: ]
      |   o- mapped_lun0 ................................................ [lun0 block/iscsi_store (rw)]
      o- luns ............................................................................... [LUNs: ]
      | o- lun0 ............................................ [block/iscsi_store (/dev/vg1/iscsi_store)]
      o- portals ......................................................................... [Portals: ]
        o- 0.0.0.0: .......................................................................... [OK]
/iscsi> cd ..
/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: ]
  | | o- iscsi_store ............................. [/dev/vg1/iscsi_store (3.0GiB) write-thru activated]
  | o- fileio .................................................................... [Storage Objects: ]
  | o- pscsi ..................................................................... [Storage Objects: ]
  | o- ramdisk ................................................................... [Storage Objects: ]
  o- iscsi ............................................................................... [Targets: ]
  | o- iqn.2014-11.com.example:server0 ...................................................... [TPGs: ]
  |   o- tpg1 .................................................................. [no-gen-acls, no-auth]
  |     o- acls ............................................................................. [ACLs: ]
  |     | o- iqn.1994-05.com.redhat:9e96ff23da37 ..................................... [Mapped LUNs: ]
  |     |   o- mapped_lun0 .............................................. [lun0 block/iscsi_store (rw)]
  |     o- luns ............................................................................. [LUNs: ]
  |     | o- lun0 .......................................... [block/iscsi_store (/dev/vg1/iscsi_store)]
  |     o- portals ....................................................................... [Portals: ]
  |       o- 0.0.0.0: ........................................................................ [OK]
  o- loopback ............................................................................ [Targets: ]
/> 

/> exit
Global pref auto_save_on_exit=true
Last  configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server0 ~]# 


[root@server0 ~]# systemctl start targetd
[root@server0 ~]# firewall-cmd --add-port=3260/tcp --permanent 
success
[root@server0 ~]# firewall-cmd --reload
success
[root@server0 ~]# 

20、配置iSCSI的客户端

配置desktop0使其能连接在server0上提供的iqn.2014-11.com.example:server0并符合以下要求:iSCSI设备在系统启动的时候自动加载块设备,iSCSI上包含一个大小为2100 MiB的分区,并格式化为ext4。此分区挂载在/mnt/data上同时在系统启动的期间自动挂载。

回答:

代码语言:javascript复制
[root@desktop0 iscsi]# yum list |grep iscsi
iscsi-initiator-utils.x86_64             6.2.0.873-21.el7              @rhel_dvd
iscsi-initiator-utils-iscsiuio.x86_64    6.2.0.873-21.el7              @rhel_dvd
libiscsi.x86_64                          1.9.0-6.el7                   @rhel_dvd
iscsi-initiator-utils.i686               6.2.0.873-21.el7              rhel_dvd 
libiscsi.i686                            1.9.0-6.el7                   rhel_dvd 
[root@desktop0 iscsi]# yum -y install iscsi-initiator-utils
Loaded plugins: langpacks
Package iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 already installed and latest version
Nothing to do
[root@desktop0 iscsi]# 


使用工具:iscsiadm
[root@desktop0 iscsi]# man iscsiadm
[root@desktop0 iscsi]# iscsiadm --mode discoverydb --type sendtargets --portal 172.25.0.11 --discover
172.25.0.11:, iqn.2014-11.com.example:server0
[root@desktop0 iscsi]# iscsiadm --mode node --targetname iqn.2014-11.com.example:server0 --portal 172.25.0.11:3260 --login
Logging in to [iface: default, target: iqn.2014-11.com.example:server0, portal: 172.25.0.11,] (multiple)
Login to [iface: default, target: iqn.2014-11.com.example:server0, portal: 172.25.0.11,] successful.
[root@desktop0 iscsi]# 


[root@desktop0 iscsi]# mkdir /mnt/data


[root@desktop0 iscsi]# fdisk /dev/sdc
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 0xa414c241.

Command (m for help): n
Partition type:
   p   primary ( primary,  extended,  free)
   e   extended
Select (default p): p
Partition number (1-4, default ): 
First sector (8192-6291455, default ): 
Using default value 
Last sector,  sectors or  size{K,M,G} (8192-6291455, default ):  M
Partition  of type Linux and of size 2.1 GiB is set

Command (m for help): p

Disk /dev/sdc:  MB,  bytes,  sectors
Units = sectors of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk label type: dos
Disk identifier: 0xa414c241

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1                           Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop0 iscsi]# 



[root@desktop0 iscsi]# mkfs.ext4  /dev/sdc1
mke2fs 1.42.9 (-Dec-2013)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
 inodes,  blocks
 blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
 block groups
 blocks per group,  fragments per group
 inodes per group
Superblock backups stored on blocks: 
    , , , , 

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done 

[root@desktop0 iscsi]# blkid
/dev/sda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/sdc1: UUID="d470fb03-aaf4-4672-bb02-80e4f48ee764" TYPE="ext4" 
[root@desktop0 iscsi]# 
[root@desktop0 iscsi]# 
[root@desktop0 iscsi]# 
[root@desktop0 iscsi]# 
[root@desktop0 iscsi]# vim /etc/fstab
[root@desktop0 iscsi]# cat /etc/fstab 
UUID=bf6b9f7-92ad-441b-848e-0257cbb883d1 /               xfs     defaults         
//172.25.0.11/common   /mnt/multiuser  cifs  defaults,username=brian,password=redhat,sec=ntlmssp,multiuser,_netdev       
172.25.0.11:/public  /mnt/nfsmount    nfs  defaults,_netdev         
172.25.0.11:/protected  /mnt/nfssecure   nfs   defaults,sec=krb5p,_netdev      
UUID=d470fb03-aaf4-4672-bb02-80e4f48ee764  /mnt/data  ext4  defaults,_netdev     
[root@desktop0 iscsi]# 

[root@desktop0 iscsi]# mount -a

[root@desktop0 iscsi]# systemctl enable iscsi
ln -s '/usr/lib/systemd/system/iscsi.service' '/etc/systemd/system/sysinit.target.wants/iscsi.service'
[root@desktop0 iscsi]# systemctl enable iscsid
ln -s '/usr/lib/systemd/system/iscsid.service' '/etc/systemd/system/multi-user.target.wants/iscsid.service'
[root@desktop0 iscsi]# 

21、部署MariaDB数据库

在server0上部署MariaDB。要求如下:仅允许从server0系统上使用登陆到数据库。

登陆数据库所用的账号为root,密码为root_password。从http://content.example.com/courses/rhce/rhel7.0/materials/mariadb/mariadb.dump上下载文件,并将其恢复为legacy库。并设置数据库访问:

用户名 密码

权限

mary xxx

对legacy库的所有数据有选择操作权限

legacy xxx

对legacy库的所有数据有选择、插入、更新、删除操作权限

report xxx

对legacy库的所有数据有选择操作权限

注意:权限错了要会 revoke

回答:

代码语言:javascript复制
[root@server0 Desktop]# yum -y install mariadb mariadb-server
[root@server0 Desktop]# systemctl enable mariadb
[root@server0 Desktop]# systemctl start mariadb
[root@server0 Desktop]# mysql_secure_installation 
/usr/bin/mysql_secure_installation: line : find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):   #####设置root 密码为root_password
y.....y   (全选y)

[root@server0 ~]# pwd
/root
[root@server0 ~]# wget http://content.example.com/courses/rhce/rhel7.0/materials/mariadb/mariadb.dump
[root@server0 Desktop]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.

MariaDB [(none)]> create database legacy;
Query OK,  row affected (0.00 sec)

MariaDB [(none)]> use legacy;
Database changed
MariaDB [legacy]> source /root/mariadb.dump
Query OK,  rows affected (0.01 sec)

MariaDB [legacy]> grant select on legacy.* to mary@'localhost' identified by 'redhat';
Query OK,  rows affected (0.00 sec)

MariaDB [legacy]> grant select,update,delete,insert on legacy.* to legacy@'localhost' identified by 'redhat';
Query OK,  rows affected (0.00 sec)

MariaDB [legacy]> grant select on legacy.* to report@'localhost' identified by 'redhat';
Query OK,  rows affected (0.00 sec)

MariaDB [legacy]> flush privileges;
Query OK,  rows affected (0.00 sec)

22、数据查询填空

在server0上登陆数据库,查看XXX库进行查询,并将结果填入相应的框格中。

Q1在product表中,查询RT-AC68U的产品id() Q2查询类别为Servers的产品的数量()

模拟考环境请在 http://classroom.example.com/cgi-bin/mariadb 提交

代码语言:javascript复制
MariaDB [legacy]> desc product;
 ----------------- -------------- ------ ----- --------- ---------------- 
| Field           | Type         | Null | Key | Default | Extra          |
 ----------------- -------------- ------ ----- --------- ---------------- 
| id              | int(11)      | NO   | PRI | NULL    | auto_increment |
| name            | varchar() | NO   |     | NULL    |                |
| price           | double       | NO   |     | NULL    |                |
| stock           | int()      | NO   |     | NULL    |                |
| id_category     | int(11)      | NO   |     | NULL    |                |
| id_manufacturer | int()      | NO   |     | NULL    |                |
 ----------------- -------------- ------ ----- --------- ---------------- 
6 rows in set (0.00 sec)
MariaDB [legacy]> select * from product;
 ---- ------------------- --------- ------- ------------- ----------------- 
| id | name              | price   | stock | id_category | id_manufacturer |
 ---- ------------------- --------- ------- ------------- ----------------- 
|  1 | ThinkServer TS14 |  539.88 |     |           2 |                |
|   | ThinkServer RD630 | 2379.14 |    20 |            |               4 |
|  3 | RT-AC68U          |  219.99 |     |           1 |                |
|   | X110 64GB         |   73.84 |   100 |            |               1 |
 ---- ------------------- --------- ------- ------------- ----------------- 
 rows in set (. sec)
MariaDB [legacy]> select id from product where name='RT-AC68U';
 ---- 
| id |
 ---- 
|  3 |
 ---- 
 row in set (. sec)
MariaDB [legacy]>
[root@server0 Desktop]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 
Server version: 5.5.-MariaDB MariaDB Server
Copyright (c) , , Oracle, Monty Program Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> use legacy;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [legacy]> select * from category;
 ---- ------------ 
| id | name       |
 ---- ------------ 
|   | Networking |
|  2 | Servers    |
|   | Ssd        |
 ---- ------------ 
 rows in set (. sec)
MariaDB [legacy]> select * from category where name='Servers';
 ---- --------- 
| id | name    |
 ---- --------- 
|   | Servers |
 ---- --------- 
 row in set (. sec)
MariaDB [legacy]> select * from product where id_category=;
 ---- ------------------- --------- ------- ------------- ----------------- 
| id | name              | price   | stock | id_category | id_manufacturer |
 ---- ------------------- --------- ------- ------------- ----------------- 
|   | ThinkServer TS140 |  539.88 |    20 |            |               4 |
|  2 | ThinkServer RD63 | 2379.14 |     |           2 |                |
 ---- ------------------- --------- ------- ------------- ----------------- 
2 rows in set (0.00 sec)
MariaDB [legacy]>

Answer1: 在product表中,查询RT-AC68U的产品id ( 为3)
Answer2: 查询类别为Servers的产品的数量   (  为 20 )

0 人点赞