运维之红帽管理员篇-----3. 软件包管理 、 网络配置 、文本/文件查找

来源:互联网 发布:淘宝网1688地板砖 编辑:程序博客网 时间:2024/05/20 01:07

THREE DAY

我看到了我的爱恋,我飞到她的身边,我捧出给她的礼物,那是一小块凝固的时间,时间上有美丽的条纹,摸出来像浅海的泥一样柔软,她把时间涂满全身,然后拉起我飞向存在的边缘,这是灵态的飞行,我们眼中的星星像幽灵,星星眼中的我们也像幽灵。      -----歌者

笔记

总结笔记:简要写知识点及必须牢记内容。

正式笔记:详细记录学习的步骤命令及细节。

随笔录:为课堂大神随口扩展的知识,此较为零散,但对自己学习体系的搭建十分有用

因此,学习的同志可以从正式笔记一步一步来,一点一点搭建自己的知识网络;多想多敲多练多总结;切忌走马观花,心浮气躁;要像练武功秘籍般心平气和,专心致志。

当然由于笔记记录仓促整理,不免有些错误与疏忽的地方,谢谢小伙伴的提醒。


总结笔记:

1.rpm -q   软件名...

rpm -ivh 软件名-版本信息.rpm

rpm -e   软件名..

 rpm -Uvh 升级软件包

-  rpm -Fvh 刷新软件包

-  rpm -qa查看已安装软件包

-  rpm -qi 查看已安装软件包描述信息

-  rpm -ql 查看已安装软件包文件列表

-  rpm -qR 查看软件包的依赖要求

-  rpm -qf 查看指定文件属于哪个软件包

###########################################.

2.指定yum软件源

#rm -rf /etc/yum.repos.d/*.repo

#yum clean all           //清缓存

#vim /etc/yum.repos.d/dvd.repo

[dvd]                             #仓库的名称

name=hahaxixi                     #仓库的描述信息

baseurl=file:///dvd               #指定仓库服务端位置

enabled=1                         #启用文件

gpgcheck=0                        #不检测签名认证

– yum repolist            //列仓库

– yum list [软件名]...     //列软件

– yum clean all           //清缓存

– yum -y install 软件名...   //安装软件

– yum -y remove 软件名...    //卸载软件

########################################

3.配置网络静态IP

nmcli connection show

# nmcli  connection  modify  'System eth0' 

ipv4.method  manual                             #手动配置IP

ipv4.addresses  '172.25.0.11/24  172.25.0.254' 

ipv4.dns  '172.25.254.254' 

connection.autoconnect  yes                    #每次开机启用

# nmcli connection up 'System eth0'            #激活网络

#systemctl  restart  NetworkManager          #开机自启

#systemctl  enable  NetworkManager

查看# ifconfig

Hostnamectl                              #查看设置主机名

Vim /etc/hostname                            #|设置永久主机名

host  server0/desktop0/content.example.com       #查看站点

Route -n

Cat /etc/resolv.conf        #查看DNS服务器地址

# cat  /etc/sysconfig/network-scripts/ifcfg-eth0

4.升级内核:内核默认位置:/boot/vmlinuz-*    多系统启动配置:/boot/grub2/grub.cfg

wget http://172.25.0.254/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm

# uname -r

# rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm

# reboot 

# uname -r

5.cat  -n  添加行号

 less  适合查看大文件,分屏阅读

head -12 /etc/passwd | tail -5 

echo 1+1 | bc

 Grep -i,忽略大小写

– -v,取反匹配

以字符串开头:^root

以字符串结尾:root$

grep -v  '#' /etc/login.defs | grep -v ‘^$’去空行与注释

[root@serverX ~]# grep  'seismic'  /usr/share/dict/words  >  /root/wordlist   #查找并提取

##########################################################################

 find [目录] [条件1] [-a|-o] [条件2] ...

– 常用条件表示:

-type 类型(f文件、d目录、l快捷方式)

-name "文档名称"

-size +|-文件大小(kMG)

-mtime +|-修改天数

-user 用户名

-group

find /boot/ -type l/f/d

find /root -name "test*" -a -type d

find /root -name "test*" -o -type d

find /boot/ -size +300k

find /  -user student -type f

find /boot/ -size +10M     -exec cp {} /opt/ \;

4.find / -user student -type f     -exec cp {}  /root/findfiles \;

 

1.自己建立的虚拟机,将光盘放入光驱,挂载光驱设备

[root@A ~]# mkdir /dvd

[root@A ~]# mount /dev/cdrom  /dvd

[root@A ~]# ls /dvd/P(tab)

[root@A ~]# ls /dvd

addons  images      Packages                 RPM-GPG-KEY-redhat-release

EFI     isolinux    release-notes            TRANS.TBL

EULA    LiveOS      repodata

###################################################

1.使用rpm命令管理软件

• RPM Package Manager,RPM包管理器

– rpm -ivh 安装软件名-版本信息.rpm

– rpm -e   卸载软件名...

– rpm -q   #显示软件名...

-  rpm -Uvh 升级软件包

-  rpm -Fvh 刷新软件包

-  rpm -qa查看已安装软件包

-  rpm -qi 查看已安装软件包描述信息

-  rpm -ql 查看已安装软件包文件列表

-  rpm -qR 查看软件包的依赖要求

-  rpm -qf 查看指定文件属于哪个软件包

 

[root@A /]# rpm -q firefox/bash/vsftpd/net-tools       #查询软件包是否安装 

firefox-38.3.0-2.el7_1.x86_64

[root@A /]# rpm -ivh /dvd/Packages/vsftpd-3.0.2-10.el7.x86_64.rpm 

[root@A /]# rpm -e vsftpd      #卸载程序

[root@A /]# rpm -q vsftpd

了解:导入红帽官方签名信息

[root@A /]# rpm --import /dvd/RPM-GPG-KEY-redhat-release

######################################################

错误的依赖关系

# rpm -ivh bind-chroot-9.9.4-29.el7.x86_64.rpm 

error: Failed dependencies:

bind = 32:9.9.4-29.el7 is needed by bind-chroot-32:9.9.4-29.el7.x86_64

###################################################

2.Yum软件包仓库

服务:C/S  

服务端:提供服务,为客户端安装软件包的服务

1.前提 众多的RPM

2.前提 仓库清单文件(repodata)

3.挂载光盘,出现光盘的所有内容

客户端:享受服务,指明服务端位置,修改配置

配置前:

[root@A dvd]#rm -rf /etc/yum.repos.d/*.repo

yum clean all           //清缓存

1.[root@desktop0 ~]# yum-config-manager  --add-repo  http://content.example.com/rhel7.0/x86_64/dvd 

2.[root@desktop0~]# vim /etc/yum.repos.d/dvd.repo或者content.example.com/rhel7.0/x86_64/dvd 

[dvd]                             #仓库的名称

name=hahaxixi                     #仓库的描述信息

baseurl=file:///dvd               #指定仓库服务端位置

enabled=1                         #启用文件

gpgcheck=0                        #不检测签名认证

3.[root@A /]# yum repolist     #列出Yum仓库的信息

注意:错误的客户端配置文件,会影响正确的配置文件

####################################################

Yum的使用:

– yum repolist            //列仓库

– yum list [软件名]...     //列软件

– yum clean all           //清缓存

– yum -y install 软件名...   //安装软件

– yum -y remove 软件名...    //卸载软件

[root@A /]# yum -y install gcc/bind-chroot/system-config-kickstart/mariadb-server /httpd

[root@A /]# yum remove gcc

检测Yum是否可用:

[root@A /]# yum clean all   #清空缓存

[root@A /]# yum repolist

###################################################

在虚拟机classrom上,搭建Web服务,共享光盘所有内容

Baseurl=http://172.25.0.254/content/rhel7.0/x86_64/dvd/

虚拟机server/desktop同上

###################################################

3.升级Linux内核

虚拟机server0

复制:http://172.25.0.11/content/rhel7.0/x86_64/errata/Pac

kages/kernel-3.10.0-123.1.2.el7.x86_64.rpm

[root@server0 ~]# wget http://172.25.0.254/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm

# uname -r

rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm

reboot 

# uname -r

#######################################################

4.配置网络

查看/设置IP地址

1. ifconfig命令

 ifconfig [接口名]

– ifconfig -a显示所有网卡

– ifconfig [接口名] IPv4地址/掩码长度

   ifconfig  lo  down/up

##################################################

2.配置静态主机名:[root@server0 ~]# vim /etc/hostname

3.DNS测试:host 主机名/IP

 配置DNS服务器:vim /etc/resolv.conf  设置完退出再进

网卡配置文件:Vim/cat /etc/sysconfig/network-scripts/ifcfg-eth0 

4.查看网络连接:nmcli connection show

5.修改网络连接: nmcli  connection  modify  'System eth0' 

               ipv4.method  manual          #手动配置IP

               ipv4.addresses  '172.25.0.11/24  172.25.0.254' 

               ipv4.dns  '172.25.254.254' 

               connection.autoconnect  yes  #次开机启用

#6. nmcli connection up 'System eth0   #激活网络

7.systemctl  restart  NetworkManager

  systemctl  enable  NetworkManager   #设置开机自启

8.查看# ifconfig

   Route -n

   Cat /etc/resolv.conf

  # cat  /etc/sysconfig/network-scripts/ifcfg-eth0

RHEL7.2系统中

# nmcli connection modify eth0 ipv4.method  manual ipv4.addresses 192.168.4.123/24               ipv4.gateway   192.168.4.254  ipv4.dns '8.8.8.8' connection.autoconnect yes

######################################################

5.重定向输出:将前面命令的输出结果,写入文本文件中

  >  :覆盖重定向

  >>:追加重定向

[root@server001 ~]# hostname > /opt/a.txt

[root@server001 ~]# cat /opt/a.txt

[root@server001 ~]# hostname >> /opt/a.txt

[root@server001 ~]# cat /opt/a.txt

#################################################

6.查看文本文件内容命令:

1. cat  适合查看小文件

  cat  -n  添加行号

2. less  适合查看大文件,分屏阅读

     按键盘上下键   按q退出

3. head   -n    查看文件头几行

  tail   -n    查看文件尾几行 

4. bc   Linux中命令行交互式,计算器    输入quit退出

head -12 /etc/passwd    |  tail -5 

cat  -n  /etc/passwd |  head -12     |  tail -5 

# cat -n  /etc/passwd |  less

# ifconfig  |  head -2

# echo 1+1 | bc

# echo 3*6 | bc

管道:将前面命令的输出结果,传递给后面命令,作为后面命令的参数

######################################################

5.grep 过滤操作

  在文本文件内容中,查找包含指定字符串的行

  grep  '指定字符串'   文本文件

常用命令选项

 -i,忽略大小写

– -v,取反匹配

[root@server001 ~]# grep 'root' /etc/passwd

[root@server001 ~]# grep -i 'Root'  /etc/passwd

[root@server001 ~]# grep -v 'root' /etc/passwd

指定字符串

以字符串开头:^root   查找文本文件内容中,以root开头

以字符串结尾:root$   查找文本文件内容中,以root结尾

[root@server001 ~]# grep '^root' /etc/passwd

[root@server001 ~]# grep 'root$' /etc/passwd

[root@server001 ~]# grep '^$' /etc/passwd

[root@server001 ~]# grep -v '^$' /etc/passwd去空行

[root@server001 ~]# grep '#' /etc/default/useradd

[root@server001 ~]# grep -v  '#/etc/default/useradd去注释

[root@server001 ~]# grep -v  '#' /etc/login.defs | grep -v ‘^$’                #去空行与注释

[root@serverX ~]# grep  'seismic'  /usr/share/dict/words  >  /root/wordlist   #查找并提取

6.find 按条件查找文件

根据预设的条件递归查找对应的文件

– find [目录] [条件1] [-a|-o] [条件2] ...

– 常用条件表示:

-type 类型(f文件、d目录、l快捷方式)

-name "文档名称"

-size +|-文件大小(kMG)

-mtime +|-修改天数

-user 用户名

-group

[root@server0 ~]# find /boot/ -type l

/boot/grub/menu.lst

[root@server0 ~]# ls /boot/grub/menu.lst 

[root@server0 ~]# find /boot/ -type d

[root@server0 ~]# find /boot/ -type f

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

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

[root@server0 ~]# find /etc/ -name "passwd"

[root@server0 ~]# touch /root/test01.txt

[root@server0 ~]# touch /root/test02.txt

[root@server0 ~]# mkdir /root/test

[root@server0 ~]# find /root -name "test*"

[root@server0 ~]# find /root -name "test*" -a -type f

[root@server0 ~]# find /root -name "test*" -a -type d

[root@server0 ~]# find /root -name "test*" -o -type d

[root@server0 ~]# find /root -name "test*"  -type f

[root@server0 ~]# find /boot/ -size +300k

[root@server0 ~]# find /boot/ -size +10M

[root@server0 ~]# find /boot/ -size -10M

-mtime +|-修改天数

-mtime +10   10天之前

-mtime -10   最近10天之内

###################################################

  -user  用户名查找属于哪个用户的

[root@server0 ~]# find /  -user student 

[root@server0 ~]# find /  -user student -type f

[root@server0 ~]# useradd harry

[root@server0 ~]# find /  -user harry

###################################################

• 使用find命令的 --exec 操作

– find .. .. -exec 处理命令 {} \;

– 优势:以 {} 代替每一个结果,逐个处理,遇 \; 结束

# find /boot/ -size +10M     -exec cp {} /opt/ \;

# mkdir /root/findfiles

# find / -user student -type f     -exec cp {}  /root/findfiles \;

# ls /root/findfiles/

# ls -A /root/findfiles/



阅读全文
0 0