CentOS7安装vncserver

http://www.cnblogs.com/kevingrace/p/5821450.htmlhtml

不作过多介绍了,下面直接记录下centos7系统下安装配置vncserver的操做记录linux

1)关闭防火墙
centos的防火墙是firewalld,关闭防火墙的命令
[root@localhost ~]# systemctl stop firewalld.service #中止firewall
[root@localhost ~]# systemctl disable firewalld.service #禁止firewall开机启动vim

[root@localhost ~]# setenforce 0 
[root@localhost ~]# getenforce 
[root@localhost ~]# cat /etc/sysconfig/selinux 
SELINUX=disabled
SELINUXTYPE=targetedcentos

2)安装软件
[root@localhost ~]# yum update
[root@localhost ~]# yum groupinstall "GNOME Desktop" "X Window System" "Desktop" 
[root@localhost ~]# yum install tigervnc-server tigervnc vnc vnc-servertcp

3)配置vnc链接
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service 
修改/etc/systemd/system/vncserver@:1.service
找到这一行
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid测试

这里直接用root 用户登陆,因此我替换成
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pidcentos7

若是是其余用户的话好比john替换以下
ExecStart=/sbin/runuser -l john -c "/usr/bin/vncserver %i"
PIDFile=/home/john/.vnc/%H%i.pidspa

因为直接root用户登陆,因此配置以下:
[root@localhost ~]# cat /etc/systemd/system/vncserver@:1.service
.........
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.targetunix

[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 || :'rest

[Install]
WantedBy=multi-user.target

为VNC设密码
[root@localhost ~]# vncpasswd
123456

[root@localhost ~]# vim /etc/libvirt/qemu.conf 
vnc_password = "123456"
vnc_listen = "0.0.0.0"

重加载 systemd
[root@localhost ~]# systemctl daemon-reload

启动vnc
[root@localhost ~]# systemctl enable vncserver@:1.service
[root@localhost ~]# systemctl start vncserver@:1.service

注意,此处关闭了防火墙
若是防火墙开了,须要开通一下规则:
[root@localhost ~]# firewall-cmd --permanent --add-service vnc-server
[root@localhost ~]# systemctl restart firewalld.service
若是是iptable,则须要在/etc/sysconfig/iptables里添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5903 -j ACCEPT

关闭vnc链接
[root@localhost ~]# /usr/bin/vncserver -kill :1

测试vnc链接

使用vncviewer链接, 其中VNC Server指定为 IP:1 (192.168.157.100:1), 其它设置均为缺省便可。

相关文章
相关标签/搜索