OS:RHEL7.2
step1: 安装 vncserver 端, 这里使用的是 tiger vnc
- yum install tigervnc-server
- yum install tigervnc
注意: 使用 vnc 之前先得保证能够开启 xwindows, 所以如果你没有 xwindows, 需要安装: yum groupinstall "GNOME Desktop"
关闭防火墙
- systemctl stop firewalld
- systemctl disable firewalld
关闭 selinux
step2: 复制并修改配置文件
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service == 这是给 root 的配置文件
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service == 这是给 shichunda 用户的配置文件
vim /etc/systemd/system/vncserver@\:1.service == 修改成如下内容, 注意红色字体
- [Unit]
- Description=Remote desktop service (VNC)
- After=syslog.target network.target
- [Service]
- Type=forking
- # Clean any existing files in /tmp/.X11-unix environment
- ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :1> /dev/null 2>&1 || :'
- ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver :1"
- PIDFile=/root/.vnc/%H%i.pid
- ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1> /dev/null 2>&1 || :'
- [Install]
- WantedBy=multi-user.target
- vim /etc/systemd/system/vncserver@\:2.service
- [Unit]
- Description=Remote desktop service (VNC)
- After=syslog.target network.target
- [Service]
- Type=forking
- # Clean any existing files in /tmp/.X11-unix environment
- ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :2> /dev/null 2>&1 || :'
- ExecStart=/usr/sbin/runuser -l shichunda -c "/usr/bin/vncserver :2 -geometry 1280*720 -depth 24"
- PIDFile=/home/shichunda/.vnc/%H%i.pid
- ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :2> /dev/null 2>&1 || :'
- [Install]
- WantedBy=multi-user.target
step3: 加载配置文件
systemctl daemon-reload
step4: 配置 vnc 密码
- su - root
- vncpasswd
- su - shichunda
- vncpasswd
注意: 也可以在 vncserver :1 启动的时候设置 vnc 密码
step5: 开启 vnc server
方法 1:
[root@file system]# vncserver :2
You will require a password to access your desktops.
- Password:
- Verify:
- New 'file:2 (root)' desktop is file:2
- Creating default startup script /root/.vnc/xstartup
- Starting applications specified in /root/.vnc/xstartup
- Log file is /root/.vnc/file:2.log
方法 2:
systemctl start vncserver-root@\:1.service
注意: 有的时候用这种方法不能启动 vnc server. 建议使用方法 1
step6: 客户端连接
客户端打开 vnc viewer, 之后输入 192.168.107.105:1, 之后输入 root 的密码即可 == 作为 root 登录
客户端打开 vnc viewer, 之后输入 192.168.107.105:2, 之后输入 shichunda 的密码 == 作为 shichnda 登录
查看 vncserver
- [root@file system]# vncserver -list
- TigerVNC server sessions:
- X DISPLAY # PROCESS ID
- :1 31143
关闭 vncserver
- [fanguihua@file ~]$ vncserver -kill :3
- Killing Xvnc process ID 37239
关于分辨率
默认连接到 server 上是 1024*768 分辨率, 可以在 server 的桌面设置分辨率
在 vncserver@:2.service 配置文件中设置 - geometry 1280*720 -depth 24 没有什么效果
##################################
问题
1 用 root 作为: 1 之后, shichunda 用户就不能用: 1 了?
是的
2 root 只有一个配置文件的话, 如果启动多个的话也是可以的, 但只有: 1 能够登录, 因为该用户只有 1 个配置文件
- vncserver :1
- vncserver :2
- vncserver :3
- [root@file system]# vncserver -list
- TigerVNC server sessions:
- X DISPLAY # PROCESS ID
- :1 31143
- :2 33659
- :3 34164
此时如果在用 shichunda 用户启动: 2 的话, 会报错, 如下:== 因为 root 已经占用了: 2 了
shichunda 的配置文件如下:
- [shichunda@file ~]$ more /etc/systemd/system/vncserver@\:2.service
- [Unit]
- Description=Remote desktop service (VNC)
- After=syslog.target network.target
- [Service]
- Type=forking
- # Clean any existing files in /tmp/.X11-unix environment
- ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :2> /dev/null 2>&1 || :'
- ExecStart=/usr/sbin/runuser -l shichunda -c "/usr/bin/vncserver :2 -geometry 1600*900"
- PIDFile=/home/shichunda/.vnc/%H%i.pid
- ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :2> /dev/null 2>&1 || :'
- [Install]
- WantedBy=multi-user.target
报错内容如下:
- [shichunda@file ~]$ vncserver :2
- Warning: file:2 is taken because of /tmp/.X2-lock
- Remove this file if there is no X server file:2
- A VNC server is already running as :2
把 root 的: 2 和: 3 关掉, 用 shichunda 启动: 2 才可以
来源: http://www.bubuko.com/infodetail-2718141.html