您的位置:首页 > 运维架构 > Linux

centOS 6.5 VNC配置

2015-06-23 10:55 811 查看
参考文章

一.配置VNC

1.首先查看安装的centOS版本

lsb_release -a

Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:        6.5
Codename:       Final


2.查看有没有安装vncserver

rpm –q tigervnc tigervnc-server
#其实只要tigervnc-server就够了
#列出所有被安装的rpm package
# rpm -qa




3.编辑vncservers配置文件

[root@localhost ~]# vim /etc/sysconfig/vncservers

VNCSERVERS="1:root 2:bob" //其中的1表示桌面号,后面指定用户如果设置多个用户可以继续书写,用户必须为系统存在用户,最多为6,端口对应5901-5906。
VNCSERVERARGS[1]="-geometry 1024x768-nolisten tcp"//我没写也能用。。
VNCSERVERARGS[2]="-geometry 1024x768-nolisten tcp"




4.初次启动设置root用户的vnc登录密码,会生成/root/.vnc/passwd密码文件。

[root@localhost ~]# vncserver
password:
verify:


5.设置bob用户的vnc登录密码,会生成/home/bob/.vnc/passwd密码文件。

[root@localhost ~]# su - bob(-和bob之间也有空格)

[bob@localhost ~]$ vncserver

password:

verify:

6.在root用户下,修改/root/.vnc/xstartup文件,启动GNOME桌面还是KDE桌面。

[bob@localhost ~]$ exit
logout
[root@localhost ~]# vim /root/.vnc/xstartup
#twm & //注释该行
末尾追加如下行:
gnome-session & //如果为KDE桌面,则修改为:startkde &


7.在bob用户下,修改/home/bob/.vnc/xstartup文件,启动GNOME桌面还是KDE桌面。

[bob@localhost ~]# vim /home/bob/.vnc/xstartup
#twm & //注释该行
末尾追加如下行:
gnome-session & //如果为KDE桌面,则修改为:startkde &

# 另外一种:
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 &


8.启动服务,搭建完成。service vncserver start/restart

要重启vnc才能使更改过/etc/sysconfig/VNCSERVERS 起作用。

[root@sunth ~]# service vncserver start
Starting VNC server: 1:root A VNC server is already running as :1
[FAILED]
[root@sunth ~]# service vncserver restart
Shutting down VNC server: 1:root                           [  OK  ]
Starting VNC server: 1:root xauth: (stdin):1:  bad display name "sunth.localdomain:1" in "add" command

New 'sunth.localdomain:1 (root)' desktop is sunth.localdomain:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/sunth.localdomain:1.log

[  OK  ]


二、其他的一些vnc命令

1.关闭root用户的vnc桌面,再连接被拒绝

(此时bob用户不受影响,bob用户关闭vnc桌面同root)。

[root@localhost ~]# vncserver -kill :1
Killing Xvnc process ID 5962
Xvnc seems to be deadlocked.  Kill the process manually and then re-run
/usr/bin/vncserver -kill :1
to clean up the socket files.
[root@localhost ~]# kill 5962  进程deadlocked,所以要手动kill进程(不知道需不需要 kill -9 5962, -9 是强制杀掉)


2.重新开启root用户的vnc桌面。

[root@localhost ~]# vncserver :1 -geometry 1280x1024 //后面的geometry不加的话就使用默认值
//对于1920x1080的显示器来说,1895x1000比较适合
//进入vnc后也可以按F12然后选择全屏
New 'localhost.localdomain:1 (root)'desktop is localhost.localdomain:1
Starting applications specified in/root/.vnc/xstartup
Log file is/root/.vnc/localhost.localdomain:1.log


3.修改root用户在初次启动vncserver时设置的vnc登录密码

(切换到bob用户,修改方法同root)。

[root@localhost ~]# vncpasswd
Password:
Verify:


再次登录需要设置使用新设置的密码。

4.开机自启动vncserver服务

# chkconfig vncserver on
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: