转载于 https://blog.csdn.net/wlzjsj/article/details/52149547
VNC主要是用于远程桌面控制,所以我们的思路是装vnc需要把一些桌面环境,字体包全部装好。
root@devgp01 /# ps -ef | grep vnc
root 25769 3442 0 08:46 pts/1 00:00:00 grep vnc
root@devgp01 /# rpm -qa | grep vnc
tigervnc-1.1.0-16.el6.centos.x86_64
tigervnc-server-1.1.0-16.el6.centos.x86_64
root@devgp01 /#
yum install tigervnc tigervnc-server -y
root@devgp01 /# rpm -qa | grep vnc
tigervnc-1.1.0-16.el6.centos.x86_64
tigervnc-server-1.1.0-16.el6.centos.x86_64
root@devgp01 /#
yum install -y gnome*
root@devgp01 /# vim /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see this URL:
# https://access.redhat.com/knowledge/solutions/7027
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERS="1:root"
#VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -localhost"
VNCSERVERARGS[1]="-geometry 800x600"
注释前面2行,我在后面加了2行。
root@devgp01 /# vim /root/.vnc/xstartup
#!/bin/sh
[ -r /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
export LANG
export SYSFONT
vncconfig -iconic &
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
gnome-session &
一个用户一个端口,第一个为5901 后面为5902,....
root@devgp01 /# vim /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Thu Dec 14 14:29:36 2017
*filter
:INPUT ACCEPT [290:54245]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [268:65326]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8500 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
COMMIT
# Completed on Thu Dec 14 14:29:36 2017
重启防火墙,当让其它方法都行,重点是开放5901端口。这里还有一个取巧的办法就是可以临时将防火墙关掉。
vncpasswd
修改vnc的连接密码
root@devgp01 /# service vncserver restart
Shutting down VNC server: 1:root [FAILED]
Starting VNC server: 1:root
New 'devgp01:1 (root)' desktop is devgp01:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/devgp01:1.log
[ OK ]
验证起来了
root@devgp01 /# ps aux | grep vnc
root 26340 0.2 0.1 113004 11524 pts/1 S 08:57 0:00 /usr/bin/Xvnc :1 -desktop devgp01:1 (root) -auth /root/.Xauthority -geometry 800x600 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn
root 26361 0.0 0.0 50148 2028 pts/1 S 08:57 0:00 vncconfig -iconic
root 26457 0.0 0.0 103252 824 pts/1 S+ 08:57 0:00 grep vnc
安装完成后在启动过程中遇到的问题:
参考:https://yq.aliyun.com/articles/5626