『精品』『多用户』13 vnc命令详解

13 vnc命令详解

设置多个用户 https://zls.bndstone.com/1049.html
设置单个用户 https://zls.bndstone.com/1658.html

1-1. 查看是否已安装服务VNC

1
2
rpm -qa | grep tigervnc
rpm -qa | grep tigervnc-server

2-1. 安装 VNC

1
2
yum install -y tigervnc
yum install -y tigervnc-server

3-1. 启动VNC [第一次会要求输密码,这个密码是VNC登录密码,不是root密码]

1
vncserver

3-2. 看一下哪些端口可以使用

1
vncserver -list

3-3. 原始的配置文件位置

1
vi /usr/lib/systemd/system/vncserver@.service

3-4. 复制配置文件

1
cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

原本的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

主要要换的是这三行

1
2
3
Type=forking
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid

3-5. 修改配置文件

1
vi /etc/systemd/system/vncserver@:1.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[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 %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"                
PIDFile=/root/.vnc/%H%i.pid                                            
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'        

[Install]
WantedBy=multi-user.target

3-6. 配置多个账号: –ancky2006

1
cp /etc/systemd/system/vncserver@:1.service /etc/systemd/system/vncserver@:2.service
1
vi /etc/systemd/system/vncserver@:2.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[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 %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l ancky2006 -c "/usr/bin/vncserver %i"                
PIDFile=/home/ancky2006/.vnc/%H%i.pid                                            
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'        

[Install]
WantedBy=multi-user.target

给 vncserver@:2.service 设置密码,否则无法启动成功

1
su ancky2006
1
vncpasswd

3-7. 配置多个账号: –test

1
cp /etc/systemd/system/vncserver@:1.service /etc/systemd/system/vncserver@:3.service
1
vi /etc/systemd/system/vncserver@:3.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[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 %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l test -c "/usr/bin/vncserver %i"                
PIDFile=/home/test/.vnc/%H%i.pid                                            
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'        

[Install]
WantedBy=multi-user.target

给 vncserver@:3.service 设置密码,否则无法启动成功

1
su test
1
vncpasswd

3-8. 让修改后的文件生效

1
systemctl daemon-reload

3-9. 添加用户配置-单个root

1
vi /etc/sysconfig/vncservers
1
2
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 -BlacklistTimeout 0"

3-10. 添加用户配置-多个root,ancky2006,test

1
vi /etc/sysconfig/vncservers
1
2
3
4
VNCSERVERS="1:root 2:ancky2006 3:test"
VNCSERVERARGS[1]="-geometry 1024x768 -BlacklistTimeout 0"
VNCSERVERARGS[2]="-geometry 1024x768 -BlacklistTimeout 0"
VNCSERVERARGS[3]="-geometry 1024x768 -BlacklistTimeout 0"

3-11. 放行端口

1
2
3
firewall-cmd --zone=public --permanent --add-port=5900-5999/tcp
firewall-cmd --zone=public --permanent --add-port=5900-5999/udp
firewall-cmd --reload

3-12. 从阿里后台放行5901,5902,5903端口

3-13. 开启,关闭,vnc

奇怪了.第一次安装完时,启动总是报错,但reboot重启后,以下所有代码都正常.
1
2
3
4
systemctl status vncserver@:1.service        //查看状态
systemctl start vncserver@:1.service         //启动
systemctl stop vncserver@:1.service          //关闭
systemctl enable vncserver@:1.service        //开机自启动

3-14. 重启服务器

1
reboot

3-15. 用VNC连接.出现这个页面说明已经好了.(因为系统是mini版.要安装桌面板才能进入.)

4. 配置桌面环境

1
https://zls.bndstone.com/1066.html

4-1. 更新yum,否则会出现软件冲突

1
yum update -y

4-2. 安装GNOME Desktop图形桌面服务

1
yum groupinstall -y "GNOME Desktop"
这步骤最后时要等挺久,所以操作时尽量通过 hk vps windows 上 连接 hk vps centos 7. 以免做到一半掉线.

4-3. 设置桌面运行模式为默认启动模式

1
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

4-4. 重启

1
reboot

4-5. 用VNC连接.进入系统

4-1. 查看服务状态vncserver@:1.service

1
systemctl status vncserver@:1.service

4-2. 启动服务vncserver@:1.service

1
systemctl start vncserver@:1.service

4-3. 关闭服务vncserver@:1.service

1
systemctl stop vncserver@:1.service

4-4. 重启服务vncserver@:1.service

1
systemctl restart vncserver@:1.service

4-5. 设置开机启动项服务vncserver@:1.service

1
systemctl enable vncserver@:1.service

4-6. 取消开机启动项服务vncserver@:1.service

1
systemctl disable vncserver@:1.service

4-7. 列出各种服务开机是否启动

1
systemctl list-unit-files

4-8. 列出vncserver@:1.service服务是否开机启动

1
systemctl list-unit-files | grep vncserver@:1.service

4-9. 列出vncserver@:1.service服务是否开机启动

1
systemctl is-enabled vncserver@:1.service

4-10. 查看5901是否已经被占用

1
lsof -i:5901

5-1. 查看服务状态vncserver@:2.service

1
systemctl status vncserver@:2.service

5-2. 启动服务vncserver@:2.service

1
systemctl start vncserver@:2.service

5-3. 关闭服务vncserver@:2.service

1
systemctl stop vncserver@:2.service

5-4. 重启服务vncserver@:2.service

1
systemctl restart vncserver@:2.service

5-5. 设置开机启动项服务vncserver@:2.service

1
systemctl enable vncserver@:2.service

5-6. 取消开机启动项服务vncserver@:2.service

1
systemctl disable vncserver@:2.service

5-7. 列出各种服务开机是否启动

1
systemctl list-unit-files

5-8. 列出vncserver@:2.service服务是否开机启动

1
systemctl list-unit-files | grep vncserver@:2.service

5-9. 列出vncserver@:2.service服务是否开机启动

1
systemctl is-enabled vncserver@:2.service

5-10. 查看5902是否已经被占用

1
lsof -i:5902

6-1. 查看服务状态vncserver@:3.service

1
systemctl status vncserver@:3.service

6-2. 启动服务vncserver@:3.service

1
systemctl start vncserver@:3.service

6-3. 关闭服务vncserver@:3.service

1
systemctl stop vncserver@:3.service

6-4. 重启服务vncserver@:3.service

1
systemctl restart vncserver@:3.service

6-5. 设置开机启动项服务vncserver@:3.service

1
systemctl enable vncserver@:3.service

6-6. 取消开机启动项服务vncserver@:3.service

1
systemctl disable vncserver@:3.service

6-7. 列出各种服务开机是否启动

1
systemctl list-unit-files

6-8. 列出vncserver@:3.service服务是否开机启动

1
systemctl list-unit-files | grep vncserver@:3.service

6-9. 列出vncserver@:3.service服务是否开机启动

1
systemctl is-enabled vncserver@:3.service

6-10. 查看5903是否已经被占用

1
lsof -i:5903
备注:防火墙要端口放行,而不是直接关闭,直接关闭会连不上,出现”no route to host”,因为我用的是kvm虚拟机,需要firewalld打开才能连上网络

Leave a Reply

Your email address will not be published. Required fields are marked *