qq524061227 发表于 2018-5-10 08:07:14

linux redhat 虚拟机

  df ###查看已经使用了的空间
  blkid ###显示所有可用设备的id信息
  du -sh /mnt/###查看设备的使用情况
  fuser -vm /dev/sdb1###
$ fuser -vm /dev/sdb1
$

  

# updatedb    ###更新数据库
# locate westos   ###查找westos文件,locate查找不准确,locate只在数据库里面查找,所以要更新数据路库
# touch /boot/westos
# locate westos
# updatedb
# locate westos
  /boot/westos
# rm -fr /boot/westos
# locate westos
  /boot/westos
# ll /boot/westos
  ls: cannot access /boot/westos: No such file or directory
# cat /boot/westos
  cat: /boot/westos: No such file or directory
# updatedb
# cat /boot/westos
  cat: /boot/westos: No such file or directory
# locate westos
#
  

# cd /mnt
# ls
# touch file{1..5}
# 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
# grep bash /etc/passwd    ###查看用户本机所有用户信息
  root:x:0:0:root:/root:/bin/bash
  student:x:1000:1000:Student User:/home/student:/bin/bash
# useradd westos
# useradd lee
# chown westos file1   ###更改文件file1所属用户为westsos
# chown lee file2
# chown westos.lee file3   ##3更改文件file3所属用户为westos所属组为lee
# chown lee.lee file4
# 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 lee0 Oct 12 21:53 file3
  -rw-r--r--. 1 lee    lee0 Oct 12 21:53 file4
  -rw-r--r--. 1 root   root 0 Oct 12 21:53 file5
# find /mnt/ -user westos    ###查找属于用户westos的文件
  /mnt/file1
  /mnt/file3
# find /mnt/ -group root   ###查找属于组root的文件
  /mnt/
  /mnt/file1
  /mnt/file2
  /mnt/file5
# ll -d /mnt/   ###查看目录信息
  drwxr-xr-x. 2 root root 66 Oct 12 21:53 /mnt/
# find /mnt/ -group lee -a -user westos    ###查找属于组lee并且属于用户westos的
  /mnt/file3
# find /mnt/ -not -group lee -a -not -user westos   ###查找不再组lee并且不属于用古westos的
  /mnt/
  /mnt/file2
  /mnt/file5
  

  ###############################
# 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
# 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
# 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
# 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
# find /mnt/ -size 20k   ###查找文件大小为20k的
  /mnt/file2
# find /mnt/ -size -20k    ###查找文件小于20k的
  /mnt/
  /mnt/file1
# find /mnt/ -size +20k    ###查找文件大于20k的
  /mnt/file3
# find /mnt/ -size -20k -a -type f   ###查找文件小于20k
  /mnt/file1
# find /mnt/ -size -20k -a -type d   ###查找目录小于20k
  /mnt/
#
  ##############################
# chmod 000 /mnt/*   ###更改/mnt/下所有文件的权限为0
# 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
# chmod 444 file1   ###更改文件file1的权限
# chmod 404 file2
# 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
# find /mnt -perm 444   ###查找文件权限等于444的文件,permission
  /mnt/file1
# find /mnt -perm -444   ###查找权限大于和等于444文件的
  /mnt
  /mnt/file1
# find /mnt -perm /444
  /mnt
  /mnt/file1
  /mnt/file2
# find /mnt -perm /755   ###斜杠后面跟的数字越大,找到满足条件的文件会越多,以为他是或的关系,只要7个条件中有一个满足就可以
  /mnt
  /mnt/file1
  /mnt/file2
# urwx grx orx^C
  ####################################################
  perm 444###文件权限必须是rrr
  perm -444   ###文件每一位都要含有r权限
  perm /444   ###文件任意一位含有r权限
  -maxdepth 数字   ###最深目录层
  -mindepth 数字   ###最浅目录层
  -exec命令 {} \   ###对查找出的结果做相应的处理
# find /etc/ -maxdepth 2 -mindepth 2 -name ^C
# find /etc/ -name passwd###查找文件名为passwd的文件
  /etc/passwd
  /etc/pam.d/passwd
# find /etc/ -maxdepth 1 -name passwd###查找目录深度为1的文件名为passwd的文件
  /etc/passwd
# find /etc/ -maxdepth 2 -name passwd###查找目录深度为2以内(包括深度为1的)的文件名为passwd的文件
  /etc/passwd
  /etc/pam.d/passwd
# find /etc/ -maxdepth 2 -mindepth 2 -name passwd   ###查找最大深度是2最小深度也是2的文件名为passwd的文件
  /etc/pam.d/passwd
# find /etc/ -maxdepth 2 -mindepth 2 -name passwd -exec cp {} /mnt \; ###查找最大深度是2最小深度也是2的文件名是passwd的文件,并且把它复制到/mnt目录下
# ls###查看刚才复制过来的文件
  file1file2file3passwd
# find /mnt/ -perm -444 -exec rm -fr {} \;   ###查找文件权限是444并且删除所有
  find: ‘/mnt/’: No such file or directory
#
# ls
#
  软连接就是快捷方式,建立软链接的目的是为了节省设备存储
  硬链接就是把文件重新复制一次,只有文件的内容没有文件的属性
# touch file
# ln -s /mnt/file /mnt/westos###soft指的软链接
# 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
# rm -fr file
# cat /mnt/westos   ###删掉文件之后,软链接也不可用
  cat: /mnt/westos: No such file or directory
# rm -fr *
# touch file
# ln /mnt/file /mnt/westos    ###创建硬链接,
# 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
# ln /mnt/file /mnt/westos1
# 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
# rm -fr westos1
# 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
# rm -fr westos
# ll
  total 0
  -rw-r--r--. 1 root root 0 Oct 12 23:17 file
# rm -fr file
# ll
  total 0
# ls -li *###查看节点信息
  virt-manager ###安装虚拟机
  ls -i ###查看设备的节点号
# virt-manager   ###弹出虚拟机管理界面
# virt-viewer desktop###立即弹出desktop虚拟机界面
# virt-manager test11
# 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
#
# virsh list   ###列出所有虚拟机信息
  Id    Name                           State
  ----------------------------------------------------
  2   desktop                        paused
  3   server                         paused
  8   test11                         running
# virsh list --all
  Id    Name                           State
  ----------------------------------------------------
  2   desktop                        paused
  3   server                         paused
  8   test11                         running
# virsh destroy test11   ###立即关闭虚拟机
  Domain test11 destroyed
  

# virsh start test11   ###开启虚拟机
# virsh shutdown test11   ###关闭虚拟机
  Domain test11 started
# cd /var/lib/libvirt/images   ###进入虚拟机文件存放目录
# ls   ###查看所有可用源镜像
  rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2
  rh124-desktop-vda.qcow2rh124-server-vda.ovl    rh124-server.xml
  rh124-desktop-vdb.ovl    rh124-server-vda.qcow2rhel7.0.qcow2
  rh124-desktop-vdb.qcow2rh124-server-vdb.ovl
# 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
# ls   ###查看新建的快照
  rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2
  rh124-desktop-vda.qcow2rh124-server-vda.ovl    rh124-server.xml
  rh124-desktop-vdb.ovl    rh124-server-vda.qcow2rhel7.0.qcow2
  rh124-desktop-vdb.qcow2rh124-server-vdb.ovl    test1.qcow2
# du -sh test1.qcow2   ###查看快照的大小信息
  196Ktest1.qcow2
  ####################################################################
  然后新建虚拟机,选择已有镜像
  

  

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

# 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
#
# 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]
查看完整版本: linux redhat 虚拟机