2011年9月14日 星期三

[KVM]使用『Virt-manager』管理KVM - 建立 VM

    由於我是在 Ubuntu 11.04 Desktop 上安裝『Virt-manager』,Ubuntu 11.04所收錄的『Virt-manager』是 0.8.6,其他版本的『Virt-manager』在版面上或有不同但是設定的次序是大同小異。

    我主要用過 0.8.2 及 0.8.6 兩個版本 的『Virt-manager』,在這邊主要以 0.8.6 來進行示範。

1. 啟動『Virt-manager』

    我的 Ubuntu 11.04 Desktop 所使用的桌面環境是 LXDE,在畫面左下方的[選單]=>[系統工具]中看到虛擬機器管理員。


    若是Gnome則是畫面左上角的[應用程式]=>[系統工具] 中可以看到。


    下面是開啟『Virt-manager』的畫面,


2.新增連線

    接著要連線到 KVM 所在的主機

    a.單擊 [檔案] => [Add Connection]


    會出現一個新增連線的設定視窗,


    b. 將『Connect to remote host』勾選起來


    c. 設定連線資訊

        接著就填入連線所需的資訊,然後單擊 [連接( n )]。




    如果是『Virt-manager』0.8.2 就只能用 root 連線到遠端主機。

    d.啟動連線

      雙擊剛剛建立的連線,連線成功會出現密碼輸入視窗。


     
    登入完畢後會列出現有的VM清單。


3.設定 Storage Pool

    這邊規劃將之後建立的VM  image 檔 及 OS 的iso檔分開存放, VM  image 檔放在『/media/SDA3/VmImage』, OS iso檔放在『/media/SDC7/001.LinuxISO』。

    a. 以KVM管理帳號的身份透過 SSH 連到KVM主機

$ ssh max@192.168.1.100                     



b. 新增存放目錄

$ mkdir -p /media/SDA3/VmImage
$ mkdir -p /media/SDA3/Iso                    




c.使用『virsh』定義VM  image 檔 及 OS 的iso檔的存放目錄

        語法如下,

virsh pool-define-as <Name> <Format> - - - - "Path"          

   

         (1). 定義VM  image 檔存放目錄


$virsh pool-define-as VM-Image dir - - - - "/media/SDA3/VmImage"     





        (2). 定義iso 檔存放目錄


$virsh pool-define-as Iso dir - - - - "/media/SDC7/001.LinuxISO/"         




        (3). 列出 Stroage Pool


$ virsh pool-list --all
名稱                  狀態     自動啟動
-----------------------------------------
default              啟用     yes       
image                啟用     yes       
TcViewLite           啟用     yes       
Iso                  非啟用中 no        
VM-Image             非啟用中 no   





   






         (4).啟動新增的Storage Pool 並設為自動啟動


$ virsh pool-start VM-Image                                 
Pool VM-Image started

$ virsh pool-start Iso
Pool Iso started

$ virsh pool-autostart VM-Image
Pool VM-Image marked as autostarted

$ virsh pool-autostart Iso
Pool Iso marked as autostarted
 
$ virsh pool-list --all
名稱               狀態     自動啟動
-----------------------------------------
default              啟用     yes       
image                啟用     yes       
Iso                  啟用     yes       
TcViewLite           啟用     yes       
VM-Image             啟用     yes       

























4.建立VM

    接著我們就使用『Virt-manager』來建立一台VM。

    a.對著剛剛建立的連線單擊右鍵,點擊 [新增]



     輸入 VM 的名稱及選擇安裝方式。


    b.設定OS Type 及 Version


    c. 選取 OS iso 檔





    d.設定 RAM及CPU數量

        設定值最大均不能超過Host所擁有的實體記憶體大小及CPU數量,若是多核心CPU 則不能超過總核心數。


    e. 產生虛擬硬碟

        因為要將VM存在『/media/SDC7/001.LinuxISO/』所以這邊另外選擇存放位置


    f. 點選要存放的 Storage Pool 然後單擊[New Volume]


    g. 新增儲存卷冊

        預設的儲存卷冊名稱會與 VM 同名,副檔名會是『img』,因為這邊所選擇的儲存卷冊格式為『qcow 2』所以在副檔名前再加上『.qemu』以為標示。

        記得要設定儲存卷冊容量的最大值,這邊是設定為約6Gb的大小。


    點選剛剛新增的儲存卷冊


    f. 設定網路卡

        我們可以選擇使用『NAT』虛擬網路,若 Host有建立橋接網路卡也可以選擇『Specify shared device name』。

        由於網路卡相關設定可以在VM建立之後再變更設定,所以這邊先選用『NAT』虛擬網路。

     另外,Virt-type 選擇『kvm』,Architecture選擇『x86_64』。


    單擊『完成』就產生一台VM,之後會直接進入OS安裝畫面。

2011年9月12日 星期一

[Linux] Chrome 與 scim 合不來的解法~~~

IBus 的中文輸入法實在需要高深的技巧才能好好的用,所以只好換成 scim~~~

換完之後.......Chrome(Google Chrome、Google Brower、Google 瀏覽器) 與 scim 居然合不來mmmmmm囧~

.Chrome沒辦法使用scim的中文輸入.....怎麼辦呢?

要改一下『/etc/X11/xinit/xinput.d/scim』。

$ sudo vim /etc/X11/xinit/xinput.d/scim                          




將『GTK_IM_MODULE=xim』及『QT_IM_MODULE=xim』改成『GTK_IM_MODULE=scim』及『GTK_IM_MODULE=scim』。

#GTK_IM_MODULE=xim
#QT_IM_MODULE=xim

GTK_IM_MODULE=scim
QT_IM_MODULE=scim                                              







存檔後再重新載入scim的設定檔即可。

2011年9月11日 星期日

[LXDE] LXDE 調校及使用紀錄 on Ubuntu 11.04 之桌面工作階段設定

改用LXDE後發現『電源管理』、『藍芽管理』、『音量控制』還有『網路管理』等工具的圖示並沒有出現在桌面右下方的啟動匣中,顯然並沒有在登入時自動啟動。

在網路上找到的解法多半是以修改啟動設定檔的方式來呼叫對應工具。

不過,使用LXDE所提供的『桌面工作階段設定』會更方便。

『桌面工作階段設定』在『偏好設定』中可以找到。


將要在登入時自動啟動的工具勾選起來。

重新登入後就會在桌面右下方的啟動匣中看到『電源管理』、『藍芽管理』、『音量控制』還有『網路管理』等工具的圖示了。


[LXDE] LXDE 調校及使用紀錄 on Ubuntu 11.04 之電源管理工具

    LXDE 好像沒有提供電源管理的工具,所以借用Gnom的『gnome-power-manager』。

1. 如果使用的是Lubuntu可以另外把他裝起來,
 $ sudo apt-get install gnome-power-manager                           



2. 如果是裝Ubuntu 11.04 之後再加裝 LXDE 的話就可以直接使用,
$ gnome-power-manager                                                           

         
    在右下方的啟動匣中就會看到電源管理工具的圖示。

3. 要讓『gnome-power-manager』在開機時自動啟動要編輯  『/etc/xdg/lxsession/LXDE/autostart』,
 $ sudo vim /etc/xdg/lxsession/LXDE/autostart                                        


 
    將『@gnome-power-manager』 加上去。
@xscreensaver -no-splash
@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE @/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 @gnome-power-manager  #<-----加上這一行




Update:
其實直接使用『桌面工作階段』會更方便。
http://www.mpsstudio.org/2011/09/lxde-lxde-on-ubuntu-1104.html


※ Reference : http://silvervine-ninelives.blog.so-net.ne.jp/2010-08-27-1   

2011年9月8日 星期四

[Ubuntu]不用輸入密碼使用 sudo 的方法

當我們要在Ubuntu使用特權命令時,需要在命令前面加上一個sudo

$ sudo apt-get update
[sudo] password for max:                                               




輸入密碼後就可以執行。

但如果要在Script中使用需要root權限的命令,並在無人看守的時候執行這隻Scrip
要叫誰來輸入密碼呢?

有一個簡易的方法可以免手動輸入密碼。

只要使用echo透過pipe就可以將密碼送給sudo了,不過sudo要記得加上『-S』這個option讓sudo從stdin讀取密碼。

$ echo '<Your_Password>' | sudo -S apt-get update                            

2011年1月11日 星期二

Secure Apache Web Server

1. Secure Apache Web Server

    要保護 Apache Web Server ,除了可以使用一般的存取控制及適當設定Apache Web Server 的設定檔『/etc/httpd/conf/httpd.conf』中的安全相關設定外,還可以使用FirewallSELinux 來增強 Apache Web Server 的安全性。


2. Firewall


    先確認一下Firewall是否已開放 WWW(HTTPport 80)及 Secure WWW(HTTPSport 443)。

    在GUI 執行[System]-->[Security Level and Firewall] 或在TUI執行system-config-securitylevel』命令啟動『Security Level Configuration』。





    確認或開放WWW(HTTPport 80)Secure WWW(HTTPSport 443) 的防火牆規 則設定。    
    
    也可以在TUI執行『iptables -L』命令檢視防火牆規則。
[root@lab2 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere


Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere


Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
[root@lab2 ~]#

    確認下列兩行防火牆規則已存在於防火牆規則清單中。
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
3. 確認SELinux 的現行模式

  接著確認 SELinux的現行運作模式是否為『Enforcing』。


 在GUI 執行[System]-->[Security Level and Firewall] 或在TUI執行
system-config-securitylevel』命令啟動『Security Level Configuration』,檢視 SELinux 的現行模式。

 確認SELinux 的模式為『Enforcing』。


    或在 TUI 執行『getenforce』命令檢視SELinux 模式設定值。
[root@lab2 ~]# getenforce
Enforcing
4.Apache Web Server 主要目錄及檔案的security contexts    



    使用『ls -dZ』檢視『/etc/httpd/』、『/etc/httpd/conf/』、
/etc/httpd/conf.d/』、『 /var/www/html/』等目錄的security contexts
[root@lab2 ~]# ls -dZ /etc/httpd/ /etc/httpd/conf/ /etc/httpd/conf.d/ /var/www/html/
drwxr-xr-x root root system_u:object_r:httpd_config_t /etc/httpd/
drwxr-xr-x root root system_u:object_r:httpd_config_t /etc/httpd/conf/
drwxr-xr-x root root system_u:object_r:httpd_config_t /etc/httpd/conf.d/
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t /var/www/html/
    整理如下表,
DirectoryName
Identify
Role
Typr
/etc/httpd
system_u
object_r
httpd_config_t
/etc/httpd/conf
system_u
object_r
httpd_config_t
/etc/httpd/conf.d/
system_u
object_r
httpd_config_t
/var/www/html
system_u
object_r
httpd_sys_content_t

    先在『/var/www/html』目錄中建立『index.html』。
[root@lab2 ~]# touch /var/www/html/index.html

    使用『ls -lZ』檢視『/etc/httpd/conf/httpd.conf』、 /var/www/html/index.html』等檔案的security contexts
[root@lab2 ~]# ls -Z /etc/httpd/conf/httpd.conf /var/www/html/index.html
-rw-r--r-- root root system_u:object_r:httpd_config_t /etc/httpd/conf/httpd.conf
-rw-r--r-- root root user_u:object_r:httpd_sys_content_t /var/www/html/index.html
    整理如下表,
FileName
Identify
Role
Typr
/etc/httpd/conf/httpd.conf
system_u
object_r
httpd_config_t
/var/www/html/index.html
system_u
object_r
httpd_sys_content_t
5. security contexts 設定錯誤時如何修正


    security contexts 設定錯誤導致設定檔或網頁無法被存取時可以使用 chcon』及『restorecon』進行修正。


7. 修正個人網頁存放目錄及個人網頁檔的security contexts 設定錯誤


    a.修改 「/etc/httpd/conf/httpd.conf」的下列Directive,並重新啟動 httpd
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
#UserDir disable
加上井號
#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
#
#UserDir public_html
UserDir html
去除井號,設定使用者個人網頁目錄名稱
</IfModule>


    b. 建立個人網頁放置目錄
[max@lab2 ~]$ mkdir html

    c. 建立個人網頁
[max@lab2 ~]$ touch html/index.html
[max@lab2 ~]$ echo "Privat Test Page" >> html/index.html

    d. 檢視個人網頁

    出現無檢視權限的錯誤


    e. 檢視個人網頁放置目錄權限設定

[max@lab2 ~]$ ls -ld html/
drwxrwxr-- 2 max max 4096 Jan 11 03:48 html/
[max@lab2 ~]$ ls -l html/index.html
-rw-rw-r-- 1 max max 17 Jan 11 03:49 html/index.html

    個人網頁放置目錄的other 無『x』權限,所以無法存取個人網頁。

    f. 在家目錄及個人網頁放置目錄增加other的『x』權限
[[max@lab2 ~]$ ls -ld ~/ ~/html
drwx------ 19 max max 4096 Jan 11 03:47 /home/max/
drwxrwxr-- 2 max max 4096 Jan 11 03:48 /home/max/html
[max@lab2 ~]$ chmod o+x ~/ ~/html
[max@lab2 ~]$ ls -ld ~/ ~/html
drwx-----x 19 max max 4096 Jan 11 03:47 /home/max/
drwxrwxr-x 2 max max 4096 Jan 11 03:48 /home/max/html
    但仍是出現無存取權限的錯誤



    g. 檢視個人網頁放置目錄及個人網頁的security contexts 設定
[max@lab2 ~]$ ls -dZ html/
drwxrwxr-x max max user_u:object_r:user_home_t html/
[max@lab2 ~]$ ls -Z html/index.html
-rw-rw-r-- max max user_u:object_r:user_home_t html/index.html

h. 修正個人網頁放置目錄及個人網頁的security contexts 設定
[max@lab2 ~]$ chcon -R --referenc=/var/www/html/ ~/html/
[max@lab2 ~]$ ls -dZ html/
drwxrwxr-x max max system_u:object_r:httpd_sys_content_t html/
[max@lab2 ~]$ ls -Z html/index.html
-rw-rw-r-- max max system_u:object_r:httpd_sys_content_t html/index.html

i. 這樣就看得到個人網頁了


Powered By Blogger