歡迎您光臨本站 註冊首頁

Centos5.5配置VNC服務及客戶端連接后輸入法切換問題

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

一、在linux伺服器中,我們通常是通過ssh進行遠程操作,偶爾需要有桌面支持或圖形化安裝相關軟體時,則需要遠程到伺服器桌面或將輸出圖形調到客戶端.

linux下的遠程工具通常用到的有xmanager、vnc.以下將簡單介紹vnc的應用.

step1:安裝vnc並啟動vnc

[root@hongwb ~]# rpm -qa |grep vnc #需安裝以下兩個包
vnc-4.1.2-14.el5_6.6
vnc-server-4.1.2-14.el5_6.6

[root@hongwb ~]# service vncserver start #啟動vnc服務

Starting VNC server: no displays configured [ OK ]

step2:修改 /etc/sysconfig/vncservers 配置文件,添加tghfly和test用戶,設置會話窗口,並使用gnome桌面

[root@hongwb ~]# grep -v "#" /etc/sysconfig/vncservers

VNCSERVERS="1:tghfly 2:test" #1表示登錄會話窗口,tghfly表示登錄用戶

VNCSERVERARGS[1]="-geometry 1280x768" #遠程桌面窗口大小為1280x768

VNCSERVERARGS[2]="-geometry 1280x768"

step3:創建系統用戶tghfly和test,並設置密碼

[root@hongwb ~]# useradd tghfly

[root@hongwb ~]# 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@hongwb ~]# useradd test

[root@hongwb ~]# 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@hongwb ~]# su - tghfly

[tghfly@hongwb ~]$ 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文件

[tghfly@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 80x24 10 10 -ls -title "$VNCDESKTOP Desktop" & #註釋行

#twm & #註釋行

gnome-session & #新增行,調用gnome桌面

同理切換到test用戶,按tghfly用戶一樣設置

[tghfly@hongwb ~]$ 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 80x24 10 10 -ls -title "$VNCDESKTOP Desktop" &

#twm &

gnome-session &

step6:到root用戶下,重新啟動vnc服務

[root@hongwb ~]# 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工具遠程登錄

輸入tghfly的遠程登錄密碼tghfly

step8:當vnc客戶端窗口非正常關閉后,就不允許再登錄,需要殺死vnc進程

[tghfly@hongwb ~]$

vncserver -kill :1 #:1表示當前用戶遠程登錄會話窗口

Killing Xvnc process ID 589

備註:kill當前用戶會話窗口后,要再次遠程,需要重啟當前用戶會話窗口

只要在當用戶下輸入vncserver,就會重新啟動了

[tghfly@hongwb ~]$ 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 80x24 10 10 -ls -title "$VNCDESKTOP Desktop" &

#twm &

gnome-session &

按以上設置后,在客戶端用vnc登錄,將允許用戶切換輸入法!

本文出自 「唐光輝」 博客,請務必保留此出處http://firefly222.blog.51cto.com/899793/842028


[火星人 ] Centos5.5配置VNC服務及客戶端連接后輸入法切換問題已經有639次圍觀

http://coctec.com/docs/linux/show-post-46062.html