在VPS上安装VNC

1 环境
banwagonhost VPS centos 6 64位环境。

2 安装桌面环境
根据不同情况自行选择合适的桌面。

2.1 XFCE
XFCE是占用资源最少的桌面环境。
wget http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum search xfce
yum groupinfo xfce
yum groupinstall xfce

安装中文语言包、FireFox/Flash Player
yum -y groupinstall chinese-support
yum -y install firefox
wget http://soft.itbulu.com/vnc/install_flash_player_11_linux.x86_64.tar.gz
tar zxvf install_flash_player_11_linux.x86_64.tar.gz
mkdir -p ~/.mozilla/plugins/
cp libflashplayer.so ~/.mozilla/plugins/

这里需要安装中文语言包,这样浏览中文网站的时候就不会有乱码出现。同时安装Flash Player组件,在浏览网站或者项目时候不会有打不开的问题。有些需要挂机的项目是必须有Flash Player的。

2.2 KDE Desktop
系统常自带KDE Desktop,比较占内存。
yum groupinfo “KDE Desktop”
yum groupinstall “KDE Desktop”

3 安装配置VNC
3.1 升级及安装tightvnc
yum -y update
yum -y install tightvnc
yum -y install tightvnc-server
因为考虑到不同的版本系统的软件源的不同,我们在安装环境之前一定要更新系统源,因为有些漏洞也可以补丁打上。

3.2 设置VNC密码
vncserver

3.3 配置分辨率
vi /etc/sysconfig/vncservers
编辑文件,然后添加下面两行。

VNCSERVERS=”1:root”
VNCSERVERARGS[1]=”-geometry 800×600″

保存后退出。如果需要其他分辨率,我们可以对参数修改。

重启VNC
service vncserver restart

3.4 修改配置文件
vi /root/.vnc/xstartup
编辑文件,替换下面的内容:

#!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
#twm &
startxfce4 &

全部替换成上面的内容,保存退出。
gnome (centos原生桌面)就用下面这句
gnome-session &

3.5 重启生效
chmod +x ~/.vnc/xstartup
service vncserver restart

3.6 chkconfig vncserver on

4 使用
电脑端,下载 TightVNC
安装、启动后,在TightVNC Viewer的 Remote Host 中填写:xxx.xxx.com:2 ,然后点击“连接”即可。

手机端,下载手机app,按提示使用即可。

5 相关命令
5.1 停止vncserver
vncserver -kill :1
vncserver -kill :2

5.2 配置防火墙
iptables -I INPUT -m state –state NEW -m tcp -p tcp –dport 5900:5903 -j ACCEPT
或者
iptables -I INPUT -m state –state NEW -m tcp -p tcp –dport 5901 -j ACCEPT
iptables -I INPUT -m state –state NEW -m tcp -p tcp –dport 5902 -j ACCEPT
service iptables save

6 参考
http://www.itbulu.com/centos6-xfce.html
http://www.centoscn.com/image-text/config/2014/1120/4151.html

Leave a comment

Your email address will not be published. Required fields are marked *