三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

CentOS下判断自己的服务器是物理机还是VPS

三三 2021-11-18 2198 0条评论 服务器配置Linux使用 centosvps平台技术容器kvm技术

首页 / 正文

CentOS下想要判断自己的服务器是物理机还是VPS或者云服务器,这种情况就是判断一下vps的技术,如果不是vps的话就不会反馈结果。

一般来说,VPS的虚拟化技术,有Xen、OpenVZ、Xen HVM和VMware这几种,那么,如何判断自己的VPS是基于哪种虚拟化技术的呢?

1、执行:ls /proc/命令,一般Xen的VPS,/proc目录下面会有xen的目录,openvz的会有vz目录。

2、执行:free -m命令看内存,openvz的没有swap,当然也有xen的没有swap,但是xen的是可以加的,openvz不行。

3、执行:uname -a命令,有些xen的VPS里面会显示有xen。

4、执行:ifconfig 或者 ip addr 命令查看网卡,openvz的一般都是venet0: ,xen的一般都是eth

5、通过VPS控制面板查看,像SolusVM、vePortal控制面板上都显示虚拟技术。

6、使用专门的软件命令:

virt-what

virt-what是一个判断当前环境所使用的虚拟技术的脚本,常见的虚拟技术比如openvz,xen,kvm基本上都能正常识别出来。

可以执行如下命令安装(需要安装好gcc、make):

wget http://people.redhat.com/~rjones/virt-what/files/virt-what-1.9.tar.gz
tar zxvf virt-what-1.9.tar.gz
cd virt-what-1.9/
./configure
make && make install

再运行 virt-what ,脚本就会判断出当前环境所使用的虚拟技术

7、执行systemd-detect-virt

systemd-detect-virt   //执行该命令
kvm   //33的是阿里云的kvm技术

8、还可以使用dmidecode -t system来查看系统信息。

dmidecode -t system    //执行命令

输出结果:

# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
        Manufacturer: Alibaba Cloud
        Product Name: Alibaba Cloud ECS
        Version: pc-i440fx-2.1
        Serial Number: 111-556a-47e6-a1d8-666
        UUID: 111-556a-47e6-a1d8-666
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Not Specified

Handle 0x2000, DMI type 32, 11 bytes
System Boot Information
        Status: No errors detected

9、docker容器

a、如果是虚拟机中安装的操作系统中运行docker,则systemd-detect-virt和dmidecode -t system在容器中是失效的
b、可以通过docker容器根分区专用的文件系统类型overlay来判断:

[root@33f /]# df -h / | grep overlay
overlay          100G   25G   23G  25% /

如果根分区文件系统是ovlerlay,表示是在docker容器中
c、通过dockerenv文件判断

[root@33f /]# ls /.dockerenv 
/.dockerenv

如果存在/.dockerenv文件,则是在docker容器中
d、根据/proc/1/cgroup是否包含docker字样判断

[root@centos /]# cat /proc/1/cgroup | grep docker

11:pids:/docker/ebe4fe937bb53c80227cb4772ea73888c381f639f97bee95ab06f0b976998286
1:name=systemd:/docker/ebe4fe937bb53c80227cb4772ea73888c381f639f97bee95ab06f0b976998286
/docker/ebe4fe937bb53c80227cb4772ea73888c381f639f97bee95ab06f0b976998286/init.scope

进程1的控制组是包含有docker的字样


#systemd-detect-virt的用法

1,列出支持检测的虚拟环境

[root@33f /]# systemd-detect-virt --list
none
kvm
qemu
bochs
xen
uml
vmware
oracle
microsoft
zvm
parallels
bhyve
qnx
vm-other
systemd-nspawn
lxc-libvirt
lxc
openvz
docker
rkt
container-other

2,非虚拟机或容器环境时,返回none

[root@33f /]# systemd-detect-virt
none

3,systemd-detect-virt查看版本

[root@33f /]# systemd-detect-virt --version      
systemd 239
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=legacy

4,只检测虚拟机

[root@33f /]# systemd-detect-virt -v 
vmware

5,只检测容器

[root@33f /]# systemd-detect-virt -c 
docker

说明:如果是虚拟机中的容器会检测不到

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年05月

   1234
567891011
12131415161718
19202122232425
262728293031 

文章目录

上一张 下一张