CentOS7安装VNC Server

安稳与你 提交于 2019-12-01 12:54:09

安装Tigervnc-server

# yum -y install tigervnc-server

没有外网

  1. 在本机或者能外网的机器上,yum安装后,在缓存的地方,拷贝rpm
  2. 查看yum的配置文件
    # vi /etc/yum.conf
    
    #rpm包缓存的目录
    cachedir=/var/cache/yum/$basearch/$releasever
    #0:不缓存,1:缓存
    keepcache=0
    debuglevel=2
    logfile=/var/log/yum.log
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    installonly_limit=5
    bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
    distroverpkg=centos-releas
    
  3. 修改yum.conf的keepcache为1
  4. 安装yum -y install tigervnc-server
  5. 拷贝yum缓存文件夹中的rpm
    路径:/var/cache/yum/x86_64/7/base/packages/

安装后,设置vnc密码

对当前用户设置vnc密码,可以切换到指定的用户进行远程桌面连接

# vncpasswd

系统配置文件路径下为你的用户添加一个VNC服务配置文件

  1. root用户
cp /lib/systemd/system/vncserver@.service  /etc/systemd/system/vncserver@:1.service
  1. 普通用户jim
cp /lib/systemd/system/vncserver@.service  /etc/systemd/system/vncserver@:2.service

注意:在 @后面的数字1表示的是显示界面的序列号,对应的端口是port 5900+序列号。对于每一个启动的vncserver服务,端口号5900会自增1

修改vnc server的配置文件

  1. 配置root用户
# vim /etc/systemd/system/vncserver@\:1.service

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

[Service]
Type=forking
#Type=simple
User=root

# 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
  1. 普通用户jim
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service
# vim /etc/systemd/system/vncserver@\:2.service

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

[Service]
Type=forking
#Type=simple
User=jim

# 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 jim-c "/usr/bin/vncserver %i"
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/jim/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

普通用户的ExecStart不同于root,加/sbin/runuser则会在启动服务时报以下错误

Job for vncserver@:2.service failed because the control process exited with error code. See “systemctl status vncserver@:2.service” and “journalctl -xe” for details.

设置vncpasswd

# vncpasswd    #root用户实例的vnc密码
# su - jim
$ vncpasswd    #普通用户一定要切换到用户自己的环境下

密码设置完成后回到root权限下,启动服务

加载进程,重启服务

# systemctl daemon-reload
# systemctl start vncserver@:1.service
# systemctl start vncserver@:2.service
# systemctl enable vncserver@:1.service    
# systemctl enable vncserver@:2.service    #开机启动

配置系统防火墙

# firewall-cmd --zone=public --add-port=5901/tcp
# firewall-cmd --zone=public --add-port=5902/tcp
# firewall-cmd --reload
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!