Linux下VNC安装与配置(含解决xhost:unable to open display)
1、检查是否安装VNC
[root@localhost ~]# yum install -y vnc vnc-server
2、[root@localhost ~]# chmod 777 root/.vnc/xstartup
3、修改vnc 分辨率:
vi /usr/bin/vncserver:
$geometry = "1200x700"
4、修改 /root/.vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
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 &
5、配置VNC
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
[root@localhost ~]# vi /etc/sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/vncserver@.service
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600"VNCSERVERS="2:oracle"
VNCSERVERARGS[1]="-geometry 800x600"
[root@localhost ~]# vi /etc/systemd/system/vncserver@:1.service
#将<USER>替换成用户root:
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/home/root/.vnc/%H%i.pid
重启systemd:
[root@localhost ~]# systemctl daemon-reload
永久开启VNC服务:
[root@localhost ~]# systemctl enable vncserver@1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@1.service
to /usr/lib/systemd/system/vncserver@.service.
6、启动VNC服务(解决xhost:unable to open display)
[root@localhost ~]# vncserver
New 'localhost:1 (root)' desktop is localhost.localdomain:1
Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost:1.log
[root@localhost ~]# export DISPLAY=localhost.localdomain:1
[root@localhost ~]# xhost +
access control disabled, clients can connect from any host
再进入oracle用户(安装Oracle时需要图形化界面)
[oracle@localhost ~]$ export DISPLAY=localhost:1
[oracle@localhost ~]$ xhost +
access control disabled, clients can connect from any host
注意:一定要在root用户下先启动vnc并配置diaplay,执行xhost +,再进入oracle用户进行操作
7、关闭VNC服务
[root@localhost ~]# ps -ef|grep -i vnc (查看vnc的进程号)
root 5055 1 0 16:26 tty1 00:00:13 /bin/Xvnc :1 -auth /root/.Xauthority -desktop localhost.localdomain:1
(root) -fp catalogue:/etc/X11/fontpath.d -geometry 1200x700 -pn -rfbauth /root/.vnc/passwd -rfbport 5901 -rfbwait 30000
root 5748 5717 0 17:06 pts/0 00:00:00 grep --color=auto -i vnc
[root@localhost ~]# kill -9 5055 (通过杀掉进程关闭vnc)
或者:
[root@localhost ~]# vncserver -kill :3 #注意这里冒号前有空格,推荐这种方法
Killing Xvnc process ID 8083
8、删除无效的vnc端口
[root@localhost ~]# cd /tmp/.X11-unix/
[root@localhost .X11-unix]# ls
X1 X2 X3
[root@localhost .X11-unix]# rm X*
rm: remove socket X1 ? Y
rm: remove socket X2 ? Y
rm: remove socket X3 ? Y
[root@localhost .X11-unix]# ls
[root@localhost .X11-unix]#
更多推荐
所有评论(0)