VirtualBox 4.3.6上安裝CentOS 6.5

目標:
一、在VirtualBox中安裝CentOS
二、配置虛擬機網絡,實現:
    a.主機聯網後,宿機可以經過主機上網
    b.無論主機聯網與否,主機都能SSH登陸宿機,而且主宿機能互相傳送文件c++

安裝環境:
一、Win7 64bit 旗艦版
二、VirtualBox 4.3.6
三、CentOS 6.5 x86_64shell


一、安裝VirtualBox虛擬機
安裝完成後,在網絡鏈接中多一個"VirtualBox Host-Only Network"(僅對設置Host_only模式的網絡有用)。vim

打開VirtualBox,管理--全局設定--網絡--僅主機(Host-Only)網絡:centos

雙擊「VirtualBox Host-Only Ethernet Adapter」:服務器

主機虛擬網絡界面:
    192.168.56.1
    255.255.255.0
DHCP 服務器:
    192.168.56.100
    255.255.255.0
    192.168.56.101
    192.168.56.254網絡


二、新建並設置CentOS虛擬機
新建虛擬機:dom

(1)宿機類型:Linux/Red Hat
(2)內存大小:1G
(3)建立磁盤:
    大小:20G
    選擇動態分配始佔用空間小,性能稍差;
    選擇固定大小佔用空間較大,性能較好,推薦
(4)存儲設置:
    CD/DVD控制器中加入準備好的CentOS安裝光盤
(5)網絡設置:
    宿機啓動第一塊網卡
    網卡1:NAT
        宿機(CemtOS)用這一網卡經過主機(Win7)上網(此時宿機能夠訪問主機),而主機不能訪問宿機。ide

        注意:能夠經過網卡1中的「端口轉發」設置主機訪問宿機中的相應服務,端口轉發規則設置具體以下:工具

       


三、安裝CentOS
簡要步驟介紹:
(1)語言:簡體中文
(2)安裝設備:基本存儲設備
(3)主機名:爲默認的localhost.localdomain(在沒有真正域名前)
(4)網絡配置:先忽略
(5)root用戶的密碼設置
(6)進行哪一種類型的安裝:使用自定義佈局
(7)簡單分區方案:/--18G swap--2G
(8)選擇Desktop安裝,且如今自定義
(9)將撥號網絡、聯網工具和Emacs勾選上
(10)開始安裝進程直到結束佈局

安裝完成以後,只要主機能夠上網,宿機的CentOS就可使用NAT(網卡1)經過主機上網。
網卡1默認分配的IP以下:
eth0:IP:10.0.2.15


四、CentOS安裝後網絡配置(可選
若須要配置網絡,可參考以下部分(不須要配置的話,直接進入第5部分。爲了簡單起見,此處我沒有做網絡配置):
(1)命令配置

# ifconfig eth0 192.168.56.102 netmask 255.255.255.0 //IP地址、子網掩碼
# route add default gw 192.168.56.1 dev eth0 //網關
# hostname centos //計算機名

(2)文件配置
CentOS中的網絡配置文件主要有如下幾類:

# 指定某個網絡接口的鏈接信息,每一個網絡設備對應一個這樣的文件
/etc/sysconfig/network-scripts/ifcfg-<interface-name>
# 指定全部網絡接口的路由和主機信息
/etc/sysconfig/network
# 相似 C:\Windows\System32\drivers\etc\hosts,用於無DNS下的機器名解析
/etc/hosts
# 指定DNS服務器的IP地址
/etc/resolv.conf
# 網絡管理工具使用的配置文件存儲目錄,不要作手動修改
/etc/sysconfig/networking/

<1>修改IP地址

假設有2塊網卡,要修改2塊網卡(Host-Only,NAT)的網絡設置:
進入/etc/sysconfig/network-scripts目錄,修改兩塊網卡的ifcfg文件以下:
a. 修改ifcfg-eth0文件,配置Host-only網絡:

# vim /etc/sysconfig/network-scripts/ifcfg-eth0:
# 第一塊網卡
DEVICE=eth0
# 開機啓動
ONBOOT=yes
# 啓動協議,static/dhcp
BOOTPROTO=static
# 網卡設備的物理地址,默認,與VirtualBox網絡設置界面一致
HWADDR=08:00:27:75:AD:13
# IP地址
IPADDR=192.168.56.102
# 掩碼  
NETMASK=255.255.255.0
# 網關
GATEWAY=192.168.56.1
# 配置DNS
DNS=192.168.56.1
# 設置了DNS指令後是否自動修改/etc/resolv.conf文件,啓動協議爲dhcp時此項默認yes  
PEERDNS=yes
# 非root用戶不能控制此設備  
USERCTL=no

b. 修改ifcfg-eth1文件,配置NAT網絡:

# vim /etc/sysconfig/network-scripts/ifcfg-eth1:
DEVICE=eth1  
ONBOOT=yes  
BOOTPROTO=dhcp  
PEERDNS=yes  
HWADDR=08:00:27:90:9B:08
USERCTL=no

<2>修改網關
修改對應網卡的網關的配置文件

# vi /etc/sysconfig/network
# 表示系統是否使用網絡,通常設置爲 yes。若是設爲 no,則不能使用網絡,並且不少系統服務程序將沒法啓動
NETWORKING=yes
# 設置本機的主機名,這裏設置的主機名要和/etc/hosts 中設置的主機名對應
HOSTNAME=centos
# 設置本機鏈接的網關的IP地址。例如,網關爲192.168.56.1
GATEWAY=192.168.56.1

<3>修改DNS
修改對應網卡的 DNS 的配置文件

# vi /etc/resolv.conf
# 域名服務器1
nameserver 202.101.224.68
# 域名服務器2
nameserver 202.101.224.69

<4>從新啓動網絡配置

# service network restart
或
# /etc/init.d/network restart


五、軟件源配置
國內速度較快的經常使用更新源以下:
http://mirrors.163.com/centos/    163-網易
http://mirrors.ta139.com/centos/   中國移動通訊(山東移動)
http://centos.ustc.edu.cn/centos/  中國科學技術大學
http://mirror.neu.edu.cn/centos/   東北大學

更新yum爲網易的源:

# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O CentOS-Base.repo

更新系統中能夠更新的軟件:

# yum update


六、安裝VBoxAdditions加強功能

在VirtualBox上安裝好CentOS後,再將VBoxAdditions加強功能安裝上,主要支持:虛擬機和主機之間共享文件以及無縫窗口和鼠標指針集成等。
(1)更新內核。CentOS 6.3對應的kernel默認爲2.6.32-279.el6.i686:

# uname -r
2.6.32-431.1.2.0.1.el6.x86_64

安裝加強功能須要kernel-devel包,必須保證kernel-devel和kernel版本的一致。查看軟件源中kernel-devel的版本:

# yum info kernel-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Installed Packages
Name        : kernel-devel
Arch        : x86_64
Version     : 2.6.32
Release     : 431.1.2.0.1.el6
Size        : 24 M
Repo        : installed
From repo   : updates
Summary     : Development package for building kernel modules to match the
            : kernel
URL         : License     : GPLv2
Description : This package provides kernel headers and makefiles sufficient to
            : build modules against the kernel package.

若二者版本不一致,則必須升級kernel:

# yum update kernel

升級完後必須重啓系統,新的kernel才能被使用。

(2)安裝kernel-devel和gcc。

# yum install kernel-devel gcc gcc-c++

(3)安裝加強功能。進入加強功能光盤根目錄,執行Linux下的安裝命令:

# cd /media/VBOXADDITIONS_4.3.6_91406
# ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.6 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [肯定]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [肯定]
Building the shared folder support module                  [肯定]
Building the OpenGL support module                         [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [肯定]
Installing the Window System drivers
Installing X.Org Server 1.13 modules                       [肯定]
Setting up the Window System to use the Guest Additions    [肯定]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services componen[肯定]

解決Building the OpenGL support module FAILE的問題:

# cd /media/VBOXADDITIONS_4.3.6_91406
# export MAKE='/usr/bin/gmake -i'
# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.6 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.6 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules       [肯定]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [肯定]
Building the shared folder support module                  [肯定]
Building the OpenGL support module                         [肯定]
Doing non-kernel setup of the Guest Additions              [肯定]
You should restart your guest to make sure the new modules are actually used
Installing the Window System drivers
Installing X.Org Server 1.13 modules                       [肯定]
Setting up the Window System to use the Guest Additions    [肯定]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services componen[肯定]

至此,加強功能已安裝完成,共享文件、無縫窗口和鼠標指針繼承等功能已經可使用啦!


七、宿機重啓系統,主機和宿機相互ping下

主機和宿機的網絡配置:

    主機(Win7)IP:192.168.0.102;網關:192.168.0.1;DNS:101.226.4.6,114.114.114.114

    宿機(CentOS)IP:10.0.2.15

    網卡1:NAT

    端口轉發規則:

   

   

    宿機--主機:ping 192.168.0.102 (經過)

    宿機--網絡:ping www.163.com (經過)

   

    Win7上putty鏈接CentOS:

   

    這裏的Host Name也可填寫爲:localhost

   

    這裏設置爲UTF-8,是爲了不CentOS中的中文目錄爲在putty上顯示亂碼。

    點擊左側的Seesion回到最初的界面,單擊「Save」將Session保存,而後單擊「Open」:

   

相關文章
相關標籤/搜索