UOS UCP 考试题

1 环境准备

1.1 防火墙

请关闭防火墙并禁用开机自启。

systemctl stop firewalld
systemctl disable firewalld

如果想要开放某些端口可以查看 LInux 防火墙管理 firewall-cmd

1.2 更改主机名

考试环境的主机名为随机UUID ,请临时改为 server1server2
第一台机器:

hostname server1

第二台机器:

hostname server2

1.3 配置hosts

第一台机器:

cat >> /etc/hosts << EOF
192.168.10.175 server1
192.168.10.176 server2
EOF

第二台机器:

cat >> /etc/hosts << EOF
192.168.10.175 server1
192.168.10.176 server2
EOF

2 第1题 : (6分)

2.1 题目要求

SSH
按照以下要求配置ssh服务:

2.2 server1 配置 SSH 信任

1、在SSH客户端生成用户的公钥和私钥对文件

ssh-keygen -t rsa

2、将SSH客户的公钥添加到SSH服务器中用户的认证文件中

ls -1 ~/.ssh
ssh-copy-id -i ~/.ssh/id_rsa.pub server1
ssh-copy-id -i ~/.ssh/id_rsa.pub server2
1.  (yes/no/[fingerprint])? yes //输入yes 。
2. root@server2's password:  //输入密码。

3、不需密码或仅需私钥密码就表示密钥认证成功

ssh -l root server2

2.3 server2 配置 SSH 信任

1、在SSH客户端生成用户的公钥和私钥对文件。

ssh-keygen -t rsa

2、将SSH客户的公钥添加到SSH服务器中用户的认证文件中。

ls -1 ~/.ssh/
ssh-copy-id -i ~/.ssh/id_rsa.pub server2
ssh-copy-id -i ~/.ssh/id_rsa.pub server1
1.  (yes/no/[fingerprint])? yes //输入yes 。
2. root@server2's password:  //输入密码。

3、不需密码或仅需私钥密码就表示密钥认证成功。

ssh -l root server1 

更多配置SSH 免密请见 Linux SSH 配置节点互信

3 第2题 : (6分)

3.1 题目要求

Http虚拟主机
server1上使用Http配置基于端口的web虚拟主机,并实现下列要求

3.2 安装 httpd

dnf install httpd -y

3.3 配置虚拟主机

1、准备目录和文件

mkdir /var/www/html/port 
vi /var/www/html/port/index.html
This is Server1 

2、配置基于端口号的虚拟主机。

vi /etc/httpd/conf/httpd.conf

将以下内容添加文件末尾。

Listen 8899
<VirtualHost *:8899>
        DocumentRoot /var/www/html/port
</VirtualHost>
<Directory /var/www/html/port>
        <Requireall>
        Require all granted
        </Requireall>
</Directory> 

3.4 启动并开机自启HTTP 服务

systemctl start httpd
systemctl enable httpd

3.5 配置HOSTS 文件

vim /etc/hosts
192.168.10.175 server1 server1.uosexam.com

3.6 验证HTTP 服务

curl -l http://server1.uosexam.com:8899
This is Server1

更多信息请见 Linux Apache

4 第3题 : (6分)

4.1 题目要求

Http访问控制
server1 上使用 Http 配置基于域名的 web 虚拟主机,并实现下列要求:

4.2 配置DNS 服务

更多说明请参考 Linux DNS 文章。

4.2.1 安装DNS软件

dnf install bind bind-utils  -y

4.2.2 域名服务器配置

  1. 编辑 named.conf。修改下面示例的两行即可。
vi  /etc/named.conf  
options {
        listen-on port 53 { 192.168.10.175; };
        ... ... ... 
        allow-query     { any; };
		... ... ... 

4.2.3 配置DNS 域

  1. 编辑 named.conf
vi  /etc/named.conf  
  1. 填写需要解析的域。
zone "uosexam.com" IN {
        type master;
        file "uosexam.com.db";
};

4.2.4 配置解析文件uosexam.com.db

vi /var/named/uosexam.com.db
$TTL 1D
@       IN SOA  ns.uosexam.com. root.ns.uosexam.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.uosexam.com.
ns      A       192.168.10.175
www     A       192.168.10.175

4.2.5 修改解析文件权限

chown named:named /var/named/uosexam.com.db

4.2.6 启动DNS 服务器

systemctl start named
systemctl enable named

4.2.7 测试DNS 有效性

1、配置DNS 服务。

vi /etc/resolv.conf 
nameserver 192.168.10.175

2、测试DNS 是否有效。

nestloop www.uosexam.com server1
ping www.uosexam.com 

4.3 准备目录和文件

mkdir -p /uos/
vi /uos/index.html
This is Server1

4.4 配置虚拟主机

vi /etc/httpd/conf/httpd.conf
Alias /net "/uos"
<Directory "/uos">
    Options Indexes FollowSymLinks
    AllowOverride all
    <Requireall>
    Require all granted
    Require not ip 192.168.10.175
    </Requireall>
</Directory>
<VirtualHost 192.168.10.175:80>
        ServerName www.uosexam.com
        DocumentRoot /var/www/virsh
</VirtualHost>

4.5 重启HTTP 服务

systemctl restart httpd

4.6 验证HTTP 服务

server1

curl http://www.uosexam.com/net/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
</body></html>

server2

curl http://www.uosexam.com/net/
This is Server1

5 第4题 :(6分)

Nginx 虚拟主机在 server2 上使用 Nginx 配置基于端口的web虚拟主机,并实现下列要求

5.1 配置DNS 解析

Warning

配置DNS 需要在 Server1 上执行。

5.1.1 配置解析文件uosexam.com.db

vi /var/named/uosexam.com.db
$TTL 1D
@       IN SOA  ns.uosexam.com. root.ns.uosexam.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.uosexam.com.
ns      A       192.168.10.175
www     A       192.168.10.175
server2 A       192.168.10.176 

5.1.2 启动DNS 服务器

systemctl restart named

5.1.3 测试DNS 有效性

ping server2.uosexam.com

5.1.4 配置互联网DNS

Warning

这里需要先配置DNS ,否则无法下载nginx 安装包。

vi /etc/resolv.conf
nameserver 192.168.10.1

5.2 安装Nginx

2、安装Nginx 并开机自启。

dnf install nginx -y
systemctl start nginx 
systemctl enable nginx

5.3 准备目录和文件

mkdir -p /usr/share/nginx/html/port
echo "This is Server2" > /usr/share/nginx/html/port/index.html

5.4 配置Nginx 虚拟主机

需要修改以下内容。

vi /etc/nginx/nginx.conf
 server {
        listen 8899;
        .....
        server_name  server2.uosexam.com;
        root         /usr/share/nginx/html/port;
        ...........

5.5 重启Nginx 服务

systemctl restart nginx 

5.6 验证Nginx 服务

curl http://server2.uosexam.com:8899
This is Server2

6 第5题 : (6分)

安全Nginx主机

6.1 生成证书文件

mkdir -p /etc/pki/nginx/private
openssl req -new -x509 -days 365 -nodes -out /etc/pki/nginx/server.crt -keyout /etc/pki/nginx/private/server.key -subj "/C=CN/ST=China/L=Beijing/O=uosexam.com/OU=uosexam.com/CN=server2.uosexam.com"

6.2 生成受信任的证书

cd ~
openssl x509 -in /etc/pki/nginx/server.crt -out server.pem

本机信任此证书。

 cat server.pem >> /etc/pki/tls/certs/ca-bundle.crt 

6.3 配置SSL 类型的虚拟主机

打开SSL 类型的虚拟机配置,修改以下内容。

vi  /etc/nginx/nginx.conf
    server {
        listen       443 ssl http2 default_server;
        ... ... ... 
        server_name  server2.uosexam.com;
        root         /usr/share/nginx/html/port;
        ... ... ... 

6.4 重启Nginx 服务

systemctl restart nginx 

6.5 验证Nginx 服务

通过 curl 命令可以看到返回值为 200

 curl -i https://server2.uosexam.com
HTTP/2 200 
server: nginx/1.14.1
date: Wed, 15 Nov 2023 07:58:59 GMT
content-type: text/html
content-length: 3510
last-modified: Sat, 01 Apr 2023 15:16:39 GMT
etag: "64284ad7-db6"
accept-ranges: bytes
... ... ... 

7 第6题 :(6分)

7.1 题目要求

FTP
在server1上创建FTP服务并按照下列要求进行配置

7.2 Server1 配置DNS 互联网

Warning

这里需要先配置DNS ,否则无法下载FTP 安装包。

vi /etc/resolv.conf
nameserver 192.168.10.1

7.3 Server1 准备目录和文件

mkdir -p /var/ftp/dir
chown -R ftp:ftp /var/ftp/dir

7.4 Server1 安装FTP

dnf install vsftpd -y

7.5 Server1 配置FTP 匿名用户上传

vi /etc/vsftpd/vsftpd.conf 
anonymous_enable=YES
anon_upload_enable=YES
write_enable=YES
anon_mkdir_write_enable=YES
anon_umask=022

7.6 Server1 启动ftp 服务

systemctl start vsftpd

7.7 Server2 客户端验证

  1. server2 上安装ftp 客户端。
dnf install ftp
  1. 登录FTP 服务器。
ftp server1
Connected to server1 (192.168.10.175).
220 (vsFTPd 3.0.3)
Name (server1:root): ftp   //输入匿名用户名ftp 
331 Please specify the password.
Password: //这里直接回车,匿名用户没有密码。
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
  1. 切换目录并上传文件。
ftp> cd ../dir
ftp> put anaconda-ks.cfg
  1. sever1 更改权限
chmod +r anaconda-ks.cfg
  1. 下载文件。
ftp> cd ../dir
ftp> get anaconda-ks.cfg

8 第7题 : (6分)

FTP登陆限制
server1上,安装vsFTP,并对用户登陆限制,使用chroot_list方式

8.1 创建FTP 用户并设置密码。

useradd xiyou
useradd shuihu
echo 'uos1_2.3'| passwd --stdin shuihu
echo 'uos1_2.3'| passwd --stdin shuihu

8.2 配置FTP 服务

local_enable=YES
local_umask=022
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot

8.3 配置 chroot_list 文件

vi /etc/vsftpd/chroot_list
shuihu

8.4 重启FTP 服务

 systemctl restart vsftpd

8.5 验证FTP

  1. shuihu 能够切换到上层目录。
[root@server2 ~]# ftp server1
Connected to server1 (192.168.10.175).
220 (vsFTPd 3.0.3)
Name (server1:root): shuihu
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd ..
250 Directory successfully changed.
ftp> pwd
257 "/home" is the current directory
ftp> exit
221 Goodbye.
  1. xiyou 不能切换到上层目录
[root@server2 ~]# ftp server1
Connected to server1 (192.168.10.175).
220 (vsFTPd 3.0.3)
Name (server1:root): xiyou
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/" is the current directory
ftp> cd ../
250 Directory successfully changed.
ftp> pwd
257 "/" is the current directory
ftp> 

更多详情请见 Linux FTP

9 第8题 : (8分)

ISCSI
在server2上配置iscsi服务,并满足下列要求:

9.1

9.2 安装 targetcli 安装包

dnf install targetcli -y
systemctl start target
systemctl enable target

9.3 服务端配置 ISCSI 存储

9.3.1 对磁盘分区

请手动添加磁盘后,进行格式化和分区。

[root@server2 ~]# fdisk /dev/sdb 

欢迎使用 fdisk (util-linux 2.35.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

设备不包含可识别的分区表。
创建了一个磁盘标识符为 0x9fc35768 的新 DOS 磁盘标签。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (0 primary, 0 extended, 4 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):p
分区号 (1-4, 默认  1): 
第一个扇区 (2048-33554431, 默认 2048): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (2048-33554431, 默认 33554431): +5G

创建了一个新分区 1,类型为“Linux”,大小为 5 GiB。

命令(输入 m 获取帮助):p
Disk /dev/sdb:16 GiB,17179869184 字节,33554432 个扇区
磁盘型号:Virtual disk    
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x9fc35768

设备       启动  起点     末尾     扇区 大小 Id 类型
/dev/sdb1        2048 10487807 10485760   5G 83 Linux

命令(输入 m 获取帮助):w
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

Linux 磁盘管理 文件系统配置

9.3.2 创建存储磁盘

targetcli
/> /backstores/block create uos_disk /dev/sdb1 
Created block storage object uos_disk using /dev/sdb1.

9.3.3 创建 iSCSI 路径

/> /iscsi  create iqn.2020-06.com.uosexam:server
Created target iqn.2020-06.com.uosexam:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

9.3.4 配置iSCSI 访问规则

/> /iscsi/iqn.2020-06.com.uosexam:server/tpg1/acls create iqn.2020-06.com.uosexam::client1 
Created Node ACL for iqn.2020-06.com.uosexam::client1

9.3.5 关联iSCSI存储和iSCSI LUN

/> /iscsi/iqn.2020-06.com.uosexam:server/tpg1/luns create /backstores/block/uos_disk 

Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-06.com.uosexam::client1

9.3.6 保存配置

saveconfig
exit

9.3.7 查看 ISCSI 存储配置

targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- uos_disk ........................................................................ [/dev/sdb1 (5.0GiB) write-thru activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2020-06.com.uosexam:server .................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2020-06.com.uosexam::client1 ..................................................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 .............................................................................. [lun0 block/uos_disk (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................. [block/uos_disk (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]

10 第9题 : (8分)

挂载iscsi
server1上挂载server2提供的iscsi存储,并满足下列要求:
* iscsi设备在系统重启后能自动加载

10.1 安装客户端

dnf install iscsi-initiator-utils -y

10.2 配置客户端文件

vi /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2020-06.com.uosexam::client1

10.3 发现iscsi 存储

iscsiadm --mode discoverydb --type sendtargets --portal server2 --discover
192.168.10.176:3260,1 iqn.2020-06.com.uosexam:server

10.4 登录存储服务器

iscsiadm -m node -T iqn.2020-06.com.uosexam:server server2:3260 -l
Logging in to [iface: default, target: iqn.2020-06.com.uosexam:server, portal: 192.168.10.176,3260]
Login to [iface: default, target: iqn.2020-06.com.uosexam:server, portal: 192.168.10.176,3260] successful.

10.5 对磁盘分区

fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.35.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

设备不包含可识别的分区表。
创建了一个磁盘标识符为 0x662b66eb 的新 DOS 磁盘标签。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (0 primary, 0 extended, 4 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):p
分区号 (1-4, 默认  1): 
第一个扇区 (65528-10485759, 默认 65528): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (65528-10485759, 默认 10485759): +2G

创建了一个新分区 1,类型为“Linux”,大小为 2 GiB。

命令(输入 m 获取帮助):p
Disk /dev/sdb:5 GiB,5368709120 字节,10485760 个扇区
磁盘型号:uos_disk        
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 33550336 字节
磁盘标签类型:dos
磁盘标识符:0x662b66eb

设备       启动  起点    末尾    扇区 大小 Id 类型
/dev/sdb1       65528 4259319 4193792   2G 83 Linux

命令(输入 m 获取帮助):w
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

10.6 制作文件系统

mkfs.ext4 /dev/sdb1

10.7 查看UUID

blkid /dev/sdb1
/dev/sdb1: UUID="a9b7157d-580d-438d-962a-fbfe38fda7da" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="662b66eb-01"

10.8 永久挂载

mkdir -p /mnt/iscsi
vi /etc/fstab
UUID="a9b7157d-580d-438d-962a-fbfe38fda7da"  /mnt/iscsi ext4   defaults        0 0 

10.9 挂载磁盘

mount -a
df -h
Warning

这里需要使用 mount -a 挂载磁盘用于验证 /etc/fstab 文件无错误。如果编写错误有可能造成操作系统无法启动。

11 第10题 :(6分)

数据库MariaDB
server1上创建mariadb数据库,并实现下列要求

11.1 安装 MariaDB

dnf install mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb.service

11.2 设置root密码

mysql_secure_installation
Enter current password for root (enter for none):直接回车
Set root password? [Y/n] 回车
New password: 输入txuos,回车
Re-enter new password:   输入txuos
Remove anonymous users? [Y/n] y 回车
Disallow root login remotely? [Y/n] n 回车
Remove test database and access to it? [Y/n] y  回车
Reload privilege tables now? [Y/n] y 回车

11.3 导入数据

11.3.1 创建 scott 数据库

CREATE DATABASE scott;
USE scott;

11.3.2 导入 scott.sql


-- MySQL equivalent of Oracle SCOTT default schema.
-- (datatypes are different but should generally be equivalent)
--
-- Oracle database installations reportedly have included a default
-- schema called SCOTT, accessed by user "scott" with password "tiger".
-- Wikipedia reports the SCOTT schema originated with Bruce Scott, one
-- of the first employees at Oracle (then Software Development
-- Laboratories), who had a cat named Tiger.
--
-- (1) Wikipedia contributors, "Oracle Database," Wikipedia, The Free
-- Encyclopedia, http://en.wikipedia.org/w/index.php?title=Oracle_Database&oldid=416894489
-- (accessed 2013/01/08).
--

-- phpMyAdmin SQL Dump
-- version 3.5.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 08, 2013 at 11:02 PM
-- Server version: 5.5.25a
-- PHP Version: 5.4.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `scott`
--

-- --------------------------------------------------------

--
-- Table structure for table `bonus`
--

CREATE TABLE IF NOT EXISTS `bonus` (
  `ENAME` varchar(10) DEFAULT NULL,
  `JOB` varchar(9) DEFAULT NULL,
  `SAL` int(11) DEFAULT NULL,
  `COMM` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `dept`
--

CREATE TABLE IF NOT EXISTS `dept` (
  `DEPTNO` int(11) DEFAULT NULL,
  `DNAME` varchar(14) DEFAULT NULL,
  `LOC` varchar(13) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `dept`
--

INSERT INTO `dept` (`DEPTNO`, `DNAME`, `LOC`) VALUES
(10, 'ACCOUNTING', 'NEW YORK'),
(20, 'RESEARCH', 'DALLAS'),
(30, 'SALES', 'CHICAGO'),
(40, 'OPERATIONS', 'BOSTON');

-- --------------------------------------------------------

--
-- Table structure for table `dummy`
--

CREATE TABLE IF NOT EXISTS `dummy` (
  `DUMMY` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `dummy`
--

INSERT INTO `dummy` (`DUMMY`) VALUES
(0);

-- --------------------------------------------------------

--
-- Table structure for table `emp`
--

CREATE TABLE IF NOT EXISTS `emp` (
  `EMPNO` int(11) NOT NULL,
  `ENAME` varchar(10) DEFAULT NULL,
  `JOB` varchar(9) DEFAULT NULL,
  `MGR` int(11) DEFAULT NULL,
  `HIREDATE` date DEFAULT NULL,
  `SAL` int(11) DEFAULT NULL,
  `COMM` int(11) DEFAULT NULL,
  `DEPTNO` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `emp`
--

INSERT INTO `emp` (`EMPNO`, `ENAME`, `JOB`, `MGR`, `HIREDATE`, `SAL`, `COMM`, `DEPTNO`) VALUES
(7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '1981-02-20', 1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, '1981-02-22', 1250, 500, 30),
(7566, 'JONES', 'MANAGER', 7839, '1981-04-02', 2975, NULL, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, '1981-09-28', 1250, 1400, 30),
(7698, 'BLAKE', 'MANAGER', 7839, '1981-05-01', 2850, NULL, 30),
(7782, 'CLARK', 'MANAGER', 7839, '1981-06-09', 2450, NULL, 10),
(7788, 'SCOTT', 'ANALYST', 7566, '1982-12-09', 3000, NULL, 20),
(7839, 'KING', 'PRESIDENT', NULL, '1981-11-17', 5000, NULL, 10),
(7844, 'TURNER', 'SALESMAN', 7698, '1980-09-08', 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, '1983-01-12', 1100, NULL, 20),
(7900, 'JAMES', 'CLERK', 7698, '1981-12-03', 950, NULL, 30),
(7902, 'FORD', 'ANALYST', 7566, '1981-12-03', 3000, NULL, 20),
(7934, 'MILLER', 'CLERK', 7782, '1982-01-23', 1300, NULL, 10);

-- --------------------------------------------------------

--
-- Table structure for table `salgrade`
--

CREATE TABLE IF NOT EXISTS `salgrade` (
  `GRADE` int(11) DEFAULT NULL,
  `LOSAL` int(11) DEFAULT NULL,
  `HISAL` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `salgrade`
--

INSERT INTO `salgrade` (`GRADE`, `LOSAL`, `HISAL`) VALUES
(1, 700, 1200),
(2, 1201, 1400),
(3, 1401, 2000),
(4, 2001, 3000),
(5, 3001, 9999);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

11.4 创建 deepin 用户

mysql -u root 
GRANT ALL PRIVILEGES on scott.* to 'deepin'@'%' identified by 'txuos';

11.5 验证符合题意

[root@server1 mariadb]# mysql -u deepin -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.3.35-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| scott              |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> 

12 第11题 :(6分)

数据库内容查找
按照下列要求查询数据:

12.1 登录数据库并导出数据

mysql -u root -p
use scott;
SELECT ENAME FROM emp 
WHERE deptno=30 AND sal>2000
INTO OUTFILE '/var/lib/mysql/exam.txt';

12.2 排错思路

如果写入失败,请检查secure_file_priv参数配置:

show global variables like '%secure_file_priv%';

secure_file_priv为 NULL 时,表示不允许导入或导出。
secure_file_priv为路径时(如/var/lib/mysql-files/),表示只允许在此路径目录中执行。
secure_file_priv没有值时,表示可在任意目录的导入导出。

13 第12题 : (6分)

编写脚本
在server1中创建/root/filing.sh的脚本,要求使用case完成以下功能:

13.1 编写SHELL 脚本

#!/bin/bash
if [ $# -eq 1 ];then
        if [ $1 == "gzip"  ];then
	        mkdir -p /backups
            tar -zcvf /backups/etc-2020.tar.gz /etc
        elif [ $1 == "bzip2" ]; then
            mkdir -p /backups
            tar -jcvf /backups/etc-2020.tar.bz2 /etc
        elif [ $1 == "xz" ]; then
	        mkdir -p /backups
            tar -Jcvf /backups/etc-2020.tar.xz /etc
        else
        echo "ERROR!!!,Please INPUT Use:gzip|bzip2|xz."
        exit 100
        fi
else 
        echo "ERROR!!!,Please INPUT 1 Argument."
        exit 100
fi
#!/bin/bash
if [ $# -ne 1 ];then
        echo "ERROR!!!,Please INPUT 1 Argument."
        exit 3
else 
        case $1 in
         "gzip")
                 mkdir -p /backups
                 tar -zvcf /backups/etc-2020.tar.gz /etc
                 exit 0
                 ;;
         "bzip2")
                 mkdir -p /backups
                 tar -cvjf /backups/etc-2020.tar.bz2 /etc
                 exit 1
                 ;;
         "xz")
                 mkdir -p /backups
                 tar -cvJf /backups/etc-2020.tar.gz /etc
                 exit 2
                 ;;
          *)
                 echo "ERROR!!!,Please INPUT Use:gzip|bzip2|xz."
                 exit 3
                 ;;
        esac
fi

更多脚本请参考 Linux Shell 输入内容进行格式化

14 第13题 :(8分)

docker映射web服务
server1上面搭建docker服务,满足下列要求

14.1 安装Docker Engine

14.1.1 安装依赖包

dnf install docker -y

14.1.2 启动 Docker 并开机自启

systemctl start podman
 systemctl enable podman
Warning

注意这里使用了podman-docker 。

14.2 导入 Nginx

可以通过网络下载镜像。

docker pull nginx

考试请使用导入进行命令。

docker load -i ginx.tar 

14.3 运行Nginx 服务

mkdir -p /usr/nginx/html

echo "I'm UOS" > /usr/nginx/html/index.html

docker run --name nginx -d -p 8888:80 -v /usr/nginx/html:/usr/share/nginx/html --restart=always nginx:latest

14.4 验证 Nginx 服务

curl http://server1:8888
I'm UOS

15 第14题 :(8分)

docker部署mysql服务
在server1上面搭建docker服务,满足下列要求

15.1 答题过程

docker pull mysql:5.6
docker images
mkdir /usr/mysql
docker run --name mysqlexam -d -p 33060:3306 -e MYSQL_ROOT_PASSWORD=uos  -v /usr/mysql:/var/lib/mysql mysql:5.6 
docker exec -it mysqlexam /bin/bash
mysql -uroot -p
输入密码:uos
create database uos;
exit
exit

16 第15题 :(8分)

使用Ansible安装软件
编写一个playbook名称为/root/yum.yml、满足下列要求:

16.1 安装 ansible

dnf install -y ansible

16.2 配置server1和server2免密登录

vim /etc/ansible/hosts

加入如下内容

[web]
server1

[db]
server2
ansible all -m ping
vim /root/yum.yml
---
- hosts: web
  user: root
  tasks:
    - name: install php-fpm
      yum:
          name: php-fpm
          state: present
    - name: start php-fpm
      service:
        name: php-fpm
        state: started
        enabled: yes
    - name: install samba
      yum:
          name: samba*
          state: present
    - name: start samba
      service:
        name: smb
        state: started
        enabled: yes
- hosts: db
  user: root
  tasks:
    - name: install mariadb-server
      yum:
          name: mariadb-server
          state: present
    - name: start mariadb-server
      service:
        name: mariadb
        state: started
        enabled: yes

16.3 验证题目要求

ansible-playbook --syntax-check yum.yml
ansible-playbook yum.yml -e "ansible_python_interpreter=/usr/bin/python3"
[root@server1 ~]# ansible-playbook --syntax-check yum.yml

playbook: yum.yml
[root@server1 ~]# ansible-playbook yum.yml -e "ansible_python_interpreter=/usr/bin/python3"

PLAY [web] *****************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [server1]

TASK [install php-fpm] *****************************************************************************************************************
changed: [server1]

TASK [start php-fpm] *******************************************************************************************************************
changed: [server1]

TASK [install samba] *******************************************************************************************************************
changed: [server1]

TASK [start samba] *********************************************************************************************************************
changed: [server1]

PLAY [db] ******************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************
ok: [server2]

TASK [install mariadb-server] **********************************************************************************************************
changed: [server2]

TASK [start mariadb-server] ************************************************************************************************************
changed: [server2]

PLAY RECAP *****************************************************************************************************************************
server1                    : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
server2                    : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0