案例练习,准备:
rht-vmctl reset classroom
rht-vmctl reset server
rht-vmctl reset desktop
######################################################
?案例1:为虚拟机 server 配置以下静态地址参数
– 主机名:server0.example.com
echo server0.example.com > /etc/hostname
– IP地址:172.25.0.11
– 子网掩码:255.255.255.0
– 默认网关:172.25.0.254
nmcli connection modify 'System eth0' ipv4.method manual ipv4.addresses '172.25.0.11/24 172.25.0.254' connection.autoconnect yes
nmcli connection up 'Syetem eth0'
– DNS服务器:172.25.254.254
echo nameserver 172.25.254.254 > /etc/resolv.conf
案例2:为虚拟机 desktop 配置以下静态地址参数
– 主机名:desktop0.example.com
echo desktop0.example.com > /etc/hostname
– IP地址:172.25.0.10
– 子网掩码:255.255.255.0
– 默认网关:172.25.0.254
nmcli connection modify 'System eth0' ipv4.method manual ipv4.addresses '172.25.0.10/24 172.25.0.254' connection.autoconnection yes
nmcli connection up 'System eth0'
– DNS服务器:172.25.254.254
echo nameserver 172.25.254.254 > /etc/resolv.conf
案例3:指定yum软件源
为 server0 指定可用的 yum 软件源
– YUM软件库的地址为 http://classroom.example.com/rhel7.0/x86_64/dvd
vim /etc/yum.repos.d/rhel_dvd.repo
– 将此配置为虚拟机 server0 的默认软件仓库
– 确认可用的仓库列表
yum repolist
– 利用yum仓库安装gcc编译工具
yum -y install gcc
– 利用yum仓库安装httpd软件
yum -y install httpd
– 利用yum仓库安装sssd软件
yum -y install sssd
案例5:查找并处理文件
– 利用find查找所有用户 student 拥有的文件,把它们拷贝到 /root/findfiles/ 文件夹中
mkdir /root/finddiles
find -user student -type f -exec cp {} /root/findfiles \;
– 利用find查找/boot目录下大于10M并且必须是文件,拷贝到/opt
find /boot -size +10M -type f -exec cp {} /opt \;
ls -lA /opt
– 利用find查找/boot/ 目录下以 vm 开头且必须是文件,拷贝到/opt
find /boot -name 'vm*' -type f -exec cp {} /opt \;
ls /opt
– 利用find查找/etc目录下以“tab”结尾的,必须是文件
find /etc -name '*tab' -type f
– 利用find查找/etc/以“.conf”结尾的配置文件
find /etc -name '*.conf'
– 分别找出/boot目录下的普通文件、文件夹
find /boot -type f
find /boot -type d
– 分别找出/boot目录下的快捷方式、普通文件、文件夹
find /boot -type l
find /boot -type f
find /boot -type d
– 新建一个目录/study,在study目录下建子目录subdir
mkdir /study
mkdir /study/subdir
– 将/etc/fstab拷贝到subdir目录下
cp -r /etc/fstab /study/subdir
ls /study/subdir
– 在study目录下创建测试文件ipadd.txt,存入eth0网卡的IP地址信息
touch /study/ipadd.txt
ifconfig eth0 > /study/ipadd.txt
– 找出study目录下名称以ip开头txt结尾的文件或者目录
find /study -name 'ip*txt'
– 在study目录下创建目录abc,创建两个文件abc01.txt、abc02.txt
mkdir /study/abc
touch /study/abc/abc01.txt
touch /study/abc/abc02.txt
– 找出study目录下以abc开头,但必须文件
find /study -name 'abc*' -type f
– 找出study目录下以abc开头,但必须目录
find /study -name 'abc*' -type d
案例6:在server上操作,查找并提取文件内容
1.在文件 /usr/share/dict/words 中查找到所有包含字符串 seismic 的行,将输出信息,写入到/opt/nsd.txt
grep seismic /usr/share/dict/words
2.查看内核版本将显示结果重定向到/root/abc.txt
uname -r > /root/abc.txt
3.查看红帽系统版本将显示结果追加到/root/abc.txt
cat /etc/redhat-release >> /root/abc.txt
4.将/etc/login.defs文件以“#”开头的内容 写入到/root/login.txt
grep '^#' /etc/login.defs > /root/login.txt
5.提取/etc/passwd以root开头的行,将其信息写入/opt/admin.txt
grep '^root' /etc/passwd > /opt/admin.txt
案例7:定义别名
1)在server上操作,设置一个永久别名byebye,执行byebye的时候能关闭系统
vim /root/.bashrc
alias byebye='poweroff'
:wq
案例8:在server上操作,
以root用户新建/nsddir/目录,在此目录下新建readme.txt文件,并进一步完成下列操作
mkdir /nsddir
touch /nsddir/read.txt
1)将“I love Linux”写入到文件readme.txt
echo I love Linux > readme.txt
2)将readme.txt重命名为mylove.txt
cp /nsddir/readme.txt /nsddir/mylove.txt
3)将/etc/passwd、/boot、/etc/group同时拷贝到/nsddir目录下
cp -r /etc/passwd /boot /etc/group /mnt
4)将ifconfig命令的前两行内容,追加写入mylove.txt
ifconfig | head -2 >> /nsddir/mylove.txt
cat /nsddir/mylove.txt
5)将主机名永久配置文件,拷贝到/nsddir目录下
cp /etc/hostname /nsddir
cat /nsddir/hostname
6)将DNS永久配置文件,拷贝到/nsddir目录下
cp /etc/resolv.conf /nsddir
cat /nsddir/resolv.conf
7)将/boot强制覆盖,拷贝到/nsddir目录下
\cp -rf /boot /nsddir
NSD1710-exec01
原文:http://blog.51cto.com/12055902/2044566