Linux Shell 实现一键部署vmtools

2023-10-12 08:04

本文主要是介绍Linux Shell 实现一键部署vmtools,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

这篇关于Linux Shell 实现一键部署vmtools的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/194469

相关文章

linux生产者,消费者问题

pthread_cond_wait() :用于阻塞当前线程,等待别的线程使用pthread_cond_signal()或pthread_cond_broadcast来唤醒它。 pthread_cond_wait() 必须与pthread_mutex 配套使用。pthread_cond_wait()函数一进入wait状态就会自动release mutex。当其他线程通过pthread

C++对象布局及多态实现探索之内存布局(整理的很多链接)

本文通过观察对象的内存布局,跟踪函数调用的汇编代码。分析了C++对象内存的布局情况,虚函数的执行方式,以及虚继承,等等 文章链接:http://dev.yesky.com/254/2191254.shtml      论C/C++函数间动态内存的传递 (2005-07-30)   当你涉及到C/C++的核心编程的时候,你会无止境地与内存管理打交道。 文章链接:http://dev.yesky

Linux 安装、配置Tomcat 的HTTPS

Linux 安装 、配置Tomcat的HTTPS 安装Tomcat 这里选择的是 tomcat 10.X ,需要Java 11及更高版本 Binary Distributions ->Core->选择 tar.gz包 下载、上传到内网服务器 /opt 目录tar -xzf 解压将解压的根目录改名为 tomat-10 并移动到 /opt 下, 形成个人习惯的路径 /opt/tomcat-10

RedHat运维-Linux文本操作基础-AWK进阶

你不用整理,跟着敲一遍,有个印象,然后把它保存到本地,以后要用再去看,如果有了新东西,你自个再添加。这是我参考牛客上的shell编程专项题,只不过换成了问答的方式而已。不用背,就算是我自己亲自敲,我现在好多也记不住。 1. 输出nowcoder.txt文件第5行的内容 2. 输出nowcoder.txt文件第6行的内容 3. 输出nowcoder.txt文件第7行的内容 4. 输出nowcode

【Linux进阶】UNIX体系结构分解——操作系统,内核,shell

1.什么是操作系统? 从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境。我们通常将这种软件称为内核(kerel),因为它相对较小,而且位于环境的核心。  从广义上说,操作系统包括了内核和一些其他软件,这些软件使得计算机能够发挥作用,并使计算机具有自己的特生。这里所说的其他软件包括系统实用程序(system utility)、应用程序、shell以及公用函数库等

UnrealScriptIDE调试环境部署

先安装vs2010   再安装VSIsoShell.exe, 下载地址 https://pan.baidu.com/s/10kPNUuDGTbWXbz7Nos-1WA       fd3t   最后安装unside,下载地址 https://archive.codeplex.com/?p=uside  安装中间有一步选择Binary文件夹要选对路径。   安装好以后,启动 UDKDe

通过SSH隧道实现通过远程服务器上外网

搭建隧道 autossh -M 0 -f -D 1080 -C -N user1@remotehost##验证隧道是否生效,查看1080端口是否启动netstat -tuln | grep 1080## 测试ssh 隧道是否生效curl -x socks5h://127.0.0.1:1080 -I http://www.github.com 将autossh 设置为服务,隧道开机启动

Windows/macOS/Linux 安装 Redis 和 Redis Desktop Manager 可视化工具

本文所有安装都在macOS High Sierra 10.13.4进行,Windows安装相对容易些,Linux安装与macOS类似,文中会做区分讲解 1. Redis安装 1.下载Redis https://redis.io/download 把下载的源码更名为redis-4.0.9-source,我喜欢跟maven、Tomcat放在一起,就放到/Users/zhan/Documents

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测 目录 时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测基本介绍程序设计参考资料 基本介绍 MATLAB实现LSTM时间序列未来多步预测-递归预测。LSTM是一种含有LSTM区块(blocks)或其他的一种类神经网络,文献或其他资料中LSTM区块可能被描述成智能网络单元,因为

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主