Zer*_*ero 34 vnc vncserver ubuntu
我在 Ubuntu 9.10 VPS 服务器上安装了 Ubuntu 桌面,并且能够使用 TightVNC 连接到服务器。但是,这个 VPS 上的 VNC 服务器只能通过 SSH 登录并输入以下命令来启动:
vncserver :1 -geometry 800x600 -depth 16 -pixelformat rgb565
Run Code Online (Sandbox Code Playgroud)
如果我在启动时或作为计划任务运行此命令,它将不会启动。我有哪些选择?
Ste*_*ngs 34
我通过在 Google 上搜索“ ubuntu launch vnc server on startup ”找到了这些说明。
vncserver
首次启动设置密码。/etc/init.d/vncserver
(确保根据自己的喜好修改用户、几何、名称等)。sudo chmod +x /etc/init.d/vncserver
sudo update-rc.d vncserver defaults
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Default-Start: S
# Default-Stop: 0 6
### END INIT INFO
PATH="$PATH:/usr/X11R6/bin/"
# The Username:Group that will run VNC
export USER="mythtv"
#${RUNAS}
# The display that VNC will use
DISPLAY="1"
# Color depth (between 8 and 32)
DEPTH="16"
# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
#GEOMETRY="800x600"
GEOMETRY="1024x768"
#GEOMETRY="1280x1024"
# The name that the VNC Desktop will have.
NAME="my-vnc-server"
OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;
stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
Run Code Online (Sandbox Code Playgroud)
Jus*_*ser 12
如果您想要更动态的配置和连接多个用户的能力,那么有更好的方法来做到这一点。以 root 身份创建文件(如果不存在则创建目录)/etc/sysconfig/vncservers 即:
mkdir -p /etc/vncserver
touch /etc/vncserver/vncservers.conf
Run Code Online (Sandbox Code Playgroud)
通过将如下内容添加到您刚刚创建的 vncservers.conf 文件中,根据需要为每个用户添加服务器:
VNCSERVERS="1:justin 2:bob"
VNCSERVERARGS[1]="-geometry 1920x1080 -depth 24"
VNCSERVERARGS[2]="-geometry 800x600 -depth 8"
Run Code Online (Sandbox Code Playgroud)
接下来创建一个空的初始化脚本并使其可执行:
touch /etc/init.d/vncserver
chmod +x /etc/init.d/vncserver
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到 /etc/init.d/vncserver:
#!/bin/bash
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$"VNC server"
start() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS}
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
DISP="${display%%:*}"
export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
fi
done
}
stop() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $"Shutting down VNCServer: "
for display in ${VNCSERVERS}
do
export USER="${display##*:}"
if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
echo -n "${display} "
unset BASH_ENV ENV
export USER="${display##*:}"
su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
fi
done
echo -e "\n"
echo "VNCServer Stopped"
}
case "$1" in
start)
start $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
fi
;;
status)
status Xvnc
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
Run Code Online (Sandbox Code Playgroud)
正如斯蒂芬在他的回答中提到的,您需要至少以您想要登录的每个用户身份运行 vncserver 一次。我把它放在大写中,因为如果你跳过那一步,它都不会起作用。所以作为 root 你可以这样做:
su justin -c vncserver
su bob -c vncserver
Run Code Online (Sandbox Code Playgroud)
这将使用适当的启动脚本在每个用户的主目录中创建一个 .vnc 目录。
最后,执行以下操作:
update-rc.d vncserver defaults 99
Run Code Online (Sandbox Code Playgroud)
现在您可以通过键入以下内容重新启动或手动启动服务:
service vncserver start
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
203911 次 |
最近记录: |