桌面版centos安装vncserver并在windows下使用VNC Viewer远程连接

首先关闭防火墙

在Centos中安装vncserver

yum install tigervnc-server

 

拷贝一份  /lib/systemd/system/[email protected]

cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

编辑/etc/systemd/system/vncserver@:1.service

vim /etc/systemd/system/vncserver@:1.service

 修改内容为

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
#Type=forking
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=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x720"                #其中的root是用户名
PIDFile=/home/oracle/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

保存后重新加载此文件

systemctl daemon-reload

 设置开机启动

systemctl enable vncserver@:1.service

执行

vncserver

设定密码,输入自己的密码即可

杀死服务并重启

vncserver -kill :1
systemctl daemon-reload
systemctl restart vncserver@:1.service

 查看服务开启状态

systemctl restart vncserver@:1.service

出现下列情况表示服务成功开启

查看服务开启的端口号

netstat -lntpu | grep vnc --color

现在在windows中下载 VNC Viewer (百度即可) 并安装

运行软件

在搜索框中输入Centos的IP以及端口(我这里是5901),然后回车连接,在弹框中输入之前设置的密码即可成功连接

不过这个软件不支持文件传输,还是很不方便的(^ _^)

遇到的问题:

开启服务失败

[root@xinglichao hadoop]# systemctl restart vncserver@:1.service
Job for vncserver@:1.service failed because the control process exited with error code. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.

解决办法1:执行下列命令删除 /tmp/.X11-unix/

rm -rf /tmp/.X11-unix/

(但是在我这并没有解决问题,方法来源于网络

解决办法2:将/etc/systemd/system/vncserver@:1.service文件中的Type改为simple(之前默认为forking)

[Service]
#Type=forking
Type=simple

本节完......

猜你喜欢

转载自www.cnblogs.com/xinglichao/p/9774628.html