Linux系统管理上机作业2

chapter02 - 03 作业

 

1、分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处?

[root@localhost ~]# cat /etc/ssh/sshd_config

[root@localhost ~]# tac /etc/ssh/sshd_config

[root@localhost ~]# nl /etc/ssh/sshd_config

不同之处:
虽都是查看文件内容,cat正常顺序显示文件内容,但是tac则逆序显示文件内容。cat -n nl 区别在与nl 对空白行不标行号,而cat -n显示空白行行号。

2、分别用moreless查看/etc/ssh/sshd_config里面的内容,请用总结moreless两个命令的相同和不同之处?

[root@localhost ~]# more /etc/ssh/sshd_config

[root@localhost ~]# less /etc/ssh/sshd_config

more全屏方式分页显示文件内容,lessmore基础相同,但是扩展功能更多。

more使画面在显示满一页时暂停,此时可按Enter向下滚动一行,空格健向下滚动一页。q键退出。less也可以用来浏览超过一页的文件.所不同的是less命令除了可以按空格键向下显示文件外,还可以利用PgUpPgDn键来上下翻页,按“/”键查找内容。

3、将/etc/passwd文件中的前20行重定向保存到/root下改名为20_pass.txt,/etc/passwd文件中的后15行重定向保存到/root下改名为:pass_15.txt

[root@localhost ~]# head -20 /etc/passwd > /root/20_pass.txt

[root@localhost ~]# tail -15 /etc/passwd > /root//pass_15.txt

4、请用一个命令统计/etc/hosts文件包含有多少行?多少字节?多少单词数?

[root@localhost ~]# wc -lwc /etc/hosts

  2  10 158 /etc/hosts  

210字节  158单词数

5、练习使用grepegrep

5.1.通过grep管道工具过滤出ifconfig命令显示信息中的IP字段?

[root@localhost ~]# ifconfig|grep "inet"

        inet 192.168.100.140  netmask 255.255.255.0  broadcast 192.168.100.255

        inet6 fe80::20c:29ff:fe1f:d4f9  prefixlen 64  scopeid 0x20<link>

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

5.2./etc/passwd文件中的前20行重定向保存到/root下名称为pass

[root@localhost ~]# head -20 /etc/passwd >pass

5.3.过滤/etc/passwd文件中含有/sbin/nologin 的行并统计行数?

[root@localhost ~]# grep -v "sbi/nologin" /etc/passwd |wc -l

40

5.4 过滤/etc/passwd文件中以sh结尾的行,及以 root开头的行,不显示包含login的行?

root@localhost ~]# egrep -v "sh$|^root|*login*" /etc/passwd

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

5.5 分别用grepegrep过滤出/etc/ssh/sshd_config文件中不包含“#”开头和空白的行?

[root@localhost ~]# grep -v "^#" /etc/ssh/sshd_config |grep -v "^$"

[root@localhost ~]# egrep -v "^#|^$" /etc/ssh/sshd_config

6.1 通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.gz

[root@localhost ~]# tar zcf /root/file.tar.gz /etc/passwd

tar: 从成员名中删除开头的“/

6.2通过tar命令将/etc/passwd文件打包压缩成/root/file.tar.bz2

[root@localhost ~]# tar jcf /root/file.tar.bz2 /etc/passwd

tar: 从成员名中删除开头的“/

6.3创建空文件夹/web/test1,并将file.tar.bz2 解包并释放到/web/test1目录下?

[root@localhost ~]# mkdir -pv /web/test1

mkdir: 已创建目录 "/web/test1"

[root@localhost ~]# tar xf file.tar.bz2 -C /web/test1

7.1 通过vi编辑/web/test1/passwd文件将文件里为root单词全部替换成benet

[root@localhost ~]# vi pass passwd为空文件故编辑pass

:%s/root/benet/g

7.2 通过vi编辑 删除pass文件第1510行。

:set nu

:10   dd

:5    dd

:1    dd

7.3 vi中显示pass文件行号复制文件2 3 4行粘贴到以lp开头的行下。

:set nu

:2

3yy

/ip

p

7.4 通过vi编辑 查找文件内包含mail var等字符串,并记录所在行号。

:set nu

/mail

/var

7.5 通过vi编辑 快速跳转到文件的第二行,通过r 读取 /etc/hosts 文件的内容到第二行下。

:2

:r /etc/hosts

7.6将更改后的文件使用vim另存为/root/new_pass

:w /root/new_pass

7.7new_pass文件压缩成gz格式并改名为npass.gz文件。

[root@localhost ~]# gzip new_pass > npass.gz

8统计/dev 目录下的文件数量。

[root@localhost ~]# ls -la /dev |grep -v "^d"|wc -l

141

9.1/boot下查找文件名以vmlinuz开头的文件?

[root@localhost ~]# find /boot -name "vmlinuz*"

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-3976b93719124fbe85ee29d5f4a34965

9.2/boot下查找文件大小大于3M 小于 20M 的文件

[root@localhost ~]# find /boot -size +3M -a -size -20M

/boot/vmlinuz-3.10.0-229.el7.x86_64

/boot/vmlinuz-0-rescue-3976b93719124fbe85ee29d5f4a34965

/boot/initramfs-3.10.0-229.el7.x86_64.img

10 请详细写出构建本地yum仓库的步骤?并在每行命令后面用自己的话做上中文注释?

[root@localhost ~]# ls /media/  (查看光盘)

[root@localhost ~]# mount /dev/sr0 /media/  (挂载光盘)

mount: /dev/sr0 写保护,将以只读方式挂载

[root@localhost ~]# ls /media/  (查看光盘)

CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7

EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7

EULA             isolinux  repodata  TRANS.TBL

[root@localhost ~]# cd /etc/yum.r*   (切换目录)

[root@localhost yum.repos.d]# ls    (查看目录)

CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo

CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Vault.repo

[root@localhost yum.repos.d]# mkdir a/  (创建a/

[root@localhost yum.repos.d]# mv C* a/   (将Centos均剪切到a)

[root@localhost yum.repos.d]# ls   (查看)

 a

[root@localhost yum.repos.d]# ls a

CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo

CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Vault.repo

[root@localhost yum.repos.d]# vi ./local.repo  (创建本地yum仓库文档)

 

[cdrom]   

name=cdrom

baseurl=file:///media/

enabled=1

gpgcheck=0                                                                      

~                                                                                                                                                     

"local.repo" [New] 5L, 65C written

[root@localhost yum.repos.d]# yum -y clean all

已加载插件:fastestmirror, langpacks

正在清理软件源: cdrom

Cleaning up everything

Cleaning up list of fastest mirrors

[root@localhost yum.repos.d]# yum makecache

已加载插件:fastestmirror, langpacks

cdrom                                                    | 3.6 kB     00:00     

(1/4): cdrom/filelists_db                                  | 2.7 MB   00:00     

(2/4): cdrom/group_gz                                      | 154 kB   00:00     

(3/4): cdrom/other_db                                      | 1.1 MB   00:00     

(4/4): cdrom/primary_db                                    | 2.7 MB   00:00     

Determining fastest mirrors

元数据缓存已建立

11、用yum命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost yum.repos.d]# rpm -q vsftpd

未安装软件包 vsftpd

[root@localhost yum.repos.d]# yum -y install vsftpd

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解决依赖关系

--> 正在检查事务

---> 软件包 vsftpd.x86_64.0.3.0.2-9.el7 将被 安装

--> 解决依赖关系完成

 

依赖关系解决

 

================================================================================

 Package          架构             版本                   源               大小

================================================================================

正在安装:

 vsftpd           x86_64           3.0.2-9.el7            cdrom           165 k

 

事务概要

================================================================================

安装  1 软件包

 

总下载量:165 k

安装大小:343 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : vsftpd-3.0.2-9.el7.x86_64                                   1/1

  验证中      : vsftpd-3.0.2-9.el7.x86_64                                   1/1

 

已安装:

  vsftpd.x86_64 0:3.0.2-9.el7                                                   

 

完毕!

[root@localhost yum.repos.d]# rpm -q vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost yum.repos.d]# yum -y remove vsftpd

已加载插件:fastestmirror, langpacks

正在解决依赖关系

--> 正在检查事务

---> 软件包 vsftpd.x86_64.0.3.0.2-9.el7 将被 删除

--> 解决依赖关系完成

 

依赖关系解决

 

================================================================================

 Package          架构             版本                  源                大小

================================================================================

正在删除:

 vsftpd           x86_64           3.0.2-9.el7           @cdrom           343 k

 

事务概要

================================================================================

移除  1 软件包

 

安装大小:343 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在删除    : vsftpd-3.0.2-9.el7.x86_64                                   1/1

  验证中      : vsftpd-3.0.2-9.el7.x86_64                                   1/1

 

删除:

  vsftpd.x86_64 0:3.0.2-9.el7                                                   

 

完毕!

[root@localhost yum.repos.d]# rpm -q vsftpd

未安装软件包 vsftpd

12、用rpm命令安装vsftpd,查询安装情况,最后卸载vsftpd,并再次查询卸载情况?

[root@localhost ~]# cd /media/Packages

[root@localhost Packages]# rpm -q vsftpd

未安装软件包 vsftpd

[root@localhost Packages]# rpm -ivh vsftpd-3.0.2-9.el7.x86_64.rpm

警告:vsftpd-3.0.2-9.el7.x86_64.rpm: V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

准备中...                          ################################# [100%]

正在升级/安装...

   1:vsftpd-3.0.2-9.el7               ################################# [100%]

[root@localhost Packages]#  rpm -q vsftpd

vsftpd-3.0.2-9.el7.x86_64

[root@localhost Packages]#  rpm -e vsftpd

[root@localhost Packages]#  rpm -q vsftpd

未安装软件包 vsftpd

13、通过源码方式通过解包、配置、编译、安装四个步骤安装源码软件httpd-2.2.17.tar.gz?并进行测试?

[root@localhost ~]# cd /opt

[root@localhost Packages]# rpm -q gcc gcc-c++ make

未安装软件包 gcc

未安装软件包 gcc-c++

make-3.82-21.el7.x86_64

[root@localhost Packages]# yum -y install gcc gcc-c++

[root@localhost opt]# rpm -q gcc gcc-c++ make

[root@localhost opt]# gcc --version

[root@localhost opt]# make --version

[root@localhost ~]# ls

anaconda-ks.cfg      公共  视频  文档  音乐

httpd-2.2.17.tar.gz  模板  图片  下载  桌面

[root@localhost ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src/

[root@localhost ~]# ls /usr/src/

debug  httpd-2.2.17  kernels

[root@localhost ~]# cd /usr/src/httpd-2.2.17/

[root@localhost httpd-2.2.17]# ./config --prefix=/usr/local/apache

[root@localhost httpd-2.2.17]# make

[root@localhost httpd-2.2.17]# make install   //安装完成编译安装

[root@localhost ~]# cd /usr/local/apache/conf 

[root@localhost conf]# ls
extra httpd.conf magic mime.types original
[root@localhost conf]# cp httpd.conf{,.bak}
[root@localhost conf]# ls
extra httpd.conf httpd.conf.bak magic mime.types original

[root@localhost conf]# vi /usr/local/apache/conf/httpd.conf

[root@localhost conf]# /usr/local/apache/bin/apachectl start

[root@localhost conf]# systemctl stop firewalld
[root@localhost conf]# systemctl disable firewalld
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
[root@localhost conf]# setenforce 0

[root@localhost conf]# sed -i '7 s/enforcing/disabled/' /etc/selinux/config

[root@localhost conf]# sed -n '7p' /etc/selinux/config
SELINUX=disabled

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

[root@localhost ~]# lynx http:// 192.168.100.100

 

转载于:https://www.cnblogs.com/bbhymy/p/11252562.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值