centos 7.0 vncserver 相关配置

VNC-Server installation on CentOS 7

Version 1.0

Author: Srijan Kishore

Last edited 1/Sep/2014

This guide explains how to configure VNC-server in CentOS 7.0 server. It is a very convinient way of administrating the CentOS 7.0 with the help of GUI(Graphics User Interface). The GUI can be access any where with the help of the VNC-client on any OS. The basic condition is that the connecting OS must have VNC-clients installed in it.

1 Preliminary Note

This tutorial is based on CentOS 7.0 server, so you should set up a basic CentOS 7.0 server installation before you continue with this tutorial. The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname.

IP address  

192.168.0.100

Gateway  

192.168.0.1

DNS    

8.8.8.8    8.8.4.4

Hostname

server1.example.com

VNC-server benefits
  • Remote GUI administration makes work easy & convenient.
  • Clipboard sharing between host CentOS server & VNC-client machine.
  • GUI tools can be installed on the host CentOS server to make the administration more powerful
  • Host CentOS server can be administered through any OS having the VNC-client installed.
  • More reliable over ssh graphics.
  • More reliable over RDP connections.

2 Installation

I am logged in my system with

root

, & now I will be installing the VNC-server.

yum groupinstall "GNOME Desktop"

Further install

yum install tigervnc-server

3 Adding VNC user

In my case I am using  user=srijan

it will differ in your case. You can use any username for the same.


useradd srijan

In CentOS 7.0 there is change in the vncserver configuration file. Before ContOS 7.0 it was  /etc/sysconfig/vncservers and now it have changed in

/lib/systemd/system/vncserver@.service

. Next I will use the original file and create the configuration file as shown:

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

Now we will edit the file as follows:

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

Replace the string <USER> with appropriate vncuser’s username.  In my case I will be using the user srijan just created above:

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

If you wish to add more users you would create a new vncserver@:#.service file and change the <USER> string to the new users.

Firewall settings:

firewall-cmd --permanent --zone=public --add-service vnc-server firewall-cmd --reload

Now switch to the vncuser just created above and start the vnc service as:

[srijan@server1 ~]$ vncserver

You will require a password to access your desktops.

Password: <--yourvncpassword

Verify: <--yourvncpassword

xauth:  file /home/srijan/.Xauthority does not exist

New 'server1.example.com:1 (srijan)' desktop is server1.example.com:1

Creating default startup script /home/kishore/.vnc/xstartup

Starting applications specified in /home/kishore/.vnc/xstartup

Log file is /home/srijan/.vnc/server1.example.com:1.log

[srijan@server1 ~]$

Now make the service enabled on after every reboot with root credentials:

su - systemctl daemon-reload

systemctl enable vncserver@:1.service

reboot systemctl start vncserver@:1.service

4 VNC Client

At client end my OS is Ubuntu 14.04 with vino installed on my client machine. Otherwise you can install any VNC-client of your choice. In case other OS say Windows-7 you can install Realvnc-client or any other of your choice.

Now I am going to connect with the VNC server through my VNC-client at 192.168.0.100:5901

Click to enlarge

It will prompt for the password, give the vnc password just created above as follows:

Click to enlarge

Put yourvncpassword the same which you gave at the time of adding the user srijan .

Click to enlarge
Now you are connected with the CentOS 7.0 Server. In case you want to add more users to access the vnc-console you need to add :

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:2.service vi /etc/systemd/system/vncserver@:2.service

For instance I am using user

kishore

, entries will be like this
[...]
[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=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
#PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStart=/sbin/runuser -l kishore -c "/usr/bin/vncserver %i"
PIDFile=/home/kishore/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

Now switch to the vncuser just created above and start the vnc service as:

[kishore@server1 ~]$ vncserver

You will require a password to access your desktops.

Password: <--yourvncpassword

Verify: <--yourvncpassword

xauth:  file /home/kishore/.Xauthority does not exist

New 'server1.example.com:2 (kishore)' desktop is server1.example.com:2

Creating default startup script /home/kishore/.vnc/xstartup

Starting applications specified in /home/kishore/.vnc/xstartup

Log file is /home/kishore/.vnc/server1.example.com:2.log

[kishore@server1 ~]$

Now  start the service on after every reboot for second user as follows:

systemctl daemon-reload

systemctl enable vncserver@:2.service

reboot systemctl start vncserver@:2.service

This will enable user kishore to get the access to the VNC-server with the port 5902 as

192.168.0.100:5902

. In the same way you can add the root user also.

Congrats you have configured the VNC-server in CentOS 7.0 successfully :) 

如果远程Linux的VNC桌面很久没有输入,那么使用VNC View打开远程linux桌面时,桌面显示不出来,显示一片黑屏,并且点击键盘或者鼠标仍然毫无反应,仍然一片黑屏。
这时候需要在vnc server上设置一下。

编辑 /root/.vnc/xstartup 
[root@localhost ~]# vi /root/.vnc/xstartup   

去掉下面两行的注释: 
unset SESSION_MANAGER  
exec /etc/X11/xinit/xinitrc  
执行下面的命令重启vnc server:
[root@localhost ~]# vncserver -kill :1  
[root@localhost ~]# vncserver :1 

安装步骤:

       关闭防火墙,centos的防火墙是firewalld,关闭防火墙的命令systemctl stop firewalld.service 。关闭enforce,setenforce 0。

 1.安装tigervncserver,yum install tigervnc-server tigervnc-server-module

 2.拷贝配置文件cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

 3.进入到配置文件目录cd /etc/systemd/system

 4.修改配置文件vim vncserver@:1.service

配置文件内容为:

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

[Service]
Type=forking
User=root
ExecStart=/usr/bin/vncserver :1 -geometry 1280x1024 -depth 16 -securitytypes=none -fp /usr/share/X11/fonts/misc
ExecStop=/usr/bin/vncserver -kill :1

[Install]
WantedBy=multi-user.target

 5.  启用配置文件 systemctl enable vncserver@:1.service

 6. 设置登陆密码:vncpasswd

 7. 启动vncserver:systemctl start vncserver@:1.service

 8 . 启动状态查看:systemctl status vncserver@:1.service

 9.查看端口状态:netstat -lnt | grep 590*

 10.查看报错信息:grep vnc /var/log/messages#!/bin/sh


vim /root/.vnc/xstartup 
LANG="zh_CN.UTF-8"
#unset SESSION_MANAGER
#unset DBUS_SESSION_BUS_ADDRESS
exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
gnome-session &





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值