在使用阿里云的linux云主机,看到官方提供的远程连接服务器bash脚本,记录下来。
功能:自动修改系统源和安装vncserver相关的软件包,centos、redhat系列都是安装gnome桌面环境,ubuntu和debian系列都是安装LXDE(Lightweight X11 Desktop Environment) 。
适用系统版本:兼容线上所有linux版本
执行方法:以root身份执行命令:bash install_vnc_server.sh
解决了什么问题:一键式安装vncserver,使用户可以远程图形化管理服务器
install_vnc_server.zip
(4 K)
#!/bin/bash
##########################################Function: install vnc server
#Usage: bash install_vnc_server.sh
#Author: Customer service department
#Company: Alibaba Cloud Computing
#Version: 1.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 "CentOS release" /etc/issue 2>/dev/null)
os_release_2=$(grep "CentOS release" /etc/*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=centos5
echo "$os_release"
elif echo "$os_release"|grep "release 6" >/dev/null 2>&1
then
os_release=centos6
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" >/dev/null 2>&1
then
os_release=ubuntu12
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"
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
}
modify_rhel5_yum()
{
rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS-Base-163.repo -O CentOS-Base-163.repo
sed -i '/mirrorlist/d' CentOS-Base-163.repo
sed -i 's/\$releasever/5/' CentOS-Base-163.repo
yum clean metadata
yum makecache
cd ~
}
modify_rhel6_yum()
{
rpm --import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS-Base-163.repo -O CentOS-Base-163.repo
sed -i '/mirrorlist/d' CentOS-Base-163.repo
sed -i '/\[addons\]/,/^$/d' CentOS-Base-163.repo
sed -i 's/\$releasever/6/' CentOS-Base-163.repo
sed -i 's/RPM-GPG-KEY-CentOS-5/RPM-GPG-KEY-CentOS-6/' CentOS-Base-163.repo
yum clean metadata
yum makecache
cd ~
}
update_ubuntu10_apt_source()
{
echo -e "\033[40;32mBackup th