masayuki5160's diary

名古屋でエンジニアしてます。

VNCサーバ構築してみる1

リモートデスクトップしたくていろいろ調べてたら、
VNCというのをみつけたのでやってみました。

参考サイト
CentOS5.2にVNCサーバ環境を構築した http://d.hatena.ne.jp/rdera/20090303/1236071478
はじめての自宅サーバ構築 http://kajuhome.com/vnc.shtml#n08


環境:CentOS 5.2

手順
1.VNCインストール
# yum install vnc

2./etc/sysconfig/vncservers の編集

[root@localhost .vnc]# cat /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
# url:http://www.uk.research.att.com/archive/vnc/sshvnc.html.

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# Use "-nohttpd" to prevent web-based VNC clients connecting.

# 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="1:admin"
VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp -nohttpd"


3.パスワード設定(VNC Viewerからの接続に使用)
# vncpasswd
Password:
Verify:

4.~/.vnc/xstartupの編集

[root@localhost .vnc]# cat /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 &
gnome-session


5.VNCサーバの起動
# vncserver -geometry 800x600

New 'localhost.localdomain:1 (masayuki)' desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

6.VNC Viewerから接続
下記からインストール
http://www.realvnc.com/products/download.html

VNC Viewer起動後、host、passwordを入力し完了。
※host名の後ろに:ディスプレイ番号を追記("host:ディスプレイ番号")

7.VNCサーバの停止

# vncserver -kill :1
Killing Xvnc process ID 5783

以下作業ログ

[root@localhost masayuki]# yum install vnc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies

    • > Running transaction check
      • > Package vnc.i386 0:4.1.2-14.el5_6.6 set to be updated
    • > Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vnc i386 4.1.2-14.el5_6.6 base 160 k

Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 160 k
Is this ok [y/N]: y
Downloading Packages:
vnc-4.1.2-14.el5_6.6.i386.rpm | 160 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : vnc 1/1

Installed:
vnc.i386 0:4.1.2-14.el5_6.6

Complete!
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]# vi /etc/sysconfig/vncservers
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]# vnc
vncconfig vncpasswd vncserver vncviewer
[root@localhost masayuki]# vncpasswd
Password:
Verify:
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]#
[root@localhost masayuki]# vi ~/.vnc/xstartup
[root@localhost .vnc]# vncserver -geometry 800x600

New 'localhost.localdomain:1 (masayuki)' desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

[root@localhost .vnc]#