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

相关文章

基于Python实现高效PPT转图片工具

《基于Python实现高效PPT转图片工具》在日常工作中,PPT是我们常用的演示工具,但有时候我们需要将PPT的内容提取为图片格式以便于展示或保存,所以本文将用Python实现PPT转PNG工具,希望... 目录1. 概述2. 功能使用2.1 安装依赖2.2 使用步骤2.3 代码实现2.4 GUI界面3.效

MySQL更新某个字段拼接固定字符串的实现

《MySQL更新某个字段拼接固定字符串的实现》在MySQL中,我们经常需要对数据库中的某个字段进行更新操作,本文就来介绍一下MySQL更新某个字段拼接固定字符串的实现,感兴趣的可以了解一下... 目录1. 查看字段当前值2. 更新字段拼接固定字符串3. 验证更新结果mysql更新某个字段拼接固定字符串 -

java实现延迟/超时/定时问题

《java实现延迟/超时/定时问题》:本文主要介绍java实现延迟/超时/定时问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java实现延迟/超时/定时java 每间隔5秒执行一次,一共执行5次然后结束scheduleAtFixedRate 和 schedu

Java Optional避免空指针异常的实现

《JavaOptional避免空指针异常的实现》空指针异常一直是困扰开发者的常见问题之一,本文主要介绍了JavaOptional避免空指针异常的实现,帮助开发者编写更健壮、可读性更高的代码,减少因... 目录一、Optional 概述二、Optional 的创建三、Optional 的常用方法四、Optio

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

Redis实现延迟任务的三种方法详解

《Redis实现延迟任务的三种方法详解》延迟任务(DelayedTask)是指在未来的某个时间点,执行相应的任务,本文为大家整理了三种常见的实现方法,感兴趣的小伙伴可以参考一下... 目录1.前言2.Redis如何实现延迟任务3.代码实现3.1. 过期键通知事件实现3.2. 使用ZSet实现延迟任务3.3

基于Python和MoviePy实现照片管理和视频合成工具

《基于Python和MoviePy实现照片管理和视频合成工具》在这篇博客中,我们将详细剖析一个基于Python的图形界面应用程序,该程序使用wxPython构建用户界面,并结合MoviePy、Pill... 目录引言项目概述代码结构分析1. 导入和依赖2. 主类:PhotoManager初始化方法:__in

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

SpringBoot利用@Validated注解优雅实现参数校验

《SpringBoot利用@Validated注解优雅实现参数校验》在开发Web应用时,用户输入的合法性校验是保障系统稳定性的基础,​SpringBoot的@Validated注解提供了一种更优雅的解... 目录​一、为什么需要参数校验二、Validated 的核心用法​1. 基础校验2. php分组校验3