VMware Tools 简介
VMware Tools 中包含一系列服务和模块,可在 VMware 产品中实现多种功能,从而使用户能够更好地管理客户机操作系统,以及与客户机操作系统进行无缝交互。
VMware Tools 具备以下功能:
- 将消息从主机操作系统传递到客户机操作系统。
- 将客户机操作系统作为 vCenter Server 及其他 VMware 产品的组成部分进行自定义。
- 运行有助于实现客户机操作系统自动化运行的脚本。这些脚本在虚拟机的电源状态改变时运行。
- 在客户机操作系统与主机操作系统之间同步时间。
一键安装vmtools
- 兼容Centos/Redhat 及复刻系列,ubuntu ,suse
vi /vmtools_install.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: CIASM
# update 2023/10/11
# increase indent:Tab
# decrease indent:Shift+Tab
# install source vm-tools<<!
# ubuntu To execute this script
ln -sf bash /bin/sh
!install_basics() {# Check if the script is being run as root
if [ "$(id -u)" != "0" ]; thenecho "This script must be run as root."exit 1
fi# Check the CentOS/Red Hat version
if [[ -f /etc/redhat-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the oralce Linux version
elif [[ -f /etc/oracle-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the Rock Linux version
elif [[ -f /etc/rocky-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the AlmaLinux version
elif [[ -f /etc/almalinux-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the ubuntu version
elif [[ -f /etc/os-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the suse version
elif [[ -f /etc/SuSE-release ]]; thenOS=$( cat /etc/*release* | grep "^PRETTY_NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+\.[0-9]+' | head -n1)# Check the Debian version
elif [[ -f /etc/os-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+' | head -n1)# Check the Fedora version
elif [[ -f /etc/fedora-release ]]; thenOS=$(cat /etc/*release* | grep "^NAME=" | cut -d'=' -f2- | tr -d '"')VERSION=$(cat /etc/*release* | grep -oE '[0-9]+' | head -n1)elseecho -e "\033[31m This script only supports $OS $VERSION...\033[0m"exit 1
fi# Check the vmtools version
if ! command -v vmtoolsd &> /dev/null; thenecho -e "\033[32m Installing vmtools for $OS $VERSION...\033[0m"case $VERSION in# CentOS/RedHat/oracle 7 install7.?)echo Installing basics...yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmyum install -y open-vm-toolsinstall_all_vmtools;;# CentOS/RedHat/oracle/RockLinux/AlmaLinux 8 install 8.?)echo Installing basics...yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpmyum install -y open-vm-toolsinstall_all_vmtools;;# CentOS/RedHat/oracle/RockLinux/AlmaLinux 9 install9.?) echo Installing basics...yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpmyum install -y open-vm-toolsinstall_all_vmtools;;# ubuntu 20.04 Linux install20.04)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;# ubuntu 21 Linux install21.04|21.10)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;# ubuntu 22 Linux install22.04)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;# Debian 10, 11 , 1210)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;11)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;12)echo Installing basics...sudo apt install -y open-vm-toolsinstall_all_vmtools;;# Fedora 31,32,3336|37|38)echo Installing basics...yum install -y open-vm-toolsinstall_all_vmtools;;# SUSE 12 install12.?)echo Installing basics...sudo SUSEConnect -p sle-sdk/12.4/x86_64zypper in -y open-vm-toolsinstall_all_vmtools;;# SUSE 15 install15.?)echo Installing basics...sudo SUSEConnect -p sle-sdk/15.3/x86_64zypper in -y open-vm-toolsinstall_all_vmtools;;*)echo -e "\033[31m Unsupported $OS $VERSION...\033[0m" exit 1;;
esacecho -e "\033[32m vmtools for $OS $VERSION successfully installed...\033[0m"
elseecho -e "\033[33m vmtools for $OS $VERSION already installed...\033[0m"
fi}install_all_vmtools() {
echo "install vm-tools"
systemctl enable --now vmtoolsd.service# start vmtools
systemctl start vmtoolsd#check vmtools version
vmtoolsd -v | awk '{print $5}'# check vmtoolsd service state
systemctl status vmtoolsd | grep "Active" | awk '{print $3}' | tr -d "()"
}main (){install_basics
}main
执行安装
sh /vmtools_install.sh