big-ip rest api

jsonで返ってくるのでjqかなければpython -m json.tool を使うと見易い。

$ curl -s -k --user user:pass https://192.168.0.1/mgmt/tm/ | jq .

URLはこの辺
/tm/net/
/tm/ltm/
/tm/security/
/tm/apm/

ltm

  • node追加
curl --user user:pass -s -k https://192.168.0.1/mgmt/tm/ltm/node \
     -H 'Content-Type: application/json' -X POST \
     -d '{"address": "192.168.0.1", "name": "testnode"}'

responseで帰ってくるの "selfLink": "https://localhost/mgmt/tm/ltm/node/~Common~testnode",
というのこのnodeをapiで操作するurl

  • node削除
curl --user user:pass -s -k https://192.168.0.1/mgmt/tm/ltm/node/~Common~testnode \
     -X DELETE 
  • pool追加

https://192.168.0.1/mgmt/tm/ltm/pool
postパラメータ

'{"name":"testpool-http","monitor":"http","description":"hoge:","members":[{"name":"testnode:80"}]}'

複数monitorを登録する方法は不明

https://192.168.0.1/mgmt/tm/ltm/virtual
postパラメータ

'{"name":"testvirtual-http","destination":"192.168.0.10:80","pool":"testpool-http"}' 

typeがstandardではなくてPerformance(layer 4)になる。。。

afm (security)

  • security address-list一覧

/mgmt/tm/security/firewall/address-list

  • security address-list追加

/mgmt/tm/security/firewall/address-list

'{"name": "hogehoge", "addresses": ["1.1.1.1/32"]}'
  • security address-list変更

PUTメソッドで上書きする
既存の内容を全て上書きするので、追加文だけではなくて既存のものも含める必要がある
/mgmt/tm/security/firewall/address-list/hogehoge -X PUT

'{"addresses": ["1.1.1.1/32", "2.2.2.2/32", "3.3.3.3/32"]}'

nginx のproxy_passするときのホスト名指定とresolver

(OS違ったけど詳細忘れた)現象が発生するサーバとしないサーバあったので、これだけが原因じゃないかも。とりあえず心に留めておく。

location /hoge/ {
  proxy_pass "http://example.com/";
} 

これは問題なく動いた。

proxy_pass先でurlまで指定すると

location /hoge/ {
  proxy_pass "http://example.com/hoge/";
} 

"no resolver defined to resolve"というエラーで502 Bad Gatewayが出た。
(もちろんosの/etc/resolv.confにはdns server指定している)

resolver でdns server指定したら動いた

location /hoge/ {
  resolver 8.8.8.8;
  proxy_pass "http://example.com/hoge/";
} 

big-ipで帯域制御 Bandwith ControllerとRate Shaping

Bandwith Controller

Bandwidth controllers のほうが最新機能のようなのでこっちのがいいかも
Rate Shapingの後継機能のようで、共存はできない。
(どこにも割り当てていないRate Shapingの設定すら存在してはいけない)

Acceleration - Bandwith Controller

VirtualServer
advancedにしてBandwith Controllerを選択

dynamicにするとper user で設定できるみたいだけど、
そのbandwidth controller設定はvirtual serverに適用できなかった。

iruleで適用

拡張子で適用する例
https://devcentral.f5.com/wiki/iRules.BWC__policy.ashx

when HTTP_REQUEST {
  if { [HTTP::path] ends_with ".mp4" } {
    BWC::policy attach bandwidth_test1
  }
}

virtualhost名で振り分ける例

  switch -glob [string tolower [HTTP::host]] {
    "www1.example.com" {
      BWC::policy attach bandwidth_test1
    }
    "www2.example.com" {
      BWC::policy attach bandwidth_test2
    }
  }

Rate Shaping

Acceleration - Rate Shaping

http://www.f5networks.co.jp/shared/pdf/BIG-IP_TB_Rate_Shaping.pdf

適用する箇所
VirtualServer
PacketFilter
iRule

一番使うのはVirtualServerかな

VirtualServer
Acceleration - Rate Class

ガチガチに制限せず、バーストトラフィック発生時に少し余裕を持たせるのであれば
Rate 10Mbps
Ceiling 50Mbps
Burst size 5MByte
とかにすれば良さげ?(数字は適当)

awsのIP一覧

https://ip-ranges.amazonaws.com/ip-ranges.json

jsonで返ってくるのでjq使うと良い。

ex: cloudfront のip prefixだけ抜く

curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service == "CLOUDFRONT") | .ip_prefix'

13.32.0.0/15
13.54.63.128/26
34.195.252.0/24
35.162.63.192/26
52.15.127.128/26
52.46.0.0/18
52.52.191.128/26
52.56.127.0/25
52.57.254.0/24
52.66.194.128/26
52.78.247.128/26
52.84.0.0/15
52.199.127.192/26
52.212.248.0/26
52.220.191.0/26
52.222.128.0/17
54.182.0.0/16
54.192.0.0/16
54.230.0.0/16
54.233.255.128/26
54.239.128.0/18
54.239.192.0/19
54.240.128.0/18
204.246.164.0/22
204.246.168.0/22
204.246.174.0/23
204.246.176.0/20
205.251.192.0/19
205.251.249.0/24
205.251.250.0/23
205.251.252.0/23
205.251.254.0/24
216.137.32.0/19

sshuttle でssh使って簡単vpn

https://github.com/apenwarr/sshuttle


ポートフォワードだと個別にport設定したり、
ブラウザのプロキシ設定いじらないとダメだけど
sshuttle の場合、iptables(macだとpfctl ?)で特定のnetwork宛の通信を
ssh経由にねじまげてくれるのでvpnのように使える。素晴らしい。

VMWareの仮想マシンのdiskを縮小してpartitionを削除する

https://www.experts-exchange.com/articles/12938/HOW-TO-Shrink-a-VMware-Virtual-Machine-Disk-VMDK-in-15-minutes.html

vCenterからいじっただけでは縮小されないので。
linux VMの対応。N GBからM GBに縮小する例。
1. 削除するpartitionをumountしてfstabから消す
2. partitionを削除(これしなくて良いかも)
3. 仮想マシンをshutdown
4. データストアの/vmname/vmname.vmdk を開く
flat.vmdkの行を変更する。
N GBの場合
1024 * 1024 * 1024 * N / 512 の値になっているので
1024 * 1024 * 1024 * M / 512 を計算してその値に変更する

# 50GB
RW 104857600 VMFS "vmname-flat.vmdk"
# 30GB
RW 62914560 VMFS "vmname-flat.vmdk"

5. 仮想マシンのデータストアを移行する

これでvmname-flat.vmdkのサイズが変更後のサイズになった。