1、安装服务
yum install tigervnc-server
- 1
- 2
名字有点怪哦,CentOS5前叫vnc-server
2、运行并设置密码
vncserver + 回车
- 1
- 2
输入密码,会生成相关的文件
[root@localhost ~]# vncserver You will require a password to access your desktops. Password: Verify: New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1 Creating default startup script /root/.vnc/xstartup Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/localhost.localdomain:1.log [root@localhost ~]# vim /etc/sysconfig/vncservers
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
3、配置用户
vim /etc/sysconfig/vncservers
- 1
- 2
最后一行加入:
VNCSERVERS=”1:root” 多个用户用空格分开,并要先su - 到那个用户运行vncserver[:n]来设定配置文件和密码
4、实用命令
**usage: vncserver [:] [-name ] [-depth ]
[-geometry x]
[-pixelformat rgbNNN|bgrNNN]
[-fp ]
[-fg]
…
vncserver -kill
vncserver -list**
**vncserver[:n] 开服务
vncserver -list 看有几个在运行
vncserver -kill :n 杀掉第几个x-display
vncpasswd 修改密码**
5、服务管理
service vncserver restart
其它用法:/etc/init.d/vncserver {start|stop|restart|try-restart|status|force-reload}
chkconfig vncserver on 加入到自启动(chkconfig –level 35 vncserver on)
6、客户端连接
CentOS:使用TigerVNC Viewer 连接 ip:1
Windows:使用Real VNC Viewer 连接ip:1
输入密码即可访问
===================================================================
必须明白:
vncserver在调用的时候,会根据你的配置来启用server端的监听端口,
端口默认是从5900开始,再加上你的桌面号。
比如你的桌面号为1,则vnc的连接端口号为5900+1=5901
比如你的桌面号为1,则vnc的连接端口号为5900+1=5901
下面配置VNC服务器,使用户(root)能够通过vnc客户端远程连接到linux系统的图形界面(前提是你的服务器要安装桌面)
1、检查linux系统是否安装VNC
在终端窗口输入命令:
rpm -q vnc-server
- 1
- 2
返回信息如下
package vnc-server is not installed
- 1
- 2
说明vnc服务器没有安装
2、运行以下命令进行安装:
yum install vnc vnc-server
- 1
- 2
3、启动VNC服务
vncserver
You will require a password to access your desktops.
Password:
Verify:
- 1
- 2
- 3
- 4
- 5
会提示输入密码,这个密码是远程登录时所需要输入的密码,输入密码,回车
4、切换到root账号:su root然后输入root账号的密码
vi /etc/sysconfig/vncservers #vnc配置文件
VNCSERVERS="1:root" # 把前面的#取消了 1:root (桌面号:用户)
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
- 1
- 2
- 3
- 4
最后保存退出
5、配置防火墙,允许1+5900=5901端口通过防火墙(否则远程连不上VNC服务器)
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT(允许5901端口通过防火墙)
- 1
- 2
- 3
保存退出
6、重启vnc服务器
/etc/init.d/vncserver restart
或者
service vncserver restart
- 1
- 2
- 3
- 4
7、重启防火墙,使刚才的端口配置生效
/etc/init.d/iptables restart
service iptables restart
- 1
- 2
- 3
8、 设置vnc服务器开机自动启动
第一种方法:使用“ntsysv”命令启动图形化服务配置程序,在vncserver服务前加上星号,点击确定,配置完成。
第二种方法:使用“chkconfig”在命令行模式下进行操作,命令使用如下
chkconfig vncserver on
chkconfig --list vncserver
vncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- 1
- 2
- 3
- 4
9、更改vnc连接密码
vncpasswd
到此,VNC服务端设置完成,用VNC客户端可以连接了
vnc服务器:你的ip:5901
注意:如果在连接上之后,出现灰屏,可以按照下面的方法设置
进入用户的home目录, cd /home/user
如果是用root账号登录的,那么当前目录就是用户根目录
cd ~/.vnc
vi xstartup #编辑
#twm & #注释掉这一行
gnome-session & #添加这一行
- 1
- 2
- 3
- 4
- 5
保存退出即可正常连接!
做到这里,总算是大功告成了,接下来你可以用http://IP:port的方式来WEB登录比如说
http://IP:5901,也可以在vncviewer里用IP:1这种来登录。