设为首页 收藏本站
查看: 1754|回复: 0

[经验分享] linux redhat 虚拟机

[复制链接]

尚未签到

发表于 2018-5-10 08:07:14 | 显示全部楼层 |阅读模式
  df ###查看已经使用了的空间
  blkid ###显示所有可用设备的id信息
  du -sh /mnt/  ###查看设备的使用情况
  fuser -vm /dev/sdb1  ###
[kiosk@foundation59 Desktop]$ fuser -vm /dev/sdb1

[kiosk@foundation59 Desktop]$

  

[root@foundation14 ~]# updatedb    ###更新数据库

[root@foundation14 ~]# locate westos   ###查找westos文件,locate查找不准确,locate只在数据库里面查找,所以要更新数据路库

[root@foundation14 ~]# touch /boot/westos

[root@foundation14 ~]# locate westos

[root@foundation14 ~]# updatedb

[root@foundation14 ~]# locate westos

  /boot/westos
[root@foundation14 ~]# rm -fr /boot/westos

[root@foundation14 ~]# locate westos

  /boot/westos
[root@foundation14 ~]# ll /boot/westos

  ls: cannot access /boot/westos: No such file or directory
[root@foundation14 ~]# cat /boot/westos

  cat: /boot/westos: No such file or directory
[root@foundation14 ~]# updatedb

[root@foundation14 ~]# cat /boot/westos

  cat: /boot/westos: No such file or directory
[root@foundation14 ~]# locate westos

[root@foundation14 ~]#

  

[root@desktop14 Desktop]# cd /mnt

[root@desktop14 mnt]# ls

[root@desktop14 mnt]# touch file{1..5}

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 1 root root 0 Oct 12 21:53 file1
  -rw-r--r--. 1 root root 0 Oct 12 21:53 file2
  -rw-r--r--. 1 root root 0 Oct 12 21:53 file3
  -rw-r--r--. 1 root root 0 Oct 12 21:53 file4
  -rw-r--r--. 1 root root 0 Oct 12 21:53 file5
[root@desktop14 mnt]# grep bash /etc/passwd    ###查看用户本机所有用户信息

  root:x:0:0:root:/root:/bin/bash
  student:x:1000:1000:Student User:/home/student:/bin/bash
[root@desktop14 mnt]# useradd westos

[root@desktop14 mnt]# useradd lee

[root@desktop14 mnt]# chown westos file1   ###更改文件file1所属用户为westsos

[root@desktop14 mnt]# chown lee file2

[root@desktop14 mnt]# chown westos.lee file3   ##3更改文件file3所属用户为westos所属组为lee

[root@desktop14 mnt]# chown lee.lee file4

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 1 westos root 0 Oct 12 21:53 file1
  -rw-r--r--. 1 lee    root 0 Oct 12 21:53 file2
  -rw-r--r--. 1 westos lee  0 Oct 12 21:53 file3
  -rw-r--r--. 1 lee    lee  0 Oct 12 21:53 file4
  -rw-r--r--. 1 root   root 0 Oct 12 21:53 file5
[root@desktop14 mnt]# find /mnt/ -user westos    ###查找属于用户westos的文件

  /mnt/file1
  /mnt/file3
[root@desktop14 mnt]# find /mnt/ -group root   ###查找属于组root的文件

  /mnt/
  /mnt/file1
  /mnt/file2
  /mnt/file5
[root@desktop14 mnt]# ll -d /mnt/   ###查看目录信息

  drwxr-xr-x. 2 root root 66 Oct 12 21:53 /mnt/
[root@desktop14 mnt]# find /mnt/ -group lee -a -user westos    ###查找属于组lee并且属于用户westos的

  /mnt/file3
[root@desktop14 mnt]# find /mnt/ -not -group lee -a -not -user westos   ###查找不再组lee并且不属于用古westos的

  /mnt/
  /mnt/file2
  /mnt/file5
  

  ###############################
[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file1 bs=1024 count=10

  10+0 records in
  10+0 records out
  10240 bytes (10 kB) copied, 0.000149041 s, 68.7 MB/s
[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file2 bs=1024 count=20  ###指的是一个空的设备input,output

  20+0 records in
  20+0 records out
  20480 bytes (20 kB) copied, 0.000150441 s, 136 MB/s
[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file3 bs=1024 count=30

  30+0 records in
  30+0 records out
  30720 bytes (31 kB) copied, 0.000167358 s, 184 MB/s
[root@desktop14 mnt]# ll

  total 64
  -rw-r--r--. 1 root root 10240 Oct 12 22:08 file1
  -rw-r--r--. 1 root root 20480 Oct 12 22:08 file2
  -rw-r--r--. 1 root root 30720 Oct 12 22:09 file3
[root@desktop14 mnt]# find /mnt/ -size 20k   ###查找文件大小为20k的

  /mnt/file2
[root@desktop14 mnt]# find /mnt/ -size -20k    ###查找文件小于20k的

  /mnt/
  /mnt/file1
[root@desktop14 mnt]# find /mnt/ -size +20k    ###查找文件大于20k的

  /mnt/file3
[root@desktop14 mnt]# find /mnt/ -size -20k -a -type f   ###查找文件小于20k

  /mnt/file1
[root@desktop14 mnt]# find /mnt/ -size -20k -a -type d   ###查找目录小于20k

  /mnt/
[root@desktop14 mnt]#

  ##############################
[root@desktop14 mnt]# chmod 000 /mnt/*   ###更改/mnt/下所有文件的权限为0

[root@desktop14 mnt]# ll

  total 64
  ----------. 1 root root 10240 Oct 12 22:08 file1
  ----------. 1 root root 20480 Oct 12 22:08 file2
  ----------. 1 root root 30720 Oct 12 22:09 file3
[root@desktop14 mnt]# chmod 444 file1   ###更改文件file1的权限

[root@desktop14 mnt]# chmod 404 file2

[root@desktop14 mnt]# ll

  total 64
  -r--r--r--. 1 root root 10240 Oct 12 22:08 file1
  -r-----r--. 1 root root 20480 Oct 12 22:08 file2
  ----------. 1 root root 30720 Oct 12 22:09 file3
[root@desktop14 mnt]# find /mnt -perm 444   ###查找文件权限等于444的文件,permission

  /mnt/file1
[root@desktop14 mnt]# find /mnt -perm -444   ###查找权限大于和等于444文件的

  /mnt
  /mnt/file1
[root@desktop14 mnt]# find /mnt -perm /444

  /mnt
  /mnt/file1
  /mnt/file2
[root@desktop14 mnt]# find /mnt -perm /755   ###斜杠后面跟的数字越大,找到满足条件的文件会越多,以为他是或的关系,只要7个条件中有一个满足就可以

  /mnt
  /mnt/file1
  /mnt/file2
[root@desktop14 mnt]# urwx grx orx^C

  ####################################################
  perm 444  ###文件权限必须是rrr
  perm -444   ###文件每一位都要含有r权限
  perm /444   ###文件任意一位含有r权限
  -maxdepth 数字   ###最深目录层
  -mindepth 数字   ###最浅目录层
  -exec  命令 {} \   ###对查找出的结果做相应的处理
[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name ^C

[root@desktop14 mnt]# find /etc/ -name passwd  ###查找文件名为passwd的文件

  /etc/passwd
  /etc/pam.d/passwd
[root@desktop14 mnt]# find /etc/ -maxdepth 1 -name passwd  ###查找目录深度为1的文件名为passwd的文件

  /etc/passwd
[root@desktop14 mnt]# find /etc/ -maxdepth 2 -name passwd  ###查找目录深度为2以内(包括深度为1的)的文件名为passwd的文件

  /etc/passwd
  /etc/pam.d/passwd
[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name passwd   ###查找最大深度是2最小深度也是2的文件名为passwd的文件

  /etc/pam.d/passwd
[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name passwd -exec cp {} /mnt \; ###查找最大深度是2最小深度也是2的文件名是passwd的文件,并且把它复制到/mnt目录下

[root@desktop14 mnt]# ls  ###查看刚才复制过来的文件

  file1  file2  file3  passwd
[root@desktop14 mnt]# find /mnt/ -perm -444 -exec rm -fr {} \;   ###查找文件权限是444并且删除所有

  find: ‘/mnt/’: No such file or directory
[root@desktop14 mnt]#

[root@desktop14 mnt]# ls

[root@desktop14 mnt]#

  软连接就是快捷方式,建立软链接的目的是为了节省设备存储
  硬链接就是把文件重新复制一次,只有文件的内容没有文件的属性
[root@desktop14 mnt]# touch file

[root@desktop14 mnt]# ln -s /mnt/file /mnt/westos  ###soft指的软链接

[root@desktop14 mnt]# ll

  total 0
  drwxr-xr-x. 2 root root 6 Oct 12 23:06 backup   ###其中的2是文件被记录的次数
  -rw-r--r--. 1 root root 0 Oct 12 23:15 file
  lrwxrwxrwx. 1 root root 9 Oct 12 23:15 westos -> /mnt/file
[root@desktop14 mnt]# rm -fr file

[root@desktop14 mnt]# cat /mnt/westos   ###删掉文件之后,软链接也不可用

  cat: /mnt/westos: No such file or directory
[root@desktop14 mnt]# rm -fr *

[root@desktop14 mnt]# touch file

[root@desktop14 mnt]# ln /mnt/file /mnt/westos    ###创建硬链接,

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 2 root root 0 Oct 12 23:17 file
  -rw-r--r--. 2 root root 0 Oct 12 23:17 westos
[root@desktop14 mnt]# ln /mnt/file /mnt/westos1

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 3 root root 0 Oct 12 23:17 file
  -rw-r--r--. 3 root root 0 Oct 12 23:17 westos
  -rw-r--r--. 3 root root 0 Oct 12 23:17 westos1
[root@desktop14 mnt]# rm -fr westos1

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 2 root root 0 Oct 12 23:17 file   ###删除一次,文件的被记录的次数减少一次
  -rw-r--r--. 2 root root 0 Oct 12 23:17 westos
[root@desktop14 mnt]# rm -fr westos

[root@desktop14 mnt]# ll

  total 0
  -rw-r--r--. 1 root root 0 Oct 12 23:17 file
[root@desktop14 mnt]# rm -fr file

[root@desktop14 mnt]# ll

  total 0
[root@desktop14 mnt]# ls -li *  ###查看节点信息

  virt-manager ###安装虚拟机
  ls -i ###查看设备的节点号
[root@foundation59 mnt]# virt-manager   ###弹出虚拟机管理界面

[root@foundation59 mnt]# virt-viewer desktop  ###立即弹出desktop虚拟机界面

[root@foundation14 ~]# virt-manager test11

[root@foundation14 ~]# virt-viewer test11   ###查看虚拟机

  

  (virt-viewer:15729): GSpice-WARNING **: PulseAudio context failed Connection refused
  

  (virt-viewer:15729): GSpice-WARNING **: pa_context_connect() failed: Connection refused
  

  (virt-viewer:15729): GSpice-WARNING **: Warning no automount-inhibiting implementation available
  ^C
[root@foundation14 ~]#

[root@foundation14 ~]# virsh list   ###列出所有虚拟机信息

  Id    Name                           State
  ----------------------------------------------------
  2     desktop                        paused
  3     server                         paused
  8     test11                         running
[root@foundation14 ~]# virsh list --all

  Id    Name                           State
  ----------------------------------------------------
  2     desktop                        paused
  3     server                         paused
  8     test11                         running
[root@foundation14 ~]# virsh destroy test11   ###立即关闭虚拟机

  Domain test11 destroyed
  

[root@foundation14 ~]# virsh start test11   ###开启虚拟机

[root@foundation14 ~]# virsh shutdown test11   ###关闭虚拟机

  Domain test11 started
[root@foundation14 ~]# cd /var/lib/libvirt/images   ###进入虚拟机文件存放目录

[root@foundation14 images]# ls   ###查看所有可用源镜像

  rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2
  rh124-desktop-vda.qcow2  rh124-server-vda.ovl    rh124-server.xml
  rh124-desktop-vdb.ovl    rh124-server-vda.qcow2  rhel7.0.qcow2
  rh124-desktop-vdb.qcow2  rh124-server-vdb.ovl
[root@foundation14 images]# qemu-img create -f qcow2 -b rhel7.0.qcow2 test1.qcow2  ###快照虚拟机,新快照名为test1.qcow2

  Formatting 'test1.qcow2', fmt=qcow2 size=9663676416 backing_file='rhel7.0.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@foundation14 images]# ls   ###查看新建的快照

  rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2
  rh124-desktop-vda.qcow2  rh124-server-vda.ovl    rh124-server.xml
  rh124-desktop-vdb.ovl    rh124-server-vda.qcow2  rhel7.0.qcow2
  rh124-desktop-vdb.qcow2  rh124-server-vdb.ovl    test1.qcow2
[root@foundation14 images]# du -sh test1.qcow2   ###查看快照的大小信息

  196Ktest1.qcow2
  ####################################################################
  然后新建虚拟机,选择已有镜像
  

  

  交互式登陆就是你可以和系统进行对话,系统会有反馈
  vim /etc/chrony.conf ###设置时间进行同步
  

[root@foundation59 ~]# find / -group mail   ###

  find: ‘/proc/4303/task/4303/fd/6’: No such file or directory
  find: ‘/proc/4303/task/4303/fdinfo/6’: No such file or directory
  find: ‘/proc/4303/fd/6’: No such file or directory
  find: ‘/proc/4303/fdinfo/6’: No such file or directory
  find: ‘/run/user/1000/gvfs’: Permission denied
  /var/spool/mail
  /var/spool/mail/rpc
  /var/spool/mail/kiosk
  ^C
[root@foundation59 ~]#

[root@foundation59 ~]# find / -group mail -exec cp -rp {} /mnt/backup \;   ###找出用户组mail 拥有的文件,并且将它们放到/mnt/backup 目录中

  find: ‘/proc/4335/task/4335/fd/6’: No such file or directory
  find: ‘/proc/4335/task/4335/fdinfo/6’: No such file or directory
  find: ‘/proc/4335/fd/6’: No such file or directory
  find: ‘/proc/4335/fdinfo/6’: No such file or directory
  find: ‘/run/user/1000/gvfs’: Permission denied
  ^C
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-457841-1-1.html 上篇帖子: redhat7.1 ntfs 挂载 下篇帖子: AWS EC2 redhat7.2 操作系统中基本配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表