一、在Linux服务器中,我们通常是通过ssh进行远程操作,偶尔需要有桌面支持或图形化安装相关软件时,则需要远程到服务器桌面或将输出图形调到客户端。
Linux下的远程工具通常用到的有xmanager、vnc。以下将简单介绍vnc的应用。
step1:安装vnc并启动vnc
[root@www.linuxidc.com ~]# rpm -qa |grep vnc #需安装以下两个包
vnc-4.1.2-14.el5_6.6
vnc-server-4.1.2-14.el5_6.6
[root@www.linuxidc.com ~]# service vncserver start #启动vnc服务
Starting VNC server: no displays configured [ OK ]
step2:修改 /etc/sysconfig/vncservers 配置文件,添加tghfly和test用户,设置会话窗口,并使用gnome桌面
[root@www.linuxidc.com ~]# grep -v “#” /etc/sysconfig/vncservers
VNCSERVERS=”1:tghfly 2:test” #1表示登录会话窗口,tghfly表示登录用户
VNCSERVERARGS[1]=”-geometry 1280×768″ #远程桌面窗口大小为1280×768
VNCSERVERARGS[2]=”-geometry 1280×768″
step3:创建系统用户tghfly和test,并设置密码
[root@www.linuxidc.com ~]# useradd tghfly
[root@www.linuxidc.com ~]# passwd tghfly
Changing password for user tghfly.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@www.linuxidc.com ~]# useradd test
[root@www.linuxidc.com ~]# passwd test
Changing password for user test.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
step4:切换到tghfly和test,设置远程登录密码,生成远程认证文件
[root@www.linuxidc.com ~]# su – tghfly
[www.linuxidc.com@linuxidc ~]$ vncserver #使用vncserver设置当前用户远程登录密码
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /home/tghfly/.Xauthority
New ‘hongwb.com.cn:1 (tghfly)’ desktop is hongwb.com.cn:1
Creating default startup script /home/tghfly/.vnc/xstartup
Starting applications specified in /home/tghfly/.vnc/xstartup
Log file is /home/tghfly/.vnc/hongwb.com.cn:1.log
step5:修改当前用户下的.vnc目录下的xstartup文件
[www.linuxidc.com@linuxidc ~]$ vi .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 & #注释行
gnome-session & #新增行,调用gnome桌面
同理切换到test用户,按tghfly用户一样设置
[www.linuxidc.com@linuxidc ~]$ su – test
Password:
[test@hongwb ~]$ vncserver #生成认证文件
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /home/test/.Xauthority
New ‘hongwb.com.cn:2 (test)’ desktop is hongwb.com.cn:2
Creating default startup script /home/test/.vnc/xstartup
Starting applications specified in /home/test/.vnc/xstartup
Log file is /home/test/.vnc/hongwb.com.cn:2.log
[test@hongwb ~]$ vi .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 &
gnome-session &
step6:到root用户下,重新启动vnc服务
[root@www.linuxidc.com ~]# service vncserver restart
Shutting down VNC server: 1:tghfly 2:test [ OK ]
Starting VNC server: 1:tghfly
New ‘hongwb.com.cn:1 (tghfly)’ desktop is hongwb.com.cn:1
Starting applications specified in /home/tghfly/.vnc/xstartup
Log file is /home/tghfly/.vnc/hongwb.com.cn:1.log
2:test
New ‘hongwb.com.cn:2 (test)’ desktop is hongwb.com.cn:2
Starting applications specified in /home/test/.vnc/xstartup
Log file is /home/test/.vnc/hongwb.com.cn:2.log
[ OK ]
step7:使用浏览器或者vncview工具远程登录
650) this.width=650;” border=0>
输入tghfly的远程登录密码tghfly
650) this.width=650;” border=0>
step8:当vnc客户端窗口非正常关闭后,就不允许再登录,需要杀死vnc进程
[www.linuxidc.com@linuxidc ~]$ vncserver -kill :1 #:1表示当前用户远程登录会话窗口
Killing Xvnc process ID 589
备注:kill当前用户会话窗口后,要再次远程,需要重启当前用户会话窗口
只要在当用户下输入vncserver,就会重新启动了
[www.linuxidc.com@linuxidc ~]$ vncserver
New ‘hongwb.com.cn:1 (tghfly)’ desktop is hongwb.com.cn:1
Starting applications specified in /home/tghfly/.vnc/xstartup
Log file is /home/tghfly/.vnc/hongwb.com.cn:1.log
---------------------------------------
在完成上述vnc服务配置后,当客户端连接到vnc服务器后,若要使用服务器上的输入法输入文字时,会发现输入法无法切换,只能用英文,可通过以下步骤解决。
step1:安装scim,并安装中文输入法
[root@tgh ~]# yum -y install scim-*
step2:添加中文字体,CentOS默认没有zysong.ttf字体,需要另外下载,并保存到以下目录
[root@rac1 ~]#mkdir -p /usr/share/fonts/zh_CN/TrueType/ #创建相关目录
[root@rac1 ~]# mv zysong.ttf /usr/share/fonts/zh_CN/TrueType/zysong.ttf #将zysong.ttf放到/usr/share/fonts/zh_CN/TrueType/
Step3:在vnc用户配置文件中设置自启动scim,并添加相关输入法环境变量
[tgh@tgh ~]$ cat .vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
unset LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
unset LC_IDENTIFICATION LC_ALL LANG LANGUAGE PAGER
LANG=zh_CN.UTF-8
export LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
export LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
export LC_IDENTIFICATION LC_ALL LANG LANGUAGE PAGER
export G_FILENAME_ENCODING=@locale
XMODIFIERS=”@im=SCIM”
GTK_IM_MODULE=”scim”
export XMODIFIERS GTK_IM_MODULE
if type scim &> /dev/null ; then
scim -d &
fi
[ -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 &
gnome-session &
按以上设置后,在客户端用vnc登录,将允许用户切换输入法!