2010年11月5日 星期五

Ubuntu kvm server 建製

我們就用這張圖來建製一個中小企業的網路吧!




首先我們先建立kvm這個虛擬化軟體
$sudo apt-get install kvm libvirt-bin

$ sudo apt-get install build-essential python-libvirt python-gtk-vnc python-gnome2-desktop python-urlgrabber intltool libxml2-dev libvirt-dev libgtk2.0-dev libglade2-dev libgtk-vnc-1.0-dev

取得 virt-manager 原始碼
$ cd ~
$ mkdir virt
$ cd virt
$ wget http://virt-manager.et.redhat.com/download/sources/virt-manager/virt-manager-0.8.4.tar.gz
$ wget http://virt-manager.et.redhat.com/download/sources/virtinst/virtinst-0.500.3.tar.gz
$ wget http://virt-manager.et.redhat.com/download/sources/virt-viewer/virt-viewer-0.2.0.tar.gz
$ cd ~/virt
$ tar xvzf virt-manager-0.8.4.tar.gz
$ cd virt-manager-0.8.4/
$ ./configure
$ make
$ sudo make install

$ cd ~/virt
$ tar -xvzf virtinst-0.500.3.tar.gz
$ cd virtinst-0.500.3/
$ sudo python setup.py install

$ cd ~/virt
$ tar -xvzf virt-viewer-0.2.0.tar.gz
$ cd virt-viewer-0.2.0/
$ ./configure
$ make
$ sudo make install

virsh console 設定

sudo nano /etc/init/ttyS0.conf

貼上下列四行
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 115200 ttyS0 xterm

好了這樣就可以了,裝好後kvm會在應用程式→系統管理中

再來依上圖建立網段
100的,99的,66的網段




我先建立66的網段,其它的99和100網段請看官們如法泡製吧!

 

















1.請在編輯中選Host Details即可出現如上圖
2.選虛擬網路按加號那個選項


下一步



































 


取個你容易記的名字,因為我要建66的網段所以就有66這個數字


請打172.30.66.0/24吧(≧◇≦)
 

Enable DHCP 不要打勾,下一步



isolated virtual network












這樣你的66的網段就完成了,那99100的網段也是如法泡製







 三個網段建好了後請在本機(實體機器上)安裝bridge
 
$ sudo apt-get install bridge-utils
再打:
$ sudo nano /etc/network/interfaces
 要注意的是有個 bridge_ports ppp0 這個ppp0是指對外的網卡,所以你要清楚你的對內和對外的網卡是什麼喔! (≧◇≦)

再來就在重新起動你的網路吧!
$ sudo /etc/init.d/networking restart
實體機器弄好了就來裝虛擬的網卡吧



1.先開啟你的虛擬機器管理員。
2.選一台你要裝網卡的機器。
3.按編輯中的virtual machine details。
3.再選擇檢視詳細資訊”。
4.add hardware 選擇network。
5.再來選一個你剛設的網段吧(有100、99、66三個網段喔)、請看官要注意,你在那台機器上  
   設。
6.再按完成就好了喔。

裝好網卡後請下逹下命的指令,這樣你的網卡才能重置

(一定要下此指令,不然新增的網卡會抓不到,這是ubuntu的最大缺憾,不能自動偵測網卡拉::>_<::)

$ sudo rm /etc/udev/rules.d/70-persistent-net.rules


US104-100-NAT的設定


將裝好的網卡重置
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules

建立網路
sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
  address 172.30.100.254
  netmask 255.255.255.0

啟動nat 加入路由 對外透通
$ sudo nano /etc/rc.local
再最下方打以下指令

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


route add -net 172.30.66.0 netmask 255.255.255.0 gw 172.30.100.5
route add -net 172.30.99.0 netmask 255.255.255.0 gw 172.30.100.6 

啟動 (static route)
$ sudo nano /etc/sysctl.conf

#net.ipv4.ip_forward=1
  取消 #字號

US104-100-RD的設定
將裝好的網卡重置(一定要打喔 ,不然會抓不到網卡!)
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules

建立網路
sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
  address 172.30.100.2
  netmask 255.255.255.0
  gateway 172.30.100.254


US104-99-Router的設定(66Router也是一樣)

將裝好的網卡重置
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules

建立網路
sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
  address 172.30.100.6
  netmask 255.255.255.0
  gateway 172.30.100.254

auto eth1
iface eth1 inet static
  address 172.30.99.254
  netmask 255.255.255.0



啟動(static route)
$ sudo nano /etc/sysctl.conf
#net.ipv4.ip_forward=1
   取消#字號








US104-99-DM的設定(66-DM也是一樣的設法)
將裝好的網卡重置
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules

編網路
sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
  address 172.30.99.5      ←如果是66-DM是172.30.66.5
  netmask 255.255.255.0
  gateway 172.30.99.254  ←如果是66-DM是172.30.66.254




DHCP裝在US104-100-RD
DHCP裝在US104-100-RD

$ sudo apt-get install dhcp3-server


1. 編輯 DHCP 設定檔
$ sudo nano /etc/dhcp3/dhcpd.conf
subnet 172.30.100.0 netmask 255.255.255.0 {
        option routers                  172.30.100.254;
        option subnet-mask              255.255.255.0;
        option broadcast-address        172.30.100.255;
        option domain-name-servers      172.30.100.2;
        option netbios-name-servers     172.30.100.2;    
        option netbios-node-type 8;

        default-lease-time 86400;
        max-lease-time 86400;

       range 172.30.100.128 172.30.100.220;
}

subnet  172.30.66.0 netmask 255.255.255.0 {
        option routers                  172.30.66.254;
        option subnet-mask              255.255.255.0;
        option broadcast-address        172.30.66.255;
        option domain-name-servers      172.30.66.5;
        option netbios-name-servers     172.30.100.2;   ←都是RD那台IP位置
        option netbios-node-type 8;

        default-lease-time 86400;
        max-lease-time 86400;

          range 172.30.66.128 172.30.66.220;




subnet  172.30.99.0 netmask 255.255.255.0 {
        option routers                  172.30.99.254;
        option subnet-mask              255.255.255.0;
        option broadcast-address        172.30.99.255;
        option domain-name-servers      172.30.99.5;
        option netbios-name-servers     172.30.100.2;
        option netbios-node-type 8;

        default-lease-time 86400;
        max-lease-time 86400;

           range 172.30.99.128 172.30.99.220;
}

重新啟動 DHCP Server

sudo /etc/init.d/dhcp3-server restart

DHCP Relay Agent分別裝在

1.US104-99-Router

2.US104-66-Router
指令如下
$ sudo apt-get install dhcp3-relay

1.172.30.100.2  (ip)
2.eth0 eth1 內網外網
3.不作設定





 都設定好了我們來試試用99-DM PING 66-DM








架構圖中的左下和右下分別有一台clint pc(本測試是用windows 2003的系統)
那我們試試互ping能不能通和分別能不能上網(≧◇≦)!














 有通吧 呵呵~v( ̄︶ ̄)v~




samba的設定
US104-100-RD的設定
1.sudo apt-get install samba
2.sudo apt-get install tree
3.重新開機
4.pstree

看是否有出現 smbdnmbd,有的話samba就架起來了!

扮演 file server
sudo nano /etc/samba/smb.conf
請再最下面的地方打


[global]
workgroup = it100
wins support = yes
netbios name = it100MB
os level = 255

domain master = no
preferred master = yes
local master = yes

browse list = yes
dns proxy = no
security = user
guest only = no
guest ok = no

name resolve order = wins lmhosts bcast

# 中文顯示設定
unix charset  = utf8
display charset = utf8
dos charset  = cp950

log file = /var/log/samba/log.%m
max log size = 1000
syslog = 2

[homes]
  comment = Home Directories

  # browseable = no 這設定, 使得在網芳系統不會看到 homes 這名稱
  browseable = no

  # By default, the home directories are exported read-only. Change next
  # parameter to ‘yes’ if you want to be able to write to them.
  writable = yes

  # By default, \\server\username shares can be connected to by anyone
  # with access to the samba server. Un-comment the following parameter
  # to make sure that only “username” can connect to \\server\username
  valid users = %S

  # 符合指定格式的檔案(.*), 會自動被附於 '隱藏' 屬性
  hide files = /.*/   
          
  create mode = 0664
  directory mode = 0775
 
設定完重開機
 
 
IT66 IT99 SAMBA 設定
(1) sudo nano /etc/samba/smb.conf
[global]
workgroup = it100
wins server = 172.30.100.2  
wins proxy = no     
netbios name = it66MB
os level = 255
domain master = no
preferred master = yes
local master = yes

browse list = yes
dns proxy = no
security = user
guest only = no
guest ok = no

name resolve order = wins lmhosts hosts bcast
log file = /var/log/samba/log.%m

# 登錄檔最大僅能到多少 Kbytes ,若大於該數字,則會被 rotate
max log size = 1000
syslog = 2

[homes]
  comment = Home Directories

  # browseable = no 這設定, 使得在網芳系統不會看到 homes 這名稱,也就不會看到使用者帳號
  # By default, the home directories are exported read-only. Change next
  # parameter to ‘yes’ if you want to be able to write to them.
  writable = yes #可以寫入資料

  # By default, \\server\username shares can be connected to by anyone
  # with access to the samba server. Un-comment the following parameter
  # to make sure that only “username” can connect to \\server\username
  valid users = %S #當驗證過後,我們可以對檔案有完全控制
  # 符合指定格式的檔案(.*), 會自動被附於 '隱藏' 屬性  hide files = /.*/

設定完重開機 










這就是裝好的圖喔~ ~^_^~~


DNS server的設定

US104-100-RD 上安裝DNS
請打:$ sudo apt-get install bind9
請檢視本機電腦名稱(有二個地方要改)
 
1. sudo nano /etc/hosts

















2. sudo nano /etc/hostname 

















 
 
 
 
 
 
 
 
 
 
手動設定本機 IP 位址, 以做為 DNS Server  IP 位址
$ sudo nano /etc/network/interfaces






$sudo nano /etc/resolv.conf
 

 
sudo /etc/init.d/bind9 restart←重新啟動
p.s 清除DNS Cache 請打:$sudo rndc flush。
windowsipconfig /flushdns
 


再設定:$sudo nano /etc/bind/named.conf.local















 再設定
$sudo nano /etc/bind/db.kvm

















 
 
 
 
 
 
 
 
 
 
 ***再來修改US104-100-NAT***
 
修改成第二部的dns 也就是secondary master
安裝DNS:
$ sudo apt-get install bind9
 
修改/etc/bind/named.conf.local
$ sudo nano /etc/bind/named.conf.local


























Mail server的設定

設定66DM(99DM安裝步驟一樣)
安裝
$ sudo apt-get install postfix




設定
$ sudo dpkg-reconfigure postfix





 



 





 


 
























補充:如果你想再check一次sudo dpkg-reconfigure postfix 中的設定是否正確可以在

$ sudo nano /etc/postfix/main.cf 中的環境再來確定一次


用命令方法收發信

安裝此軟體
$ sudo apt-get install heirloom-mailx

在每個使用者的家目錄底下會產生電子郵件的資料夾
$ sudo postconf -e 'home_mailbox = ~/Maildir/'

開始寄信
$ mailx student@it99.kvm
信件內容
打完後ctrl + d離開

看信
mailx -f Maildir/




Dovecot (pop3收信套件) 

 

安裝 Dovecot(俗稱:鴿舍)

$ sudo apt-get install dovecot-imapd dovecot-pop3d
 
 
設定 Dovecot
$ sudo vi /etc/dovecot/dovecot.conf
進入後先打 『 :set nu 』可以產生列號,這樣比較容易看




再打 『:/protocols』←找尋 protocols這一列


  按『 ESC 』移動指到你要改的那一列按『i』即可進入編輯模式 ,請把25列順序改成如上圖 吧★~★



再打 『:/mail_location』←找尋 mail_location這一列,在224列喔,請改成如圖的路徑



再按『1G』←回到第一列的意思
ps:因為『:/找尋字串』 ← 是找尋游標之下的字串 ; 『:?找尋字串』←是找游標之上的字串

再打『:/disable 』可找到disable_plaintext_auth在第53列,請改成『no』吧 ::>_<::



若設no代表使用不安全機制,一般在外使用建議選yes

要出來vi的模示,請打『:wq 』←表示儲存/離開的意思;要強制儲存/離開就加!號吧 『:wq!』容易吧 ~~★~★~~





重新啟動 Dovecot
sudo /etc/init.d/dovecot restart
 
測試 Dovecot 
#用telnet連到本機的pop3 
$ telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Dovecot ready.
成功,Dovecot已在運作






沒有留言:

張貼留言