用Linux架設SLB(負載平衡)設備

參考資料:
http://kb.hyve.com/wiki/Setup%20a%20Loopback%20adaptor%20in%20Windows%202008%20for%20loadbalancer%20VIP

網路架構 (todo):

 

SLB主機安裝:
1. 灌好CentOS 6.5 OS
2. yum -y install ipvsadm keepalived
3. 編輯/etc/keepalived/keepalived.conf,範例如下

! Configuration File for keepalived

global_defs {
   notification_email {
     your-email@email.com
   }
   notification_email_from email-sender@email.com
   smtp_server 10.10.10.1
   smtp_connect_timeout 30
   router_id LVS_TF4F
}

#vrrp_instance VI_1 {
#    state MASTER
#    interface eth0
#    virtual_router_id 51
#    priority 100
#    advert_int 1
#    authentication {
#        auth_type PASS
#        auth_pass yourpassword
#    }
#    virtual_ipaddress {
#       127.0.0.5
#    }
#}

virtual_server 10.176.20.152 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 1200
    protocol TCP
    virtualhost slb.idc.local
    real_server 10.176.20.131 80 {
        weight 1
        HTTP_GET {
            url {
              path /iisstart.htm
              digest dfbd1ee66a4e792349591b88660c0956
            }
        }
    }
    real_server 10.176.20.132 80 {
        weight 1
        HTTP_GET {
            url {
              path /iisstart.htm
              digest dfbd1ee66a4e792349591b88660c0956
            }
        }

    }
    real_server 10.176.20.153 80 {
        weight 0
        HTTP_GET {
            url {
              path /slb.php
              digest 509f04652b5e1b2d2b9e6bc121a87e50
            }
        }
    }
}

4.啟動keepalived

  chkconfig keepalived on
  service keepalived start

5.觀看目前SLB連線狀態

 ipvsadm -Ln

 

Real Server安裝(CentOS 5/6 Linux)

編輯/etc/sysctl.conf加入下面兩行,設定後記得使用sysctl -p生效

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

新增/etc/sysconfig/ifcfg-lo:0檔案並加入下面內容

DEVICE=lo:0
IPADDR=10.176.20.152
NETMASK=255.255.255.255
ONBOOT=yes

啟動loopback網卡

ifup lo:0

 

Real Server安裝(Windows 2008 R2) (todo)
1.新增Loopback Interface
1

 

 

 

 

 

 

 

 

 

 

 

 

 

2 3 4 5 6 7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最後請執行下面指令

netsh interface ipv4 set interface "區域連線" weakhostreceive=enabled
netsh interface ipv4 set interface "Loopback" weakhostreceive=enabled
netsh interface ipv4 set interface "Loopback" weakhostsend=enabled

 

 

 

 

 

 

 

 

 

Windows 2008 R2 sysprep 自動化

參考資料:
How to Sysprep in Windows Server 2008 R2 and Windows 7

The Complete Guide to Preparing a Windows 7 Deployment Image using Audit Mode and Sysprep with an unattend.xml Answer File

 

基本上照著reference裡link這幾位高手的SOP跑一遍大概就OK了

幾個重點紀錄一下

  1. 要準備好windows 2008 r2 的source光碟 (裡面的/source/install.wim這個檔案 WAIK要用到)
  2. 將source光碟中的/source/install.wim (約2.7Gb)複製到硬碟 (複製完後把install.wim唯讀屬性移除)
  3. 下載並安裝Windows Automated Installation Kit (WAIK)

unattend.xml範例
目的一:自動化sysprep (全自動執行不跳出需要人工點選畫面)
目的二:修改administrator預設密碼(改成Passw0rd)

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="generalize">
        <component name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon>
        </component>
        <component name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <InputLocale>zh-TW</InputLocale>
            <SystemLocale>zh-TW</SystemLocale>
            <UserLocale>zh-TW</UserLocale>
            <UILanguage>zh-TW</UILanguage>
        </component>
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <OOBE>
                <HideEULAPage>true</HideEULAPage>
            </OOBE>
            <UserAccounts>
                <AdministratorPassword>
                    <Value>UABhAHMAcwB3ADAAcgBkAEEAZABtAGkAbgBpAHMAdAByAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==</Value>
                    <PlainText>false</PlainText>
                </AdministratorPassword>
            </UserAccounts>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="catalog:d:/sources/install_windows server 2008 r2 serverstandard.clg" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>

 

XenServer 6.2.0 hotfix update script

2013/12/14 update
XS62ESP1出來了
http://support.citrix.com/article/CTX139789

 

#!/bin/bash
xe patch-upload file-name=XS62E001.xsupdate
xe patch-upload file-name=XS62E002.xsupdate
xe patch-upload file-name=XS62E004.xsupdate
xe patch-upload file-name=XS62E005.xsupdate
xe patch-upload file-name=XS62E009.xsupdate
xe patch-upload file-name=XS62E011.xsupdate
xe patch-upload file-name=XS62E012.xsupdate
xe patch-pool-apply uuid=dedcc0dd-d8f3-4f76-90ca-92697c7a44f0
xe patch-pool-apply uuid=59128f15-92cd-4dd9-8fbe-a0115d1b07a2
xe patch-pool-apply uuid=5579f1f0-ff83-11e2-b778-0800200c9a66
xe patch-pool-apply uuid=aeff92a9-2c60-43eb-b34e-14e4132b411c
xe patch-pool-apply uuid=d9c753b9-a15b-4a31-897b-97fdae609031
xe patch-pool-apply uuid=ff202d2d-2812-4c6b-b500-2f4701de7bc4
xe patch-pool-apply uuid=a4251789-ce6c-4726-942c-3cddbadcaca6

 

MySQL mysql-bin log檔案如何rotate/remove?

Ref:
http://dev.mysql.com/doc/refman/5.0/en/log-file-maintenance.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_expire_logs_days
http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html

環境
CentOS 5 x86_64 with MySQL 5.0.95

問題
為了提升MySQL效能有將/etc/my.cnf改成使用/usr/share/mysql/my-huge.cnf
套用/usr/share/mysql/my-huge.cnf後就會enable mysql bin log (for replication/cluster)

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

此設定預設沒有啟動自動logrotate機制跑久了硬碟鐵定爆炸

解法1.1 (自動定期刪除)(修改設定檔)(是否正確生效待驗證)
於/etc/my.cnf加入下面這行 (超過3天的自動移除)

expire_logs_days=3

解法1.2 (自動定期刪除)(動態修改系統變數)

SHOW VARIABLES WHERE Variable_Name='expire_logs_days';
SET GLOBAL expire_logs_days = 1;
SHOW VARIABLES WHERE Variable_Name='expire_logs_days';

 

解法2 (人工刪除)

PURGE BINARY LOGS TO 'mysql-bin.000010';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

 

Todo
CentOS 6驗證

csv轉powercli語法大量rename VM

ref:
https://communities.vmware.com/message/2252750

csv example

Old_Name001,VM Description,New_Name001
Old_Name002,VM Description,New_Name002
Old_Name003,VM Description,New_Name003
Old_Name004,VM Description,New_Name004

 

 

<?php

$file1 = file('example.csv');
#print_r($file1);

foreach($file1 as $line){
  $tmp = preg_split("/,/", $line);
  #print_r($tmp);
  $old_name = trim($tmp[0]);
  $new_name = trim($tmp[2]);

  echo "#rename VM $old_name -> $new_name\n";
  echo "\$VM = Get-VM -Name '$old_name'\n";
  echo "Set-VM -VM \$VM -Name '$new_name' -Confirm:\$false\r\n"; #配合Windows txt格式換行符號需調整為\r\n

}//foreach

?>

 

Output

#rename VM Old_Name001 -> New_Name001
$VM = Get-VM -Name 'Old_Name001'
Set-VM -VM $VM -Name 'New_Name001' -Confirm:$false
#rename VM Old_Name002 -> New_Name002
$VM = Get-VM -Name 'Old_Name002'
Set-VM -VM $VM -Name 'New_Name002' -Confirm:$false
#rename VM Old_Name003 -> New_Name003
$VM = Get-VM -Name 'Old_Name003'
Set-VM -VM $VM -Name 'New_Name003' -Confirm:$false
#rename VM Old_Name004 -> New_Name004
$VM = Get-VM -Name 'Old_Name004'
Set-VM -VM $VM -Name 'New_Name004' -Confirm:$false