2012年3月29日 星期四

[Debian] 32bit Ram 2G 限制問題

OS : Debian 6.04-i386-32bit
RAM : 32G

問題 : Debian6.04-i386(32-bit)版不支援 RAM 4G以上,只呈現2G

解決方法:

#ps -ef
# apt-get install linux-image-2.6-686-bigmem
#reboot

參考網頁 :  http://serverfault.com/questions/25366/linux-only-detects-2gb-of-ram-with-4-installed-i386-debian-lenny

[MYSQL] -權限相關設定

# 備份  
mysqldump  -u root -p  mysql > /tmp/fifimysql.sql
或 tar low data 方式 
a. 先停止 mysql /etc/init.d/mysql  stop
b. 下達指令 tar xxx.tar.gz 資料庫名稱 
或 gzip
mysqldump -u root -p fifitest | gzip - > fifitest.gz

# 還原
mysql  -u root -p  fifitest  <  fifimysql.sql
或 zip
zcat  fifitest.gz  | mysql -u root -p fifitest

# cli 模式 秀出所有資料庫 跟 指定資料庫
mysqlshow -u root -p
mysqlshow  -u root -p  fifitest db

# 進入 Mysql cli 模式 ( command line ) 
mysql -u root -p

# 建立資料庫
mysql> create database  `fifitest`;

# 秀資料庫
mysql> show databases ;

# 離開資料庫
mysql> quit ;

# mysqlshow  -u root -p  fifitest db

透過 phpmyadmin 操作後, 會有 mysql cli 模式指令

# 建立用戶test123 , 宣告密碼 111
CREATE USER 'test123'@'localhost' IDENTIFIED BY  '111';

# 宣告test123 這各身分在 localhost 可以做的權限
GRANT USAGE ON * . * TO  'test123'@'localhost' IDENTIFIED BY  '111' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

# 宣告 test123 再,  localhost 這一台裡面對於 fifitest 資料庫 , 有所有權限
GRANT ALL PRIVILEGES ON  `fifitest` . * TO  'test123'@'localhost';

# 新增宣告 test123 在 localhost 這台機器上 , 對於 123 這各資料庫 , 有四種權限
GRANT SELECT , INSERT , UPDATE , DELETE ON  `123` . * TO  'test123'@'localhost';

# 移除所有權限 ,    test123 在 localhost 這台機器上 , 對於 123 這各資料庫 
REVOKE ALL PRIVILEGES ON  `123` . * FROM  'test123'@'localhost';

# 再宣告
GRANT SELECT , INSERT , UPDATE ON  `123` . * TO  'test123'@'localhost';

# 檢查 table
use 哪各DB
CHECK TABLE  `pma_bookmark` ,  `pma_column_info` ,  `pma_designer_coords` ,  `pma_history` ,  `pma_pdf_pages` ,  `pma_relation` , `pma_table_coords` ,  `pma_table_info` ,  `pma_tracking`

# 修復 table
REPAIR TABLE  `pma_bookmark` ,  `pma_column_info` ,  `pma_designer_coords` ,  `pma_history` ,  `pma_pdf_pages` ,  `pma_relation` , `pma_table_coords` ,  `pma_table_info` ,  `pma_tracking`

2012年3月15日 星期四

[ How-To] ESXI5 GhettoVCB 備份還原(linux 版)

  測試環境 
  新 HOST OS : ESXI5
  使用套件 : pietty0327、ghettoVCB、ghettoVCB-restore.sh
  使用需求: 需使用ghettoVCB.sh備份檔(還原格式同原本備份格式)           
                  能SSH連線訪問的到該台主機並有足夠的空間,再進行還原。



1、使用 pietty SSH 進入 ESXI5 主機後,上傳ghettoVCB.tar.gz 及 ghettoVCB作出的備份檔


2、查看ghettoVCB-restore.sh使用到的參數

  OPTIONS:

   -c     VM backup list (要還原備份的列表)

   -l     File ot output logging  (指定LOG所儲存的路徑)

   -d     Dryrun/Debug Info [1|2] (可用來測試或是Debug還原看是否有誤)

       
     還原 清單(vms_to_restore)上的虛擬機
     #./ghettoVCB-restore.sh -c vms_to_restore

  
     還原 清單(vms_to_restore)上的虛擬機,並指定 LOG 暫存路徑
     #./ghettoVCB-restore.sh -c vms_to_restore -l /tmp/ghettoVCB-restore.log

  
   設定好vms_to_restore後,可以使用Dryrun/Debug來測試看看腳本和vms_to_restore是否有問題。

     #./ghettoVCB-restore.sh -c vms_to_restore -d 1

     #./ghettoVCB-restore.sh -c vms_to_restore -d 2


3、建立還原使用的list

 
   # vi  vms_to_restore

   "/vmfs/volumes/datastore1/test123/Guest01-2012-01-11_23-48-35;/vmfs/volumes/datastore1;3" 

   # " VM備份檔所在地的完整路徑 ; 恢復後的VM要存放的完整路徑 ;  設定恢復硬碟的格式"                                
  
  
 注意 : 此list請使用在ESX或ESX(i)主機上。請勿用在non-Linux/UNIX系統上,避免特殊符號影響導致腳本錯誤。

 格式代號    格式名稱

      1 = zeroedthick

      2 = 2gbsparse

      3 = thin

      4 = eagerzeroedthick

4、還原完成後請開啟VMware vSphere Client,看VM已經自己掛上了,接下來請開啟VM 測試是能正常開機運作


5、在還原後第一次開啟時會出現詢問說此VM是怎麼來的,請選[I copied it],如果VM開啟正常,請將VM關起來後和一般正常的VM相比對,若沒有差異的 即是還原備份完成 。


參考網站 :   FAQ-BOOK  VMware esxi 備份還原ghettoVCB-restore.sh
                   FAQ-BOOK   VMware ESX(i)虛擬磁碟格式介紹
    




[ Note ] ESX(i) 指令集

 *查看版本
    #vmware -v
    
    列出 esx 裡知道的服務
    #esxconfig-firewall -s
    
    查看具體服務的情況
    #esxcfg-firewall -q sshclinet
     -sh: esxcfg-firewall: not found  
   
   重新啟動 vmware 服務
    #service mgmt-vmware restart
    
   *修改 root 的密碼
    #passwd root
    
   *列出你當前的虛擬交換機
    #esxcfg-vswitch –l
    
    查看控制台的設置
    #esxcfg-vswif -1
    
   *列出系統的網卡
    #esxcfg-nics –l

實作案例 :
添加一個虛擬交換機,名字叫(internal)連接到兩塊物理網卡(重新啟動服務,vi就能看見了)
#esxcfg-vswitch -a vSwitch1
#esxcfg-vswitch -A internal vSwitch1

#esxcfg-vswitch -L vmnic1 vSwitch1
#esxcfg-vswitch -L vmnic2 vSwitch1

刪除交換機,(注意,別把控制台的交換機也刪了
#esxcfg-vswitch -D vSwitch1

刪除交換機上的網卡
#esxcfg-vswitch -u vmnic1 vswitch2

刪除 portgroup
#esxcfg-vswitch -D internel vswitch1


創建 vmkernel switch ,如果你希望使用 vmotion,iscsi 的這些功能,你必須創建(通常是不需要添加網關的)
#esxcfg-vswitch -l
#esxcfg-vswitch -a vswitch2
#esxcfg-vswitch -A "vm kernel" vswitch2
#esxcfg-vswitch -L vmnic3 vswitch2
#esxcfg-vmknic -a "vm kernel" -i 172.16.1.141 -n 255.255.252.0
#esxcfg-route 172.16.0.254


打開防火牆 ssh 端口
#esxcfg-firewall -e sshclient
#esxcfg-firewall -d sshclient

創建控制台
#esxcfg-vswitch -a vSwitch0
#esxcfg-vswitch -A "service console" vSwitch0
#esxcfg-vswitch -L vmnic0 vSwitch0
#esxcfg-vswif -a vswif0 -p "service console" -i 172.16.1.140 -n 255.255.252.0

添加 nas 設備(a 添加標籤,-o,是 nas 伺服器的名字或 ip,-s 是 nas 輸入的共用名稱字)
#esxcfg-nas -a isos -o nas.vmwar.cn -s isos

列出 nas 連接
#esxcfg-nas –l

強迫 esx 去連接 nas 服務器(用 esxcfg-nas -l 來看看結果)
#esxcfg-nas -r
#esxcfg-nas –l

連接 iscsi 設備(e:enable q:查詢 d:disable s:強迫搜索)
#esxcfg-swiscsi –e

設置 targetip
#vmkiscsi-tool -D -a 172.16.1.133 vmhba40

列出和 target 的連接
#vmkiscsi-tool -l -T vmhba40

列出當前的磁盤
#ls -l /vmfs/devices/disks



Esxcfg command help

Networking: Esxcfg-firewall Esxcfg-nics Esxcfg-vswitch Esxcfg-vswif Esxcfg-route Esxcfg-vmknic

Esxcfg-firewall
Description: Configures the service console firewall ports
Syntax: esxcfg-firewall <options>

Options:
-q                                      Lists current settings
-q <service>                     Lists settings for the specified service
-q incoming|outgoing       Lists settings for non-required incoming/outgoing ports
-s                                      Lists known services
-l                                      Loads current settings
-r                                     Resets all options to defaults
-e <service>                    Allows specified service through the firewall (enables)
-d <service>                    Blocks specified service (disables)
-o <port, tcp|udp,in|out,name>     Opens a port
-c <port, tcp|udp,in|out>       Closes a port previously opened by –o
-h                                           Displays command help
-allowincoming                  Allow all incoming ports
-allowoutgoing                   Allow all outgoing ports
-blockincoming                  Block all non-required incoming ports (default value)
-blockoutgoing                   Block all non-required outgoing ports (default value)



Default Services:

AAMClient                     Added by the vpxa RPM: Traffic between ESX Server hosts for VMware High Availability (HA) and EMC Autostart Manager – inbound and outbound TCP and UDP Ports 2050 – 5000 and 8042 – 8045

activeDirectorKerberos       Active Directory Kerberos - outbound TCPs Port 88 and 464
CIMHttpServer                   First-party optional service: CIM HTTP Server - inbound TCP Port 5988
CIMHttpsServer                 First-party optional service: CIM HTTPS Server - inbound TCP Port 5989

CIMSLP                             First-party optional service: CIM SLP - inbound and outbound TCP and UDP Ports 427
commvaultDynamic           Backup agent: Commvault dynamic – inbound and outbound TCP Ports 8600 – 8619
commvaultStatic                 Backup agent: Commvault static – inbound and outbound TCP Ports 8400 – 8403

ftpClient                       FTP client - outbound TCP Port 21
ftpServer                      FTP server - inbound TCP Port 21
kerberos                       Kerberos - outbound TCPs Port 88 and 749
LicenseClient               FlexLM license server client - outbound TCP Ports 27000 and 27010
nfsClient                      NFS client - outbound TCP and UDP Ports 111 and 2049 (0 – 65535)
nisClient                      NIS client - outbound TCP and UDP Ports 111 (0 – 65535)
ntpClient                      NTP client - outbound UDP Port 123
smbClient                    SMB client - outbound TCP Ports 137 – 139 and 445
snmpd                          SNMP services - inbound TCP Port 161 and outbound TCP Port 162
sshClient                      SSH client - outbound TCP Port 22
sshServer                     SSH server - inbound TCP Port 22
swISCSIClient             First-party optional service: Software iSCSI client - outbound TCP Port 3260
telnetClient                  NTP client - outbound TCP Port 23
TSM                            Backup agent: IBM Tivoli Storage Manager – inbound and outbound TCP Ports 1500
veritasBackupExec     Backup agent: Veritas BackupExec – inbound TCP Ports 10000 – 10200
veritasNetBackup       Backup agent: Veritas NetBackup – inbound TCP Ports 13720, 13732, 13734, and 13783
vncServer                    VNC server - Allow VNC sessions 0-64: inbound TCP Ports 5900 – 5964
vpxHeartbeats             vpx heartbeats - outbound UDP Port 902

Note: You can configure your own services in the file /etc/vmware/firewall/services.xml
 

防火牆指令範例
esxcfg-firewall examples:
 Enable ssh client connections from the Service Console:
 # esxcfg-firewall -e sshClient

 Disable the Samba client connections:
 # esxcfg-firewall -d smbClient

 Allow syslog outgoing traffic:
 # esxcfg-firewall -o 514,udp,out,syslog

Turn off the firewall:
 # esxcfg-firewall -allowIncoming
 # esxcfg-firewall -allowOutgoing

 Re-enable the firewall:
 # esxcfg-firewall -blockIncoming
 # esxcfg-firewall –blockOutgoing

 Esxcfg-nics
 Description: Prints a list of physical network adapters along with information on the driver, PCI device, and link state of each NIC. You can also use this command to control a physical network adapter’s speed and duplexing.
 Syntax: esxcfg-nics <options> [nic]
 

Options:
-s <speed>         Set the speed of this NIC to one of 10/100/1000/10000. Requires a NIC parameter.
-d <duplex>        Set the duplex of this NIC to one of 'full' or 'half'. Requires a NIC parameter.
-a                 Set speed and duplex automatically. Requires a NIC parameter.
-l                 Print the list of NICs and their settings.
-r                 Restore the NICs configured speed/duplex settings. (Internal use only)
-h                 Displays command help



查看實際本機系統的網卡
esxcfg-nics examples:
Set the speed and duplex of a NIC (vmnic2) to 100/Full:
 #esxcfg-nics -s 100 -d full vmnic2


Set the speed and duplex of a NIC (vmnic2) to auto-negotiate:
 #esxcfg-nics -a vmnic2




[ How-To ] ESXI5 GhettoVCB 線上不停機備份(linux版 )


 GhettoVCB 線上不停機備份

測試環境 :
HOST OS : ESXI5  IP:192.168.10.5    NFS自動掛載備份 :/vmfs/volumes/backup/nfsshare
Geust OS : Debian6.04  IP:192.168.10.3    servername : Guest01
Geust OS : Debian6.04  IP:192.168.10.2    servername : Guest02
NFS OS : Debian6.04    IP:192.168.10.1  (mount point :/home/backup)

使用套件下載 : pietty0327、ghettoVCB
使用方法 : crontab + Linux shell script + mount (自動掛載 nfs)



一、NFS 設定步驟

1-1.安裝 nfs-server 並編輯設定檔

# apt-get update
# apt-get install nfs-kernel-server
# mkdir /home/backup
# chmoe 777 backup
# vi  /etc/exports

/home/tools      192.168.10.*(rw,sync,no_subtree_check)   #放多台Server使用的
 /home/backup  192.168.10.*(rw,sync,no_subtree_check)

# /etc/init.d/nfs-kernel-server restart

nfs-server防火牆設定

# vi /etc/hosts.allow
portmap : 192.168.10.
mountd : 192.168.10.

1-2.檢查 nfs 服務是否有啟動

看 111 (portmap) 和 2049 (rpc.statd) port 是否有正常啟動, 沒有請重新啟動。
# showmount -e lcoalhost


二、EXSI5 HOST設定步驟


2-1.先開啟 ESXI5 ssh 連線功能
用vSphere Clint--> configuration --> Security Profile --> Services Properties  --> ssh Options --> Start and stop manually -->start --> OK

2-2.使用pietty 上傳 ghettoVCB.tar.gz 至 EXSI5 host 下不會因重開機而刪去的目錄內, 解tar 。(請自行下載 pietty0327.exe、ghettoVCB.tar.gz ; 因重開機而會刪去的有 tmp/、var/ 下的目錄 )


2-3.編寫設定檔
 2-3-1. # vi ghettoVCB.sh (此為備份在本機端)
 
  #設定備份所存放的路徑,在這邊設定備份到本地端,用NFS設定請 # 此行
  VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/backup

  #定義被份的硬碟格式(zeroedthick, eagerzeroedthick, thin, and 2gbsparse are available)
  DISK_BACKUP_FORMAT=thin
   
  #定義備份保留的數量
  VM_BACKUP_ROTATION_COUNT=3

  #設定POWER DOWN的時間。在等待關閉時VM會放棄或是忽略特定的VM備份   
  POWER_DOWN_TIMEOUT=5

  #設定等待VM快照的時間,在等待關閉時會放棄和忽略特定備份的VM
  SNAPSHOT_TIMEOUT=15

  #備份是否啟用壓縮(enable=1,disable=0)
  ENABLE_COMPRESSION=0
  #---- NFS的相關設定----
  #定義非持久性的NFS備份(yes=1,no=0)
  ENABLE_NON_PERSISTENT_NFS=0

#以下是給不想讓NFS與系統長期連接的設定,允許只在備份的過程中連接到NFS,需要才掛載
  當有備份需要使用到NFS時才會自動掛載上去,一旦備份完成後就會自動卸載,並不會持續的掛載。

   並使用到以下5個變數。

   #是否要卸載NFS(yes=1,no=0)
  UNMOUNT_NFS=0

   #NFS Server 的地址(ip或主機名)
   NFS_SERVER=192.168.10.1

   # Defining the NFS export path:/home/backup
   NFS_MOUNT=/home/backup

   #NFS 資料存放地方的名稱 (掛載在 /vmfs/volumes/下 )
   NFS_LOCAL_NAME=TEST

   #虛擬機上NFS備份的目錄
  NFS_VM_BACKUP_DIR=mybackups

 #------MAIL 發送LOG的設定-------

  #是否要透過電子郵件來發送備份LOG(yes=1,no=0)
  EMAIL_LOG=1

  #是否發送debug的LOG,這是做為測試使用。
  EMAIL_DEBUG=1

  #mail server的ip或網址
  EMAIL_SERVER= emailserver.com

  #設定mail 所使用的port
  EMAIL_SERVER_PORT=25

  #設定每封mail之間發送的延遲時間。
  EMAIL_DELAY_INTERVAL=1

  #收件人的mail
  EMAIL_TO=xxx@gmail.com

  #寄件人的mail
  EMAIL_FROM=root@ghettoVCB

 #---修改EMAIL LOG存放位置--預設定情況下log都是存放在/tmp內,避免重開機後log會被清除。

  USE_VM_CONF=0                                                                

  USE_GLOBAL_CONF=0                                        

  BACKUP_ALL_VMS=0                       

  EXCLUDE_SOME_VMS=0                                                          

  EMAIL_LOG_HEADER=/tmp/ghettoVCB-email$$.header                                    

  EMAIL_LOG_OUTPUT=/tmp/ghettoVCB-email-$$.log                                   

  EMAIL_LOG_CONTENT=/tmp/ghettoVCB-email-$$.content
 
  #(將tmp修改成所要存放的路徑後儲存執行即可,建議存到/vmfs/volumes/datastore1/log 內)

  
2-3-2. 可編輯不同的備份腳本

 # vi ghettoVCB.conf  (備份在NFS 端 )

VM_BACKUP_VOLUME=/vmfs/volumes/datastore1/test
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=2
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=3
POWER_DOWN_TIMEOUT=5
ENABLE_COMPRESSION=0
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0
ENABLE_NON_PERSISTENT_NFS=1
UNMOUNT_NFS=1
NFS_SERVER=192.168.10.1
NFS_MOUNT=/home/backup
NFS_LOCAL_NAME=backup
NFS_VM_BACKUP_DIR=nfsshare
SNAPSHOT_TIMEOUT=5
EMAIL_LOG=1
EMAIL_DEBUG=1
EMAIL_SERVER=smtp.gmail.com
EMAIL_SERVER_PORT=25
EMAIL_DELAY_INTERVAL=1
EMAIL_TO=xxxx@gmail.com
EMAIL_FROM=root@ghettoVCB




 2-4.建立List vms_to_backup  & vm_exclusion_list
  # vi vms_to_backup (備份指定名單)

     Guest01

 #加入要指定要自動備份的虛擬機名稱,需和/vmfs/volumes/datastore1 下 虛擬機名稱相同)
  # vi vm_exclusion_list (排除list中指定)

    Guest02

  #加入要指定排除的虛擬機名稱

2-5.ghettoVCB.sh 手動使用說明
     
ghettoVCB.sh參數說明 :  


   -a     Backup all VMs on host 
          (備份主機上所有的虛擬機)

   -f     List of VMs to backup  
          (針對List名單內的虛擬機備份)

   -c     VM configuration directory for VM backups
          (VM 配置目錄for VM備份)

   -g     Path to global ghettoVCB configuration file

   -l     File to output logging  
          (將LOG記錄寫到指定檔案內)

   -d     Debug level [info|debug|dryrun] (default: info)
          (Debug測試,不會產生備份)

            
   範例操作

    只備份list內的虛擬機
    #./ghettoVCB.sh -f vms_to_backup

    全部備份
    #./ghettoVCB.sh -a 

    除了排除清單(vm_exclusion_list)上的虛擬機外,剩下的都備份
    #./ghettoVCB.sh -a -e vm_exclusion_list

     Backup VMs using global ghettoVCB configuration file
   備份虛擬機時使用ghettoVCB.conf此設定檔來備份vms_to_backup內指定的虛擬機
    #./ghettoVCB.sh -f vms_to_backup -g /global/ghettoVCB.conf


   Backup VMs based on specific configuration located in directory
   根據vm_backup_configs中特定配置來備份vms_to_backup內指定的虛擬機
  #./ghettoVCB.sh -f vms_to_backup -c vm_backup_configs


    輸出的記錄到/tmp/ghettoVCB.log(可自行設定LOG所儲存的路徑和檔案)
    #./ghettoVCB.sh -f vms_to_backup -l /vmfs/volume/local-storage/ghettoVCB.log

    Dryrun測試,不會產生備份
    #./ghettoVCB.sh -f vms_to_backup -d dryrun

    Debug不產生備份,執行後提供詳細訊息包括備份和LOG存放的路徑及備份所需容量訊息,用來排除故障是相當好用的。 
    #./ghettoVCB.sh -f vms_to_backup -d debug




三、防火牆及排程設定


 3-1.加入 crontab 的排程,自動定期備份 (為了測試是否正常可以先設定每10分測試一次)
   # vi   var/spool/cron/crontab/root

    30  20    *   *   1-5   /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/ghettoVCB.sh -f  /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/vms_to_backup
    *   24    *   *   5     /vmfs/volumes/datastore1/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a

 3-2.開啟 EMAIL 請加入 25 port 的防火牆設定  

   3-2-1.先確認ESXI是否有開啟防火牆25port


  方法一  用介面  : [Configuration]→[Security Profile]
  方法二  ESXI5 SSH  # esxcli network firewall ruleset list

 3-2-2.加入25port  
   # cd /etc/vmware/firewall/      
   # vi smtp.xml (在最後加入以下內容)

   <!--  E-MAIL SMTP  -->
  <ConfigRoot>
  <service id='1000'>
    <id>SMTP</id>
    <rule>
      <direction>outbound</direction>
      <protocol>tcp</protocol>
      <porttype>dst</porttype>
      <port>25</port>
    </rule>
    <enabled>true</enabled>
    <required>false</required>
  </service>
 </ConfigRoot>  

 3-2-3.重啟防火牆,重啟後會看到多出SMTP 25port的設定

 # esxcli network firewall refresh
 # esxcli network firewall ruleset list

 SMTP                   true     (顯現出smtp有開啟)


四、重開機防火牆自動讀入設定

4-1.編寫開機執行腳本


# vi firewall.sh

#!/bin/sh
# Firewall rules

cp /vmfs/volumes/tools/file/service.xml /etc/vmware/firewall/

esxcli network firewall refresh  #重啟防火牆設定

# chmod 755 firewall.sh


4-2.寫入到rc.local讓重開機ESXI主機自動跑firewall.sh

# vi /etc/rc.local
#在最下面加入此行
/vmfs/volumes/tools/script/firewall.sh

五、設定排程設定 (單台、多台主機環境)
在設定排程的部份,也和設定MAIL的防火牆規則一樣,都會因重開而還原。

單台主機設定
適合單一主機或是管理人員較少的使用。
缺點 : 日後要設的排程多的時後,或是加入到rc.local內的東西變多時,在管理上會容易亂掉,管理較不方便。

多台主機

建議最好新增一個NFS並將設定資料都統一放到NFS內,之後在有需要的ESXI主機上在掛載NFS就可使用。
優點 : 適合主機數較多且方便統一管理。


5-1.設定排程(root)

5-1-1.單台排程設定

直接寫在rc.local
# vi /etc/rc.local
#在最下面加入crontab

/bin/kill $(cat /var/run/crond.pid)       #刪去目前跑的 crond.pid

/bin/echo " */5    *    *   *   *   /vmfs/volumes/datastore1/backup/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a”>> /var/spool/cron/crontabs/root
#每5秒 備份一次的備份shell寫入 /var/spool/cron/crontab/root 內

/bin/busybox crond                        #重啟crond


5-2-1.多台排程設定

以下範例檔案存放在NFS上 tools/script 內,可供多機備份用。

 # mkdir -p /vmfs/volumes/tools/script
 # mkdir  /vmfs/volumes/tools/file

將要執行的 shell 暫存在 script (NFS server)


編寫 Crontab root
主要是為了日後如果有更多的排程要設定的話只需要改此root檔後,執行crontabs.sh
此腳本就會自動覆蓋舊的root檔了。在日後的管理會較為方便。

 # cp /var/spool/cron/crontabs/root /vmfs/volumes/tools/file/

 # cd /vmfs/volumes/tools/file/

 # chmod 744 root

 # vi root
#min hour day mon dow command

1    1    *   *   *   /sbin/tmpwatch.py

1    *    *   *   *   /sbin/auto-backup.sh

0    *    *   *   *   /usr/lib/vmware/vmksummary/log-heartbeat.py

*/5  *    *   *   *   /vmfs/volumes/datastore1/backup/lamw-ghettoVCB-518cef7/ghettoVCB.sh -a

#設定讓5分鐘跑一次看是否正常,測試時請用最小的vm 來測試,節省時間。


設定crontabs.sh

# cd /vmfs/volumes/tools/script

# vi crontabs.sh

#!/bin/sh

/bin/kill $(cat /var/run/crond.pid)                    

cp /vmfs/volumes/tools/file/root /var/spool/cron/crontabs

/bin/busybox crond



# chmod 755 crontabs.sh


設定rc.local開機自動跑crontabs.sh

# vi /etc/rc.local

#在最下面加入此行

/vmfs/volumes/tools/script/crontabs.sh

接下來就可以觀察在本機端 及 NFS Server 內是否有備份過去的目錄了。


備註: 安裝時出現的 error訊息

1、執行 ./ghettoVCB.sh  -f  vms_to_backup -g ghettoVCB.conf 第二各備份設定檔時出現
   error 訊息 : "mkdir: cannot create directory '/tmp/ghettoVCB.lock': File exists"
原因 : 因同第一支設定檔都使用 ghettoVCB.sh 的設定會產生 '/tmp/ghettoVCB.lock' 在跑。
解決方法 :無法同時執行,需分開備份時間或是使用另支 ghettoVCB1.sh 修改 /tmp/ghettoVCB1.lock 


2、ESXI5 本機上 mount出現文件錯亂問題

2012-03-21 02:26:53 -- info: ============ ghettoVCB LOG START ==============
(vim.fault.AlreadyExists) {
   dynamicType = <unset>,
   faultCause = (vmodl.MethodFault) null,
   name = "/vmfs/volumes/62b67156-7cecaa9a",
   msg = "The specified key, name, or identifier already exists.",
}


Datastore not found.

Datastore not found.
Datastore not found.

解決方法 :
在ESXi主机上重啟管理網路服務
# services.sh restart

3、ESXi主機配置NFS存儲為Datastore时,出錯,提示如下信息:
 Error during the configuration of the host: NFS Error: Unable to Mount filesystem: Unable to connect to NFS server

解決方法: 1.確認 NFSServer的exports 設定了no_root_squash或chmod 777
          2.在 EXSI主機手動MOUNT 測試,nfs設定是否成功 
            #  esxcfg-nas -a -o 192.168.15.54 -s /home/backup  NFS_Test
            #  esxcfg-nas -l
            #  df -h
            #  esxcfg-nas -d NFS_Test   #umount

4、ghettoVCB備份 錯誤訊息 Snapshot found for「host」, backup will not take place
原因 :  會出現此錯誤訊息,主要是因為當正在使用的虛擬機VM要備份的時後,會先做出一個snapshot檔。然後在備份
的中途若有不當的中斷或停止時。此snapshot檔就會無法自動刪除。進而造成下次要備份時出現此錯誤訊息因此時需要手動自行刪除。
解決方法: 手動刪除snapshot --> 請先登入VMware vSphere Client --> 然後點選卡住的開台虛擬機右鍵。
           [linux]→[Snapshot]→[Snapshot Manager]→[ghettoVCB-snapshot-2012-01-05] →[Delete]

5、查看 ESXi 的 VMkernel Log (/var/log/messages)
6、出現 " ERROR: Please enable firewall rule for email traffic on port 25 " 請加入25port的防火牆設定


參考網站 : 00086網誌  ESXi 5 下 ghettoVCB.sh 安裝及操作過程
                 FAQ-BOOK  VMware esxi 備份ghettoVCB.sh基本設定說明
                 FAQ-BOOK  VMware esxi 備份ghettoVCB.sh進階設定說明
                 VM官網 VMware Communities: ghettoVCB.sh - Free alternative for backing up VM's for ESX(i) 3.5, 4.x+ & 5.x

2012年3月5日 星期一

[ How-To] Debain NTP-server


OS : Debian 6.04

安裝套件
# apt-get install ntp

設定conf 檔
# cp /etc/ntp.conf.dpkg-dist  /etc/ntp.conf

設定說明

1. 先處理權限方面的問題,包括放行上層伺服器以及開放區網用戶來源:

# vim /etc/ntp.conf

# restrict [你的IP] mask [netmask_IP] [parameter]


parameter 參數:

    ignore  : 拒絕所有類型的 NTP 連線;
    nomodify: 用戶端不能使用 ntpc 與 ntpq 這兩支程式來修改伺服器的時間參數,
        但用戶端仍可透過這部主機來進行網路校時的;
    noquery:用戶端不能夠使用 ntpq, ntpc 等指令來查詢時間伺服器,等於不提供 NTP 的網路校時囉;
    notrap: 不提供 trap 這個遠端事件登錄 (remote event logging) 的功能。
    notrust: 拒絕沒有認證的用戶端。
    無      : 表示『該 IP 或網段不受任何限制』的意思。

restrict default kod nomodify notrap nopeer noquery     <==拒絕 IPv4 的用戶
restrict -6 default kod nomodify notrap nopeer noquery  <==拒絕 IPv6 的用戶
restrict 220.130.158.71   <==放行 tock.stdtime.gov.tw 進入本 NTP 伺服器
restrict 59.124.196.83    <==放行 tick.stdtime.gov.tw 進入本 NTP 伺服器
restrict 59.124.196.84    <==放行 time.stdtime.gov.tw 進入本 NTP 伺服器
restrict 127.0.0.1        <==底下兩個是預設值,放行本機來源
restrict -6 ::1
restrict 192.168.100.0 mask 255.255.255.0 nomodify <==放行區網來源


2. 設定主機來源,請先將原本的 [0|1|2].centos.pool.ntp.org 的設定註解掉:

# server [IP or hostname] [prefer]

server 220.130.158.71 prefer  <==以這部主機為最優先
server 59.124.196.83
server 59.124.196.84



3.預設時間差異分析檔案與暫不用到的 keys 等,不需要更動它:

# driftfile [可以被 ntpd 寫入的目錄與檔案]

driftfile /var/lib/ntp/drift
keys      /etc/ntp/keys    後面跟著的是存放 keys 資訊的檔案 .(Client 向 Server 連結的時候 , 可用 key 認證-ntp-keygen)



NTP 的啟動與觀察

1. 啟動 NTP
# /etc/init.d/ntpd start
# chkconfig ntpd on
# tail /var/log/messages  <==自行檢查看看有無錯誤
# tail -f /var/log/syslog

2. 觀察啟動ntp-sever 的 123 埠口是否有開啟:

# netstat -tlunp |grep ntp

udp        0      0 192.168.15.161:123      0.0.0.0:*                      1692/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           1692/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                             1692/ntpd
udp6       0      0 fe80::20c:29ff:fe65:123 :::*                                1692/ntpd
udp6       0      0 ::1:123                 :::*                                1692/ntpd
udp6       0      0 :::123                  :::*                                1692/ntpd


3.如何確認 NTP 伺服器有順利向上層連線後的更新本機的時間
列出目前 NTP-server 與相關的上層 NTP 的狀態

# ntpq -p

 remote             refid        st t when poll reach   delay   offset  jitter
========================================================================
*alqualonde.org  220.130.158.71   3 u   26   64    1   59.984   31.040   9.175
 59-125-147-68.h 220.130.158.72   3 u   25   64    1   15.194    7.389   3.562
 59-124-196-83.h 59.124.196.87    2 u   24   64    1   27.462    5.209   8.279
 59-124-196-84.h 59.124.196.87    2 u   23   64    1   27.716    5.532   7.376



remote:亦即是 NTP 主機的 IP 或主機名稱囉~注意最左邊的符號

    如果有『 * 』代表目前正在作用當中的上層 NTP
    如果是『 + 』代表也有連上線,而且可作為下一個提供時間更新的候選者。

refid:參考的上一層 NTP 主機的位址
st:就是 stratum 階層囉!
when:幾秒鐘前曾經做過時間同步化更新的動作;
poll:下一次更新在幾秒鐘之後;
reach:已經向上層 NTP 伺服器要求更新的次數
delay:網路傳輸過程當中延遲的時間,單位為 10^(-6) 秒
offset:時間補償的結果,單位與 10^(-3) 秒
jitter:Linux 系統時間與 BIOS 硬體時間的差異時間, 單位為 10^(-6) 秒。







其它補充說明

用手動寫入校對時間
# crontab -e
0 0 * * * /usr/sbin/ntpdate time.stdtime.gov.tw && /sbin/hwclock -w

ntpdate:與 NTP Server 進行時間同步的指令,後面接的是所要同步的 NTP Server。
hwclock:可讀取 BIOS 的時間及將時間寫入 BIOS。    


參考網站 :
ntp-keygen  


2012年3月2日 星期五

【Linux】關閉 Linux Ping ( ICMP 協定 ) 回應



Disable Linux ICMP Ping

# echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all

Enable  Linxue ICMP Ping 

# echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all