在Linux实例上自动安装并运行VNC Server
#!/bin/bash
#########################################
#Function: install vnc server
#Usage: bash install_vnc_server.sh
#Author: Customer service department
#Company: Alibaba Cloud Computing
#Version: 3.0
######################################### check_os_release()
{
while true
do
os_release=$(grep "Red Hat Enterprise Linux Server release" /etc/issue >/dev/null)
os_release_2=$(grep "Red Hat Enterprise Linux Server release" /etc/redhat-release >/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "release 5" >/dev/null >&
then
os_release=redhat5
echo "$os_release"
elif echo "$os_release"|grep "release 6" >/dev/null >&
then
os_release=redhat6
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
os_release=$(grep "Aliyun Linux release" /etc/issue >/dev/null)
os_release_2=$(grep "Aliyun Linux release" /etc/aliyun-release >/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "release 5" >/dev/null >&
then
os_release=aliyun5
echo "$os_release"
elif echo "$os_release"|grep "release 6" >/dev/null >&
then
os_release=aliyun6
echo "$os_release"
elif echo "$os_release"|grep "release 7" >/dev/null >&
then
os_release=aliyun7
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
os_release_2=$(grep "CentOS" /etc/*release 2>/dev/null)
if [ "$os_release_2" ]
then
if echo "$os_release_2"|grep "release 5" >/dev/null 2>&1
then
os_release=centos5
echo "$os_release"
elif echo "$os_release_2"|grep "release 6" >/dev/null 2>&1
then
os_release=centos6
echo "$os_release"
elif echo "$os_release_2"|grep "release 7" >/dev/null 2>&1
then
os_release=centos7
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
os_release=$(grep -i "ubuntu" /etc/issue 2>/dev/null)
os_release_2=$(grep -i "ubuntu" /etc/lsb-release 2>/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "Ubuntu 10" >/dev/null 2>&1
then
os_release=ubuntu10
echo "$os_release"
elif echo "$os_release"|grep "Ubuntu 12.04" >/dev/null 2>&1
then
os_release=ubuntu1204
echo "$os_release"
elif echo "$os_release"|grep "Ubuntu 12.10" >/dev/null 2>&1
then
os_release=ubuntu1210
echo "$os_release"
elif echo "$os_release"|grep "Ubuntu 14.04" >/dev/null 2>&1
then
os_release=ubuntu1204
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
os_release=$(grep -i "debian" /etc/issue 2>/dev/null)
os_release_2=$(grep -i "debian" /proc/version 2>/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "Linux 6" >/dev/null 2>&1
then
os_release=debian6
echo "$os_release"
elif echo "$os_release"|grep "Linux 7" >/dev/null 2>&1
then
os_release=debian7
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
break
done
} exit_script()
{
echo -e "\033[1;40;31mInstall $1 error,will exit.\n\033[0m"
rm -f $LOCKfile
exit 1
} update_source()
{
wget "http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/41177/cn_zh/1504061676920/update_source.sh" -O update_source.tgz
tar -zxvf update_source.tgz
bash update_source.sh
} rhel5_vnc_config()
{
cat >$vnc_xstartup_config<<EOF
#!/bin/sh # Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r \$HOME/.Xresources ] && xrdb \$HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "\$VNCDESKTOP Desktop" &
#twm &
gnome-session &
EOF
cat >$vnc_sysconfig_vncservers<<EOF
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see
# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>. # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP. # Use "-nohttpd" to prevent web-based VNC clients connecting. # Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# 'man vncviewer' manual page. # VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
VNCSERVERS="1:root"
EOF
} check_selinux_config()
{
if grep "SELINUX=enforcing" $selinux_config >/dev/null 2>&1
then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' $selinux_config
fi
} centos5_install_vnc_server()
{
if [ "$1" == "redhat5" ]
then
if rpm -qa|grep redhat-logos >/dev/null 2>&1
then
yum remove $(rpm -qa|grep redhat-logos) -y
fi
fi
if yum grouplist "GNOME Desktop Environment"|grep "Available" >/dev/null 2>&1
then
if ! yum groupinstall "GNOME Desktop Environment" -y
then
exit_script "GNOME Desktop Environment"
fi
fi
if ! rpm -q vnc-server >/dev/null 2>&1
then
if ! yum install vnc-server -y
then
exit_script vnc-server
fi
vncserver <<EOF
$password
$password
EOF
else
vncpasswd <<EOF
$password
$password
EOF
fi
vncserver -kill :1
service vncserver stop
service pcscd stop
chkconfig --del pcscd
yum remove esc -y
rhel5_vnc_config
chmod 755 $vnc_xstartup_config
chkconfig --level 345 vncserver on
service NetworkManager stop
chkconfig --del NetworkManager
check_selinux_config
sleep 20
service vncserver start
} centos6_install_vnc_server()
{
if yum grouplist "X Window System"|grep "Available" >/dev/null 2>&1
then
if ! yum groupinstall "X Window System" -y
then
exit_script "X Window System"
fi
fi
if yum grouplist "Desktop"|grep "Available" >/dev/null 2>&1
then
if ! yum groupinstall "Desktop" -y
then
exit_script Desktop
fi
fi
if yum grouplist "Chinese Support"|grep "Available" >/dev/null 2>&1
then
if ! yum groupinstall "Chinese Support" -y
then
exit_script "Chinese Support"
fi
fi
if ! rpm -q tigervnc-server >/dev/null 2>&1
then
if ! yum install tigervnc-server -y
then
exit_script tigervnc-server
fi
vncserver <<EOF
$password
$password
EOF
else
vncpasswd <<EOF
$password
$password
EOF
fi
vncserver -kill :1
service vncserver stop
service pcscd stop
chkconfig --del pcscd
yum remove esc -y
sed -i 's/.*!= root.*/#&/' /etc/pam.d/gdm
dbus-uuidgen >/var/lib/dbus/machine-id
rhel5_vnc_config
chmod $vnc_xstartup_config
chkconfig --level vncserver on
service NetworkManager stop
chkconfig --del NetworkManager
sleep
service vncserver start
check_selinux_config
} centos7_install_vnc_server()
{
if ! yum groupinstall "GNOME Desktop" "Graphical Administration Tools" -y
then
exit_script "NOME Desktop Graphical Administration Tools"
fi
if ! yum install tigervnc-server -y
then
exit_script "tigervnc-server"
fi
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@\:.service
sed -i 's/%i/:1/g' /lib/systemd/system/vncserver@\:.service
sed -i 's/<USER>/root/g' /lib/systemd/system/vncserver@\:.service
sed -i 's/home\/root/root/g' /lib/systemd/system/vncserver@\:.service
vncpasswd <<EOF
$password
$password
EOF
systemctl enable vncserver@:.service
systemctl start vncserver@:.service
systemctl status vncserver@:.service
systemctl disable initial-setup-text.service
} ubuntu_install_vnc_server()
{
if ! dpkg -s lxde >/dev/null >&
then
if ! apt-get install lxde -y --force-yes --fix-missing
then
exit_script lxde
fi
fi
if ! dpkg -s ttf-arphic-uming >/dev/null >&
then
if ! apt-get install ttf-arphic-uming -y --force-yes --fix-missing
then
exit_script ttf-arphic-uming
fi
fi
if ! dpkg -s vnc4server >/dev/null >&
then
if ! apt-get install vnc4server -y --force-yes --fix-missing
then
exit_script vnc4server
fi
vncserver <<EOF
$password
$password
EOF
else
vncpasswd <<EOF
$password
$password
EOF
fi
vncserver -kill :
sed -i 's/x-window-manager \&/startlxde \&/' $vnc_xstartup_config
sed -i '/vncserver/d' $rc_local
sed -i 's/^exit 0$/su root \-c "\/usr\/bin\/vncserver \-name my-vnc-server \-geometry 1280x800 \:1"\nexit 0/' $rc_local
sleep
vncserver
} ####################Start###################
#check lock file ,one time only let the script run one time
LOCKfile=/tmp/.$(basename $)
if [ -f "$LOCKfile" ]
then
echo -e "\033[1;40;31mThe script is already exist,please next time to run this script.\n\033[0m"
exit
else
echo -e "\033[40;32mStep 1.No lock file,begin to create lock file and continue.\n\033[40;37m"
touch $LOCKfile
fi #check user
if [ $(id -u) != "" ]
then
echo -e "\033[1;40;31mError: You must be root to run this script, please use root to install this script.\n\033[0m"
rm -f $LOCKfile
exit
fi vnc_xstartup_config=/root/.vnc/xstartup
vnc_sysconfig_vncservers=/etc/sysconfig/vncservers
selinux_config=/etc/selinux/config
rc_local=/etc/rc.local
password=$(cat /dev/urandom | head - | md5sum | head -c ) echo -e "\033[40;32mStep 2.Begen to check the OS issue.\n\033[40;37m"
os_release=$(check_os_release)
if [ "X$os_release" == "X" ]
then
echo -e "\033[1;40;31mThe OS does not identify,So this script is not executede.\n\033[0m"
rm -f $LOCKfile
exit
else
echo -e "\033[40;32mThis OS is $os_release.\n\033[40;37m"
fi echo -e "\033[40;32mStep 3.Begen to modify the source configration file and update.\n\033[40;37m"
update_source echo -e "\033[40;32mStep 4.Begen to check and install vnc server.\n\033[40;37m"
case "$os_release" in
redhat5|centos5|aliyun5)
centos5_install_vnc_server $os_release
;;
redhat6|centos6|aliyun6)
centos6_install_vnc_server
;;
centos7)
centos7_install_vnc_server
;;
ubuntu10|ubuntu1204|ubuntu1210|debian6)
ubuntu_install_vnc_server
;;
esac echo -e "\033[40;32mInstall success.The vnc password is \"$password\",this script now exit!\n\033[40;37m"
rm -f $LOCKfile
在Linux实例上自动安装并运行VNC Server的更多相关文章
- 在 Linux 实例上自动安装并运行 VNC Server
原文网址:https://help.aliyun.com/knowledge_detail/41181.html?spm=5176.8208715.110.11.4c184ae8mlC7Yy 您可以使 ...
- 使用脚本在Linux服务器上自动安装Kubernetes的包管理器Helm
Helm之于Kubernetes好比yum之于Red Hat Enterprise Linux,或者apt-get之于Ubuntu. Helm是由helm CLI和Tiller组成,是典型的Clien ...
- Linux平台上轻松安装与配置Domino
Linux平台上轻松安装与配置Domino Domino Server的编译安装过程中需要用到libstdc++-2.9和glibc-2.1.1(或者其更高的版本)两个编译模块,它们是Linux开发编 ...
- DB 查询分析器 6.04 在 Windows 10 上的安装与运行展示
DB查询分析器 6.04 在 Windows 10 上的安装与运行展示 中国本土程序员马根峰(CSDN专访马根峰:海量数据处理与分析大师的中国本土程序员 http://www.csdn.net/art ...
- 安装sqlserver 的时候 报错:无法通过Windows功能控制面板自动安装或卸载Windows Server 角色和功能。
无法安装以下功能:.NET Framework 3.5(包括.NET2.0和3.0) 无法通过Windows功能控制面板自动安装或卸载Windows Server 角色和功能. 若要安装Windows ...
- 在一台机子上,安装,运行两mysql数据库实例
为了方便测试,想要用到两个mysql数据库实例.以windows系统为例 当然安装第一个mysql数据库,很简单没什么说的.但是再要安装,运行mysql安装程序时,会提示,修复,卸载,重新安装. 这时 ...
- Domino V8 在 UNIX/Linux 平台上的安装及其常见问题
在 IBM Bluemix 云平台上开发并部署您的下一个应用. 开始您的试用 Domino V8 的安装需求 Domino V8 可以支持多种平台和操作系统,表1 列出了其支持的各种 UNIX/Lin ...
- Linux Ubuntu上手动安装.NET Core SDK
今天重装了一台Linux服务器的Ubuntu 14.04系统,需要重新安装.NET Core 1.0. 按照官网上的文档用apt-get命令进行安装: sudo sh -c 'echo "d ...
- 如何在linux平台上编译安装zlib软件(公司部分线上机器缺少zlib不能安装supervisor)
文章在Centos 6.5 linux平台上演示一下如何进行编译安装zlib软件,并配置相关的选项加载使用.示范从下载到安装并配置进行使用过程一系列整套讲解,希望可以给网友考虑使用,谢谢. 工具 ...
随机推荐
- selenium之窗口滚动
在这里和大家分享一下,selenium里面常用于处理窗口滚动的方法. location_once_scrolled_into_view 一般用于定位窗口底部元素.将窗口拉到最底部. window.sc ...
- [bzoj4827] [洛谷P3723] [Hnoi2017] 礼物
Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是 ...
- 个人任务day4
今日任务: 完成注册和登录界面的绘制,并创建用户数据库. 昨日成果: 完成博客数据库的录入和界面跳转.
- Maven的学习之路1
对于下列这段Maven的命令行有不懂之处,在zgmzyr的博客上得到了解释.非常感谢这位博友,写在自己的随笔上以便查看和修改. 1. 创建项目 $ mvn archetype:generate -Dg ...
- JavaScript中this的使用及含义(总结)
this 1.谁调用,指向谁 2.事件监听函数中,this指向,绑定监听函数的那一个元素节点 即,谁绑,指向谁 3.当一个函数没有被其他对象调用时,(普通调用),this指向全局对象(严格模式下面是u ...
- py2 to py3
网络下载的python代码,版本参差,从python2.x迁移python3.x的过程中,存在print语法问题,即python2.x中print无括号,python3.x中print有括号. 逐行添 ...
- NOde.js的安装和简介
1.nodejs的安装 1.1 检测nodejs的版本 node -v (version:版本) 1.2 path配置nodejs 的环境变量(当前版本都是自动安装配置环境变量)指令: path 1. ...
- nmap详解之选项说明
功能选项 功能选项可以组合使用.一些功能选项只能够在某种扫描模式下使用.nmap会自动识别无效或者不支持的功能选项组合,并向用户发出警告信息. 如果你是有经验的用户,可以略过结尾的示例一节.可以使用n ...
- day05【数组】
day05[数组] 1.数组 概念:是一种容器,可以同时存放多个数据. 特点: 数组是一种引用数据类型 数组当中的多个数据,类型必须统一 数组的长度在程序的运行期间不可改变 初始化:在内存当中创建一个 ...
- Leetcode 题目整理
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...