2017年7月24日 星期一

Extend Disk in Centos7 with XenServer or VMWare

背景設定

1. 硬碟=50GB

2. 分區如下使用LVM

/boot   500 MiB
swap   2048MiB
/          102400 MiB
/data   其他

3. vg-group name = centos

4.擴展/data空間    , data 的位置為 /dev/centos/data





新增硬碟大小


將VM主機關機後 , 硬碟新增至100GB , 啟動主機



確認硬碟大小是否有增加


#fdisk -l /dev/xvda



格式化新增的空間


#fdisk /dev/xvda 

#n  (新增分區) 

#p  (primary) 

#3   (假設為xvd3 ,也可直接enter)

#t  (修改格式)

#8e  (LVM的格式)

#3  (選擇修改格式的分區)

# w  (存檔)


擴展VG空間


#vgextend centos /dev/sda3



檢查VG空間是否增加


#vgdisplay



擴展data lvm空間


#lvextend -L +50G /dev/centos/data

#xfs_growfs /dev/centos/data


檢查/data是否已經擴展空間


#df -h 







2017年7月16日 星期日

Set up Gre Tunnel with ddos protection on Centos 6 - AWS EC2 (二)

環境


對外防禦IP  49.x.x.x
廠商 gre public ip 106.x.x.x
廠商 gre pravite ip 10.10.10.1
本機 gre pravite ip 10.10.10.2
本機 gre public ip   98.x.x.x (ec2 EIP )
本機eth0 192.168.1.64
後端主機eth0 192.168.1.184


為了讓玩家透過對外防禦IP 49.x.x.x 訪問Gre Server後端的實際主機 (192.168.1.184)
需要透過iptables DNAT,SNAT,FORWARD來達到同進同出的效果




1. 允許ip fordword

vi /etc/systcl.conf

#新增
net.ipv4.ip_forward=1 


2. 使ip_forward生效

systcl -p


3. 配置iptables 

(預設fordward Accept ,所以不用配置規則)

vi iptables.sh


#清空設定
iptables -X
iptables -F
iptables -Z
iptables -t nat -X
iptables -t nat -F
iptables -t nat -Z

#input , output , forward 預設Accept
iptables -P   INPUT ACCEPT
iptables -P  OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

SNAT讓封包正常回到gre tunnel
iptables -t nat -A POSTROUTING -o eth0 -j SNAT  --to-source 192.168.1.64

#  DNAT-讓訪問對外防禦IP 49.x.x.x:81的封包,目的端轉址為192.168.1.184:80 
iptables -t nat -A PREROUTING -p tcp -d 49.x.x.x/32 --dport 81 -j DNAT --to-destination 192.168.1.184:80


4. 執行iptables shell

sh iptables.sh


5. 開機啟動

#存檔/etc/sysconfig/iptables
/etc/init.d/iptables save 

#開機啟動
chkconfig iptables on



6.實現同進同出

#新增ip rule
/sbin/ip rule add from 192.168.1.184 lookup gre




Set up Gre Tunnel with ddos protection on Centos 6 - AWS EC2 (一)

環境

對外防禦IP  49.x.x.x
廠商 gre public ip 106.x.x.x
廠商 gre pravite ip 10.10.10.1
本機 gre pravite ip 10.10.10.2
本機 gre public ip   98.x.x.x (ec2 EIP )
本機eth0 192.168.1.64
後端主機eth0 192.168.1.184

為了和廠商建立GRE Tunnel , 並綁定對外防禦IP到loopback

1. 開啟GRE 模組

modprobe ip_gre


2. 開機啟動GRE模組

echo "/sbin/modprobe ip_gre > /dev/null 2>&1" > /etc/sysconfig/modules/ip_gre.modules && chmod 755 /etc/sysconfig/modules/ip_gre.modules


3.配置tunnel 網卡

vi /etc/sysconfig/network-scripts/ifcfg-tun0

DEVICE=tun0
BOOTPROTO=none
ONBOOT=yes
TYPE=GRE
PEER_OUTER_IPADDR= 106.x.x.x (廠商gre public ip)
PEER_INNER_IPADDR=10.10.10.1 (廠商gre prative ip)
MY_INNER_IPADDR= 10.10.10.2 (本機 gre prative ip)
MTU=1476


4. 啟動網卡 

    ifup tun0


5. 測試gre tunnel 是否連線成功

ping 10.10.10.1
(如果通了 gre tunnel 就建立成功)


6. 配置對外防禦IP在 loopback上   

vi /etc/sysconfig/network-scripts/ifcfg-lo:0

EVICE=lo:0
IPADDR= 49.x.x.x (對外防禦IP)
NETMASK=255.255.255.255
NETWORK= 49.x.x.x (對外防禦IP)
BROADCAST= 49.x.x.x (對外防禦IP)
ONBOOT=yes
NAME=loopback


7. 配置對稱路由 (symmetric routing)

vi /etc/iproute2/rt_tables

#新增 routing table
200 gre

8. 新增ip rules , 讓對外防禦IP從tun0 出去 , 並達成同進同出

/sbin/ip rule add from 49.x.x.x lookup gre
/sbin/ip route add default via 10.10.10.1 dev tun0 table gre


....待續