linux一键安装vncserver脚本
title: linux一键安装vncserver脚本
date: 2016-04-11 14:32:04
tags:
linux多数情况下是作为服务器使用的,管理员一般也喜欢使用命令行来管理服务器,所以服务器往往都没有配备显示器及输入输出设备,但有时候还是会用到Linux桌面,所以发一下这个脚本,希望可以帮助到有用的同学。
#!/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 2>/dev/null)
os_release_2=$(grep "Red Hat Enterprise Linux Server release" /etc/redhat-release 2>/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "release 5" >/dev/null 2>&1
then
os_release=redhat5
echo "$os_release"
elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
then
os_release=redhat6
echo "$os_release"
else
os_release=""
echo "$os_release"
fi
break
fi
os_release=$(grep "Aliyun Linux release" /etc/issue 2>/dev/null)
os_release_2=$(grep "Aliyun Linux release" /etc/aliyun-release 2>/dev/null)
if [ "$os_release" ] && [ "$os_release_2" ]
then
if echo "$os_release"|grep "release 5" >/dev/null 2>&1
then
os_release=aliyun5
echo "$os_release"
elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
then
os_release=aliyun6
echo "$os_release"
elif echo "$os_release"|grep "release 7" >/dev/null 2>&1
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://oss.aliyuncs.com/aliyunecs/update_source.tgz?spm=5176.7150518.1996836753.5.67nzlg&file=update_source.tgz" -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 755 $vnc_xstartup_config
chkconfig --level 345 vncserver on
service NetworkManager stop
chkconfig --del NetworkManager
sleep 20
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@\:1.service
sed -i 's/%i/:1/g' /lib/systemd/system/vncserver@\:1.service
sed -i 's/<USER>/root/g' /lib/systemd/system/vncserver@\:1.service
sed -i 's/home\/root/root/g' /lib/systemd/system/vncserver@\:1.service
vncpasswd <<EOF
$password
$password
EOF
systemctl enable vncserver@:1.service
systemctl start vncserver@:1.service
systemctl status vncserver@:1.service
systemctl disable initial-setup-text.service
}
ubuntu_install_vnc_server()
{
if ! dpkg -s lxde >/dev/null 2>&1
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 2>&1
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 2>&1
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 :1
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 5
vncserver
}
####################Start###################
#check lock file ,one time only let the script run one time
LOCKfile=/tmp/.$(basename $0)
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) != "0" ]
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 1
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 -1 | md5sum | head -c 6)
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 0
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一键安装vncserver脚本的更多相关文章
- linux一键安装nginx脚本
#!/bin/sh echo "----------------------------------start install nginx ------------------------- ...
- linux一键安装php脚本
#!/bin/sh echo "----------------------------------start install php --------------------------- ...
- linux一键安装mysql脚本
#!/bin/sh if [ -s /etc/my.cnf ];then rm -rf /etc/my.cnf fi echo "------------------------------ ...
- 禅道Linux一键安装版
禅道Linux一键安装版 Linux一键安装包内置了apache, php, mysql这些应用程序,只需要下载解压缩即可运行禅道.从7.3版本开始,linux一键安装包分为32位和64位两个包,大家 ...
- Rehat一键安装mysql脚本和备份数据库脚本
Rehat一键安装mysql脚本 ##说明:适用,Rehat 5 6 7 1.运行状态,运行成功输出mysql临时密码 2.代码如下 #!/bin/bash #获取系统信息 sudo cat /etc ...
- Linux一键安装宝塔控制面板
Linux一键安装宝塔的命令行 yum install -y wget && wget -O install.sh http://download.bt.cn/install/inst ...
- (转)CentOS一键安装Nginx脚本
原文:https://www.xiaoz.me/archives/10301 https://blog.slogra.com/post-676.html-----centos7一键安装nginx脚本
- Linux一键安装web环境全攻略phpstudy版
此教程主要是应对阿里云Linux云服务器ecs的web环境安装,理论上不限于阿里云服务器,此教程对所有Linux云服务器都具有参考价值. 写这篇文章的目的:网上有很多关于Linux一键安装web环境全 ...
- Linux一键安装LNMP环境
Linux一键安装LNMP环境 官方地址:https://lnmp.org/. 参考安装步骤:https://lnmp.org/install.html. 一键安装可以选择mysql版本.php版本, ...
随机推荐
- Linux shell 脚本中”2>&1″的含义解释
脚本是:nohup /mnt/Nand3/H2000G >/dev/null 2>&1 & 对于& 1 更准确的说应该是文件描述符 1,而1 一般代表的就是 ...
- CUICatalog: Invalid asset name supplied: (null)
出现这个问题的根本原因是你调用了[UIImage imageNamed:name]这个方法 但是name = nil;所以报出该错误. 解决方法,在项目中搜索[UIImage imageNamed ...
- SQL IN BETWEEN操作符
IN 操作符 IN 操作符允许我们在 WHERE 子句中规定多个值. SQL IN 语法 SELECT column_name(s) FROM table_name WHERE column_name ...
- JavaWeb 之 重复提交表单和验证码相关的问题!
下面我们首先来说一下表单的重复提交问题,我们知道在真实的网络环境中可能受网速带宽的原因会造成页面中表单在提交的过程中出现网络的延迟等问题,从而造成多次提交的问题!下面我们就具体来分析一下造成表单提交的 ...
- Centos 中 vim 的配置
工欲善其事,必先利其器,我们要用好 vim 就先来把它配置的顺手一点,这样可以大大提高我们的工作学习效率 1.跳转指令 Ctags1 从下面地址下载ctags,将其中的ctags.exe复制到vim目 ...
- HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang
感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...
- IBM X3650 服务器更换内存的过程记录
前几天,由于天气气温太高,导致中心机房UPS自动保护性关闭,最终导致所有服务器都掉电.其中一台IBM X3650服务器报警,显示内存故障.原来这台服务器共有4G内存,现在打开服务器进入系统后,显示只有 ...
- js十进制等互相转换
//十进制转其他 var x=110; alert(x); alert(x.toString(8)); alert(x.toString(32)); alert(x.toString(16)); / ...
- acdream暴力专场中的优美暴力
F - 小晴天老师系列——苹果大丰收 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- CWnd类
CWnd类的成员 .数据成员 m_hWnd 指明与这个CWnd对象相关联的HWND句柄 .构造和析构 CWnd 构造一个CWnd对象 DestroyWindow 销毁相关联的Windows窗口 .初始 ...