linux命令总结

来源:互联网 发布:mac 日历 垃圾信息 编辑:程序博客网 时间:2024/06/06 00:40
1 yum
yum命令的使用,必须有文件kvm.repo  完整路径/etc/yum.repos.d/kvm.repo
yum install package_name 安装软件包
problem:
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
出现上面的problem时,就是需要拷贝kvm.repo 文件
1)yum install * 安装所有文件

2 pwd 查看当前工作目录的完整路径
# pwd
/home/fio-2.1.2

3 qemu进行系统仿真  
1)创建qcow2镜像文件
# qemu-img create -f qcow2 /home/system-img.qcow2 30G
Formatting '/home/system-img.qcow2', fmt=qcow2 size=32212254720 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
2)查看磁盘信息
# qemu-img info /home/test2.qcow2
image: /home/test2.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
3)更改磁盘容量
#qemu-img resize test2.qcow2 40G
Image resized.

4 df 查看文件系统大小的命令
# df -h
Filesystem                                    Size  Used Avail Use% Mounted on
devtmpfs                                      1.8G     0  1.8G   0% /dev
tmpfs                                         1.8G     0  1.8G   0% /dev/shm
tmpfs                                         1.8G  1.1M  1.8G   1% /run
tmpfs                                         1.8G     0  1.8G   0% /sys/fs/cgroup
/dev/mapper/fedora--server_dhcp--11--36-root   50G  4.4G   46G   9% /
tmpfs                                         1.8G  708K  1.8G   1% /tmp
/dev/sda1                                     477M   95M  353M  22% /boot
/dev/mapper/fedora--server_dhcp--11--36-home  244G   33M  244G   1% /home
tmpfs

5 brctl网桥配置命令
# brctl show
bridge name    bridge id        STP enabled    interfaces
virbr0        8000.525400928d34    yes        virbr0-nic
# brctl addbr swith 增加一个网桥,名字叫switch
bridge name    bridge id        STP enabled    interfaces
swith        8000.000000000000    no        
virbr0        8000.525400928d34    yes        virbr0-nic

6 switch 命令
# ovs-vsctl show
6c282ecb-f532-494c-92c4-14d15805cfdd
    Bridge switch
        Port "tap0"
            Interface "tap0"
        Port switch
            Interface switch
                type: internal
        Port "eno1"
            Interface "eno1"
    ovs_version: "2.3.1-git3282e51"
# ovs-vsctl del-br switch 删除名字为switch的交换机

7 有关进程
查看进程的状态
# ps -ef|grep tgtd
关闭一个进程
kill -9 加进程号

8 查看硬件分区情况
# fdisk -l
分区命令
# fdisk /dev/sda

10 install fio
download fio package
解压
bzip2 -d fio-2.1.2.tar.bz2
tar -xf fio-2.1.2.tar
./configure, make, make install
install libaio-devel.x86_64

11 创建镜像文件iso
#mkisofs -o /home/cdimg1.iso pkgs/
#du -sh /home/cdimg1.iso  读取文件大小
1.0G    /home/cdimg1.iso

12 文件解压命令
1)对于.tar结尾的文件
tar -xf all.tar
2)对于.gz结尾的文件
gzip -d all.gz
gunzip all.gz
3)对于.tgz或.tar.gz结尾的文件
tar -xzf all.tar.gz
tar -xzf all.tgz
4)对于.bz2结尾的文件
bzip2 -d all.bz2
bunzip2 all.bz2
5)对于tar.bz2结尾的文件
tar -xjf all.tar.bz2
6)对于.Z结尾的文件
uncompress all.Z
7)对于.tar.Z结尾的文件
tar -xZf all.tar.z

13三种查看帮助文档的方式
# /usr/libexec/qemu-kvm -device ?可以看到支持哪些设备
# /usr/libexec/qemu-kvm -device virtio-blk-pci,?该设备支持哪些参数
# man qemu-kvm

14 查看软件版本
查看kernel版本
# uname -r
查看qemu版本
# rpm -qa|grep qemu
15 rpm命令
#rpm -e qemu-kvm-debuginfo-0.12.1.2-2.475.el6.x86_64 卸载冲突文件
#rpm -U *.rpm 升级下载的包rpm
#rpm -U *.rpm --oldpackage降级rpm
16如何获得系统镜像文件
# mount 10.66.90.128:/vol/S2/kvmauto /mnt
将服务器上的文件挂载到本地
#cd /mnt &&cd linux_img
ls
里面是镜像文件
17dmesg |grep -i error 检查host是否正常工作
18 如何获取软件的安装包名
对于已有命令查看其安装包
#dmesg |less
# mkfs.
mkfs.btrfs    mkfs.ext3     mkfs.fat      mkfs.msdos    mkfs.xfs
mkfs.cramfs   mkfs.ext4     mkfs.hfsplus  mkfs.ntfs     
mkfs.ext2     mkfs.ext4dev  mkfs.minix    mkfs.vfat     
# which mkfs.xfs
/sbin/mkfs.xfs
# rpm -qf /sbin/mkfs.xfs
xfsprogs-3.2.2-1.fc22.x86_64
当host上没有这个命令时,如何安装它的包,
google上搜索mkfs rpm搜索到这个命令的包名
#yum search xfsprogs 查看是否有此安装包
19 模块命令
# modprobe floppy增加模块floppy
modprobe -r floppy 删除模块floppy
# lsmod 查看模块的命令
# lsmod | grep floppy 定向查找相当于crtl+f命令的操作:
floppy                 69417  0
20 对于guest上没有ip地址的解决方法
查看网络是否网线是否连接
#ethtool eth0
Settings for eth0
         Link detected:yes
已经连接上的情况下,获取ip地址
#dhclient eth0
如此便已经获得了ip地址
21 如何正确dd入磁盘
# dd if=/dev/zero of=/mnt/sda/a bs=1M count=2000

mnt下有sda目录,而sda下没有a,所以说a是输出的数据

22 在所有文档中搜索device_add
grep "device_add" -r ./*
23 cp复制整个目录下的数据
#cp -r /etc/ /tmp 复制/etc/这个目录下的所有内容到/tmp底下
24 多个目录的删除
1)# rm -r a
rm: descend into directory ‘a’? y
rm: remove directory ‘a/b’? y
rm: remove directory ‘a’? y
目录a下有目录b,用-r来逐级删除
2)删除多个文件,不需要询问
# \rm -r /tmp/etc
在前加上反斜杠
25{"execute":"query-commands"}
查询qmp中所有命令
{"execute":"qmp_capabilities"}
{"return": {}}
26 如何用tree装guest
打开isolinux
下载:initrd.img
     vmlinuz
/usr/libexec/qemu-kvm -m 4G -smp 4 -M pc-i440fx-rhel7.2.0 -boot menu=on -drive file=/home/sys-ya,if=none,id=img -device virtio-scsi-pci,id=scsi1,bus=pci.0 -device scsi-hd,drive=img,bus=scsi1.0,id=sys-disk -monitor stdio -spice port=5931,disable-ticketing -netdev tap,id=tap0,script=/etc/qemu-ifup -device virtio-net-pci,netdev=tap0,mac=24:be:05:14:95:16 -kernel /home/vmlinuz -initrd /home/initrd.img -append method=http://download.englab.nay.redhat.com/nightly/RHEL-7.2-20150618.n.0/compose/Server/x86_64/os
27没有ifconfig的命令可以用ip addr show取代
28 如何用tree来装host
# cat /root/anaconda-ks.cfg 查看现在装的host的信息
在http://download.englab.nay.redhat.com/pub/rhel/nightly/latest-RHEL-7/compose/Server/x86_64/os/isolinux/
下载:
vmlinuz和initrd.img放在host的boot下
1)# cd /boot/
2)# wget http://download.englab.nay.redhat.com/pub/rhel/nightly/latest-RHEL-7/compose/Server/x86_64/os/isolinux/vmlinuz http://download.englab.nay.redhat.com/pub/rhel/nightly/latest-RHEL-7/compose/Server/x86_64/os/isolinux/initrd.img
修改以下配置文件
3)# vim /boot/grub2/grub.cfg

  修改位置为:
  fi
        linux16 /vmlinuz method=http://download.englab.nay.redhat.com/pub/rhel/nightly/latest-RHEL-7/compose/Server/x86_64/os
        initrd16 /initrd.img

主要method后加tree的地址

29没有ifconfig命令的解决方法:
1)# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
2)# yum search ifconfig
============================== Matched: ifconfig ===============================
net-tools.x86_64 : Basic networking tools
3)# yum install net-tools.x86_64
这样ifconfig便安装上了

29 如果remote-viewer spice://10.66.8.118:5931
unconnect
则在host上#iptables -F
关掉防火墙即可

30 对于machine type为q35,要用pcie.0。用.pci.0会出错
31 对于macvtap0方式下起guest的命令
# /usr/libexec/qemu-kvm -m 2G -object memory-backend-ram,host-nodes=0,policy=bind,id=mem-0,size=2048M,prealloc=yes -numa node,memdev=mem-0 -machine pc-q35-rhel7.2.0 -drive file=/home/RHEL-Server-7.1-64-virtio-scsi.qcow2,if=none,id=img -device virtio-scsi-pci,id=scsi1,bus=pcie.0 -device scsi-hd,drive=img,bus=scsi1.0,id=sys-disk,bootindex=1 -monitor stdio -spice port=5931,disable-ticketing -netdev tap,id=tap0,fd=18 18<>/dev/tap6 -device virtio-net-pci,netdev=tap0,mac=fa:41:fe:5e:31:65


mac地址要与ifconfig下macvtap0:下的地址一致
# ip a s 查看到6: macvtap0@eno1:,所以fd写为:fd=18 18<>/dev/tap6

32网卡问题
1 boot a guest

problem:

/etc/qemu-ifup: could not launch network script
qemu-kvm: -netdev tap,id=tap0,script=/etc/qemu-ifup: Device 'tap' could not be initialized

solution:

1.检查tun模块是否编译进去
modprobe tun;lsmod | grep tun
内核配置选项为:
Device Driver --> Networking support --> Universal TUN/TAP device driver support
2.检查/dev/net/tun权限
 ls -l /dev/net/tun
如果没有/dev/net/tun可以通过如下方式新建
mkdir /dev/net
mknod /dev/net/tun c 10 200
chmod 666 /dev/net/tun
3.检查/etc/qemu-ifup权限
chmod 777 /etc/qemu-ifdown
chmod 777 /etc/qemu-ifup

33 只读文件的拷贝问题
# cat smaps >/root/smaps  先重定向只读文件,再进行拷贝

34 测试编译时间
#time make -j 8

35 问题    libtcmalloc.so.4()(64bit) is needed by qemu-kvm-common-rhev-10:2.3.0-9.el7.x86_64的解决
安装
gperftools-2.4-1.el7中的yum install gperftools-libs-2.4-1.el7.x86_64.rpm

36 linux中删除文件中所有内容的命令
# rm -rf *

37 vcpu线程号的获得
(qemu) info cpus
* CPU #0: pc=0xffffffff81057e56 (halted) thread_id=9957
  CPU #1: pc=0xffffffff81057e56 (halted) thread_id=9958
  CPU #2: pc=0xffffffff81057e56 (halted) thread_id=9959
  CPU #3: pc=0xffffffff81057e56 (halted) thread_id=9960
  CPU #4: pc=0xffffffff81057e56 (halted) thread_id=9961
  CPU #5: pc=0xffffffff81057e56 (halted) thread_id=9962
  CPU #6: pc=0xffffffff81057e56 (halted) thread_id=9963
  CPU #7: pc=0xffffffff81057e56 (halted) thread_id=9964

38 安装qemu-kvm-rhev 遇到libtcmalloc.so.4()(64bit)的解决方法
1)install:gperftools-libs-2.4-1.el7.x86_64.rpm
当有如下问题时:
Error: Package: gperftools-libs-2.4-1.el7.x86_64 (/gperftools-libs-2.4-1.el7.x86_64)
           Requires: libunwind.so.8()(64bit)
2)install:
libunwind-1.1-2.el7.x86_64.rpm            
libunwind-devel-1.1-2.el7.x86_64.rpm
libunwind-debuginfo-1.1-2.el7.x86_64.rpm
可以成功安装.
39历史命令查找的方式
vim ~/.bash_history


40  service iptables stop 不成功的解决方案
# service iptables stop
Redirecting to /bin/systemctl stop  iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.

solution:
安装iptables
iptables-1.4.21-14.el7.x86_64.rpm
iptables-debuginfo-1.4.21-14.el7.x86_64.rpm
iptables-devel-1.4.21-14.el7.x86_64.rpm
iptables-services-1.4.21-14.el7.x86_64.rpm
iptables-utils-1.4.21-14.el7.x86_64.rpm


40 以下问题的解决方法:
# echo 8086 1515 > /sys/bus/pci/drivers/vfio-pci/new_id
-bash: /sys/bus/pci/drivers/vfio-pci/new_id: No such file or directory
需要加载模块
# lsmod|grep vfio
# modprobe vfio
# modprobe vfio-pci

41 scsi_id命令找不到的解决方法
下载安装udev包
# /lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/sdb
路径是关键
42 qemu下删除数据盘的命令
(qemu)device_del 数据盘id号
43 安装guest时,一定要加上-boot menu=on.否则会卡在蓝屏那儿。
44 解壓rpm文件的方法
rpm2cpio kernel-3.10.0-300.el7.src.rpm | cpio -div 解压rpm文件
45 如何控制guest信息的輸出
/usr/libexec/qemu-kvm -m 1024 -boot menu=on -drive file=/home/RHEL-Server-7.2-64-virtio.qcow2-bug,if=none,id=img -device virtio-blk-pci,drive=img,id=sys-img,bootindex=1 -drive file=/home/test.qcow2,if=none,id=drive-hostdev0 -device virtio-blk-pci,bus=pci.0,drive=drive-hostdev0,id=hostdev0 -monitor stdio -spice port=5932,disable-ticketing -netdev tap,id=tap0 -device virtio-net-pci,netdev=tap0,mac=24:be:05:14:95:12 -qmp tcp::8887,server,nowait -serial unix:/tmp/console,server,nowait
命令行要加上-serial unix:/tmp/console,server,nowait
在host端採用窗口登陸的方式:
# nc -U /tmp/console
在vim /boot/grub2/grub.cfg  在guest端

linux16 /vmlinuz-3.10.0-224.el7.x86_64.debug root=/dev/mapper/rhel_unused-root ro rd.lvm.lv=rhel_unused/swap console=tty0 net.ifnames=0 console=ttyS0,115200 crashkernel=auto rd.lvm.lv=rhel_unused/root biosdevname=0 LANG=en_US.UTF-8 systemd.debug console=tty0 console=ttyS0,115200

加了console=tty0 console=ttyS0,115200

46 host与guest传驱动
1)iso的方式:
在guest命令行下加载:-cdrom /usr/share/virtio-win/virtio-win-1.5.3.iso
2)软盘的方式:-fda /usr/share/virtio-win/virtio-win-1.5.3.vfd
47 perror 需要安装的包
mariadb-server-5.5.41-2.el7_0.x86_64

48stop nfs service:
# /bin/systemctl stop  nfs.service


0 0
原创粉丝点击