linux练习题(9,10,11章)

linux作业

1、设置权限,要求如下:

(1)创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt

[root@localhost ~]# groupadd g1
[root@localhost ~]# useradd redhat
[root@localhost ~]# mkdir redhat
[root@localhost ~]# cd redhat
[root@localhost redhat]# touch redhat.txt
[root@localhost redhat]# chown redhat redhat.txt
[root@localhost redhat]# chown :g1 redhat.txt
[root@localhost redhat]# ll
total 0
-rw-r--r--. 1 redhat g1 0 Oct 31 23:07 redhat.txt
[root@localhost redhat]# 

(2)新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权限

[root@localhost ~]# mkdir /sc
[root@localhost ~]# chown root:group /sc
[root@localhost redhat]# chmod -R 770 /sc

(3)新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup组中

[root@localhost ~]# useradd caiwurenyuan
[root@localhost ~]# mkdir /cw
[root@localhost ~]# chown -R :mygroup /cw
[root@localhost ~]# chmod -R 770 /cw

(4)设置 helen用户对于/sc和/cw目录可以读,写,执行

[root@localhost ~]# chown -R helen /sc
[root@localhost ~]# chown -R helen /cw
[root@localhost ~]# chmod -R 770 /sc
[root@localhost ~]# chmod -R 770 /sc

(5)设置/test目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件(t权限)

[root@localhost ~]# chmod -R o+t /test

(6)在/test/dir里创建的新文件自动属于temp组

[root@localhost ~]# mkdir /test/dir
[root@localhost ~]# chown :temp /test/dir
[root@localhost ~]# chmod g+s /test/dir
​

2、配置网络

(1)为网卡添加一个会话static,在此会话配置ip地址为x.x.x.123

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.72.2    0.0.0.0         UG    100    0        0 ens160
192.168.72.0    0.0.0.0         255.255.255.0   U     100    0        0 ens160
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.161.0   0.0.0.0         255.255.255.0   U     101    0        0 ens224
[root@localhost ~]# nmcli c add type ethernet con-name static ifname ens160 ipv4.addresses '192.168.72.123/24' ipv4.gateway 192.168.72.2 ipv4.dns '8.8.8.8,4.4.4.4' ipv4.method manual autoconnect yes
Connection 'static' (6608c0be-b797-44e2-b3f3-028b87f11c9c) successfully added.
[root@localhost ~]# nmcli c up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.72.123
PREFIX=24
GATEWAY=192.168.72.2
DNS1=8.8.8.8
DNS2=4.4.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=6608c0be-b797-44e2-b3f3-028b87f11c9c
DEVICE=ens160
ONBOOT=yes

(2)测试网络连通性,看是否能够ping通百度,并把百度首页文件下载下来

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=7.32 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=8.59 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=7.78 ms
[root@localhost ~]# mkdir baidu
[root@localhost ~]# wget -P baidu www.baidu.com
--2022-11-01 21:46:10--  http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 14.215.177.39, 14.215.177.38
Connecting to www.baidu.com (www.baidu.com)|14.215.177.39|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘baidu/index.html’
​
index.html                   100%[=============================================>]   2.33K  --.-KB/s    in 0s      
​
2022-11-01 21:46:10 (326 MB/s) - ‘baidu/index.html’ saved [2381/2381]
​
[root@localhost ~]# ll baidu
total 4
-rw-r--r--. 1 root root 2381 Nov  1 21:46 index.html
[root@localhost ~]# 
​

(3)设置系统开机时,该网卡通过DHCP协议自动获取IP地址

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.72.123
PREFIX=24
GATEWAY=192.168.72.2
DNS1=8.8.8.8
DNS2=4.4.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=6608c0be-b797-44e2-b3f3-028b87f11c9c
DEVICE=ens160
ONBOOT=yes(在上面设置中已开启开机自动获取)

1、RPM软件管理

1)通过rpm安装vsftpd软件。

#先挂载
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ll
total 48
dr-xr-xr-x. 4 root root  2048 Oct 13  2021 AppStream
dr-xr-xr-x. 4 root root  2048 Oct 13  2021 BaseOS
dr-xr-xr-x. 3 root root  2048 Oct 13  2021 EFI
-r--r--r--. 1 root root  8154 Oct 13  2021 EULA
-r--r--r--. 1 root root  1455 Oct 13  2021 extra_files.json
-r--r--r--. 1 root root 18092 Oct 13  2021 GPL
dr-xr-xr-x. 3 root root  2048 Oct 13  2021 images
dr-xr-xr-x. 2 root root  2048 Oct 13  2021 isolinux
-r--r--r--. 1 root root   103 Oct 13  2021 media.repo
-r--r--r--. 1 root root  1669 Oct 13  2021 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5135 Oct 13  2021 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 Oct 13  2021 TRANS.TBL
[root@localhost mnt]# cd AppStream/
[root@localhost AppStream]# ll
total 1156
dr-xr-xr-x. 2 root root 1179648 Oct 13  2021 Packages
dr-xr-xr-x. 2 root root    4096 Oct 13  2021 repodata
[root@localhost AppStream]# cd Packages/
[root@localhost Packages]# ls vsftpd-3.0.3-34.el8.x86_64.rpm 
vsftpd-3.0.3-34.el8.x86_64.rpm
[root@localhost Packages]# rpm -ivh vsftpd-3.0.3-34.el8.x86_64.rpm
warning: vsftpd-3.0.3-34.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.3-34.el8              ################################# [100%]
[root@localhost Packages]# 
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.72.129:22) at 17:06:31.

Type `help' to learn how to use Xshell prompt.

2)查询vsftpd软件包的信息。

[root@localhost ~]# rpm -qi vsftpd
Name        : vsftpd
Version     : 3.0.3
Release     : 34.el8
Architecture: x86_64
Install Date: Sat 05 Nov 2022 05:06:01 AM EDT
Group       : System Environment/Daemons
Size        : 355692
License     : GPLv2 with exceptions
Signature   : RSA/SHA256, Wed 21 Apr 2021 08:42:12 AM EDT, Key ID 199e2f91fd431d51
Source RPM  : vsftpd-3.0.3-34.el8.src.rpm
Build Date  : Tue 20 Apr 2021 10:28:24 AM EDT
Build Host  : x86-vm-15.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : https://security.appspot.com/vsftpd.html
Summary     : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.

3)卸载软件包vsftpd。

[root@localhost ~]# rpm -e vsftpd

2、YUM软件管理

1)挂载本地光盘,配置yum源为rhel8.repo。

[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 already mounted on /mnt.
[root@localhost ~]# vim /etc/yum.repos.d/rhel8.repo
[rhel8-BaseOS]
name=rhel8-BaseOS
baseurl=file:///media/cdrom/BaseOS
gpgcheck=0
enable=1

[rhel8-AppStream]
name=rhel8-AppStream
baseurl=file:///media/cdrom/AppStream
gpgcheck=0
enable=1

2)通过yum来安装httpd。

[root@localhost ~]# yum install httpd -y

3)使用yum查询ifconfig命令是由那个软件包提供的。

[root@localhost ~]# yum whatprovides */ifconfig
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 14:17:54 ago on Sat 05 Nov 2022 08:51:17 AM EDT.
net-tools-2.0-0.52.20160912git.el8.x86_64 : Basic networking tools
Repo        : @System
Matched from:
Filename    : /usr/sbin/ifconfig

net-tools-2.0-0.52.20160912git.el8.x86_64 : Basic networking tools
Repo        : rhel8-BaseOS
Matched from:
Filename    : /usr/sbin/ifconfig

4)卸载软件包httpd。

[root@localhost ~]# yum remove -y httpd

3、源码管理

下载tree源码包并编译安装。

[root@localhost Packages]# rpm -ivh tree-1.7.0-15.el8.x86_64.rpm
warning: tree-1.7.0-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
	package tree-1.7.0-15.el8.x86_64 is already installed

4、进程管理

1)通过ps命令的两种选项形式查看进程信息

[root@localhost Packages]# ps -l
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0    3919    3918  0  80   0 -  6924 -      pts/0    00:00:00 bash
0 R     0    5120    3919  0  80   0 - 11370 -      pts/0    00:00:00 ps
[root@localhost Packages]# ps -u

2)通过pgrep和pidof命令查看sshd服务的进程号

[root@localhost Packages]# pgrep sshd
1098
3914
3918
[root@localhost Packages]# pidof sshd
3918 3914 1098

3)使dd if=/dev/zero of=/root/file bs=1M count=8190 命令操作在前台运行

[root@localhost Packages]# dd if=/dev/zero of=/root/file bs=1M count=8190
8190+0 records in
8190+0 records out
8587837440 bytes (8.6 GB, 8.0 GiB) copied, 107.231 s, 80.1 MB/s

4)将上题操作调入到后台并暂停

[root@localhost Packages]# dd if=/dev/zero of=/root/file bs=1M count=8190
^Z
[1]+  Stopped                 dd if=/dev/zero of=/root/file bs=1M count=8190

5)使dd if=/dev/zero of=/root/file2 bs=1M count=1024 命令操作在后台运行

[root@localhost Packages]# dd if=/dev/zero of=/root/file2 bs=1M count=1024 &

6)查看后台的任务列表

[root@localhost Packages]# jobs
[1]+  Stopped                 dd if=/dev/zero of=/root/file bs=1M count=8190  &

7)恢复dd if=/dev/zero of=/root/file bs=1M count=8190 让其在后台继续运行

[root@localhost Packages]# bg %1
[1]+ dd if=/dev/zero of=/root/file bs=1M count=8190 &

8)查询dd if=/dev/zero of=/root/file bs=1M count=8190 命令的进程并通过kill杀死

[root@localhost Packages]# jobs
[1]+  Running                 dd if=/dev/zero of=/root/file bs=1M count=8190 &
[root@localhost Packages]# kill %1
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值