ubuntu 14.04 配置VNC server

25540阅读 1评论2014-12-23 fireaxe
分类:LINUX

VNC server的安装不用多说。但问题是,安装完成后,只能看到terminal,看不到桌面与菜单。原因是VNC默认是不启动桌面环境的。
虽然linuxer们坚持认为一个terminal就够了,但这不是我的菜,还是要搞出桌面才够爽。
vnc server启动时,会调用“~/.vnc/xstartup”进行初始化,我们的任务就是在这里启动桌面环境。
ubuntu支持两种桌面环境:unity与gnome,(unity是对gnome的一种深度定制)
还写以选择安装一种轻量级桌面环境,xfce4。

原来计划搞定三种桌面环境,最终却没搞定ubuntu 14.04上默认支持的unity :(
不管怎么,三种方式都放到下面的脚本中了,unity仅作参考了。

点击(此处)折叠或打开

  1. #!/bin/sh

  2. # DESK_TYPE=xfce
  3. DESK_TYPE=gnome
  4. # DESK_TYPE=unity

  5. # Uncomment the following two lines for normal desktop:
  6. unset SESSION_MANAGER
  7. unset DBUS_SESSION_BUS_ADDRESS
  8. # exec /etc/X11/xinit/xinitrc

  9. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
  10. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
  11. xsetroot -solid grey
  12. vncconfig -iconic &
  13. # x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
  14. # x-window-manager &

  15. echo $DESK_TYPE
  16. # xfce desktop
  17. if test $DESK_TYPE = xfce; then
  18. x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
  19. x-session=-manager &
  20. xfdesktop & xfce4-panel &
  21. xfce4-menu-plugin &
  22. xfsettingsd &
  23. xfconfd i&
  24. xfwm4&
  25. fi

  26. # gnome desktop
  27. if test $DESK_TYPE = gnome; then
  28. gnome-session &
  29. gnome-panel &
  30. gnome-settings-daemon &
  31. metacity &
  32. nautilus -n &
  33. gnome-terminal &
  34. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings panel-main-menu "['F1']"
  35. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings maximize "['KP_5']"
  36. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings unmaximize "['F5']"
  37. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings show-desktop "['d']"
  38. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-applications "['Tab']"
  39. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-group "['Above_Tab']"
  40. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-input-source "[]"
  41. /usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "[]"
  42. /usr/bin/gsettings set org.gnome.settings-daemon.plugins.media-keys terminal "['t']"
  43. fi

  44. # unity desktop
  45. if test $DESK_TYPE = unity; then
  46. export DESKTOP_SESSION=ubuntu
  47. export GDMSESSION=ubuntu
  48. export STARTUP="/usr/bin/gnome-session --session=ubuntu"
  49. $STARTUP &
  50. fi

vnc配置好后,如果希望开机启动,可以建立文件“/etc/vncserver/vncservers.conf”用来配置需要启动的server

点击(此处)折叠或打开

  1. VNCSERVERS="1:hao-64 11:hao-64 12:hao-64 13:hao-64 14:hao-64 15:hao-64"
  2. VNCSERVERARGS[1]="-geometry 1024x768"
  3. VNCSERVERARGS[11]="-geometry 1680x1050"
  4. VNCSERVERARGS[12]="-geometry 1366x768"
  5. VNCSERVERARGS[13]="-geometry 1280x1024"
  6. VNCSERVERARGS[14]="-geometry 1024x768"
  7. VNCSERVERARGS[15]="-geometry 800x600"
再建立文件“/etc/init.d/vncserver”,用于开机启动配置文件

点击(此处)折叠或打开

  1. #!/bin/bash
  2.  
  3. unset VNCSERVERARGS
  4. VNCSERVERS=""
  5. [ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
  6. prog=$"VNC server"
  7. start() {
  8.  . /lib/lsb/init-functions
  9.  REQ_USER=$2
  10.  echo -n $"Starting $prog: "
  11.  ulimit -S -c 0 >/dev/null 2>&1
  12.  RETVAL=0
  13.  for display in ${VNCSERVERS}
  14.  do
  15.  export USER="${display##*:}"
  16.  if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
  17.  echo -n "${display} "
  18.  unset BASH_ENV ENV
  19.  DISP="${display%%:*}"
  20.  export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
  21.  su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
  22.  fi
  23.  done
  24. }
  25. stop() {
  26.  . /lib/lsb/init-functions
  27.  REQ_USER=$2
  28.  echo -n $"Shutting down VNCServer: "
  29.  for display in ${VNCSERVERS}
  30.  do
  31.  export USER="${display##*:}"
  32.  if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
  33.  echo -n "${display} "
  34.  unset BASH_ENV ENV
  35.  export USER="${display##*:}"
  36.  su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
  37.  fi
  38.  done
  39.  echo -e "\n"
  40.  echo "VNCServer Stopped"
  41. }
  42. case "$1" in
  43. start)
  44. start $@
  45. ;;
  46. stop)
  47. stop $@
  48. ;;
  49. restart|reload)
  50. stop $@
  51. sleep 3
  52. start $@
  53. ;;
  54. condrestart)
  55. if [ -f /var/lock/subsys/vncserver ]; then
  56. stop $@
  57. sleep 3
  58. start $@
  59. fi
  60. ;;
  61. status)
  62. status Xvnc
  63. ;;
  64. *)
  65. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  66. exit 1
  67. esac
调用命令“update-rc.d vncserver defaults 99”刷新启动配置。
最后,重启系统


上一篇:说说ARM汇编的LDR伪指令【转】
下一篇:ubuntu上配置tftp server

文章评论