2013年5月1日水曜日

nginx Access-Control-Allow-Originでmultipleな環境に対応する太郎

Ajaxでクロスサイトスクリプティング的なことするとき、アクセス先のサーバに Access-Control-Allow-Originヘッダーを追加しないといけないみたいなんだな。 普通は、 単一サイトからのアクセスでGETだけ許可するのであれば
Access-Control-Allow-Origin http://yattarou.jp;
add_header Access-Control-Allow-Methods GET;
全部許可する場合は
Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET;
でできる。 ただ、大規模なサイトでallで許可するって何されるかわかんないし、ちょっとこわいよねってことで。 指定したサイトだけ許可する方法にしたかったのが、↓の書き方じゃだめだった。
Access-Control-Allow-Origin http://yattarou.jp http://yattarou2.jp;
add_header Access-Control-Allow-Methods GET;
なので、こう書いたらいけたよー yattarou.jpがoriginヘッダーに組み込まれていれば、Access-Control-Allow-Origin:*を付けて上げるっていう ことです。 ただし!!リクエストにorginヘッダーが入っているときのみ有効なので、注意してください。 アプリ、使用するメソッドによっては、originヘッダーが入ってない場合があるので

    server {
        listen       80;
        server_name  yattarou.jp;

        root /home/yattarou;

         location / {

         if ($http_origin ~ "^(http://yattarou.jp|http://yattarou2.jp|http://yattarou3.jp)$") {
           add_header Access-Control-Allow-Origin *;
           add_header Access-Control-Allow-Methods GET;
         }
       }

2013年1月25日金曜日

ubuntu 10.04でvlan×bonding×link aggregation太郎

てこずったのと情報がいろいろ錯綜していたので。
 とりま、ちゃんと設定できた情報メモっときます。
 作業c⌒っ゚д゚)っφ メモメモ...


#
#vlanのid が99と想定
#事前にaptでifenslaveは入れておくこと。
#

cat /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0 eth1

auto eth1
iface eth1 inet manual
bond-master bond0
bond-primary eth0 eth1

auto bond0
iface bond0 inet manual
bond-mode 802.3ad
bond-miimon 100
bond-slaves none

auto vlan99
iface vlan99 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
network xxx.xxx.xxx.xxx
broadcast xxx.xxx.xxx.xxx
vlan-raw-device bond0
gateway xxx.xxx.xxx.xxx




bond99でもいけるみたいなんだけど、vlanでもいけるみたいな感じだった。

2013年1月24日木曜日

openstack swift swauthの設定太郎

swauthの設定方法のめもだお(*´ω`*)
まずはproxyサーバにswauth入れる。

swiftのversionは1.7.5です。 ubuntuは10.04 LTSです。
#
#swauthをaptで持って来れるように設定
#

vim /etc/apt/sources.list.d/swauth.list

#追記
deb http://gholt.github.com/swauth/lucid lucid main

#update
apt-get update

apt-get install python-swauth swauth-doc




つづいて、proxy-server.confの編集


[pipeline:main]
pipeline = catch_errors healthcheck cache staticweb swauth proxy-server 

[app:proxy-server]
allow_account_management = true


#
#xxx.のIPはLBのインターナルIPにしました。
#

[filter:swauth]
use = egg:swauth#swauth
set log_name = swauth
super_admin_key = swauthkey
default_swift_cluster = cluster_name#http://xxx.xxx.xxx.xxx:8080/v1#http://127.0.0.1:8080/v1




つづいて、確認作業


#
#proxy 設定ファイル読み込み
#

swift-init all reload

#
#アカウント追加
#


swauth-add-user -A http://xxx.xxx.xxx.xxx:8080/auth/ -K swauthkey -a -a yattarou yattaroud yattaraouing



#
#確認してみる。下記のようにStorageURLとかがなってればok
#

swift -A http://xxx.xxx.xxx.xxx:8080/auth/v1.0 -U yattarou:yattaroud -K yattaraouing  stat -v
StorageURL: http://xxx.xxx.xxx.xxx:8080/v1/AUTH_6f760e8b-1782-4ab9-af70-c80012495824
Auth Token: AUTH_tk47aee4fa24f1411489e28301c954bc4d
   Account: AUTH_6f760e8b-1782-4ab9-af70-c80012495824
Containers: 0
   Objects: 0
     Bytes: 0
Accept-Ranges: bytes
X-Timestamp: 1359008441.84255
X-Trans-Id: tx12b86fe3b88e4ec689171f74e9e98d44
Content-Type: text/plain; charset=utf-8


2012年12月26日水曜日

Openstack Swift Objectを間違って消しちゃった太郎

OpenStack Swiftでわざとobjectを消したときの復旧方法 基本はないとは思うんだけど、rmとかでミスって消しちゃいました的な感じの対応用に。 ちなみにファイル間違って消して、べつのレプリカからcpしても使えない(objectとして認識できない?) 状態になるので注意だお(*´ω`*)


#まずはファイルを確認する。ファイルあるよね。

root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -l
total 4
drwxr-xr-x 3 yatta_swift yatta_swift  45 Dec 26 14:15 159
drwxr-xr-x 3 yatta_swift yatta_swift  45 Dec 26 14:15 2bb
drwxr-xr-x 3 yatta_swift yatta_swift  45 Dec 26 14:15 a82
drwxr-xr-x 3 yatta_swift yatta_swift  45 Dec 26 14:15 b24
drwxr-xr-x 3 yatta_swift yatta_swift  45 Dec 26 14:15 e20
-rw------- 1 yatta_swift yatta_swift 223 Dec 26 14:15 hashes.pkl
root@yatta-swift01:/srv/node/sdb1/objects/222204# 
root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -l e20/d8ff1b40757392c4af291b9839ae1e20/1356405624.80957.data 
-rw------- 1 yatta_swift yatta_swift 211481 Dec 26 14:15 e20/d8ff1b40757392c4af291b9839ae1e20/1356405624.80957.data
root@yatta-swift01:/srv/node/sdb1/objects/222204#




#
#ディレクトリ消してみる。ポイントはレプリのチェックをする
#hashes.pklも一緒にけすこと。

root@yatta-swift01:/srv/node/sdb1/objects/222204# rm -fR e20/ hashes.pkl 
root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -ltr
root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -ltr
total 0
drwxr-xr-x 3 cy_yatta cy_yatta 45 Dec 26 14:15 b24
drwxr-xr-x 3 cy_yatta cy_yatta 45 Dec 26 14:15 a82
drwxr-xr-x 3 cy_yatta cy_yatta 45 Dec 26 14:15 2bb
drwxr-xr-x 3 cy_yatta cy_yatta 45 Dec 26 14:15 159

#
#そのうち復旧される
#

root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -ltr
total 4
drwxr-xr-x 3 cy_yatta cy_yatta  45 Dec 26 14:15 b24
drwxr-xr-x 3 cy_yatta cy_yatta  45 Dec 26 14:15 a82
drwxr-xr-x 3 cy_yatta cy_yatta  45 Dec 26 14:15 2bb
drwxr-xr-x 3 cy_yatta cy_yatta  45 Dec 26 14:15 159
drwxr-xr-x 3 cy_yatta cy_yatta  45 Dec 26 14:42 e20
-rw------- 1 cy_yatta cy_yatta 223 Dec 26 14:42 hashes.pkl
root@yatta-swift01:/srv/node/sdb1/objects/222204# ls -l e20/d8ff1b40757392c4af291b9839ae1e20/
total 208
-rw------- 1 cy_yatta cy_yatta 211481 Dec 26 14:42 1356405624.80957.data






ブラウザからも確認できたお(*´ω`*) この復旧方法でいいのかちょっと微妙だけど・・・

2012年12月14日金曜日

Openstack swift objectの情報調べる太郎

Swiftでobjectの情報、どのサーバにレプリカがあるかを確認する方法(*´ω`*)
#実データに対して、swift-object-infoコマンドを実行。
#Ring locationのところにどのサーバにレプリカがあるかが表示される
root@swift-obj03:# swift-object-info /srv/node/sdb1/objects/222228/7a4/d90536ed78c14cf9335ebff89e21f7a4/1355209796.68366.data 
Path: /AUTH_yattarou/test/20121202/22/22/22/33/test8957.jpg
  Account: AUTH_yattarou
  Container: test
  Object: 20121202/22/22/22/33/test8957.jpg
  Object hash: d90536ed78c14cf9335ebff89e21f7a4
Ring locations:
  xxx.xxx.xxx.xx1:6000 - /srv/node/sdb1/objects/222228/7a4/d90536ed78c14cf9335ebff89e21f7a4/1355209796.68366.data
  xxx.xxx.xxx.xx2:6000 - /srv/node/sdb1/objects/222228/7a4/d90536ed78c14cf9335ebff89e21f7a4/1355209796.68366.data
  xxx.xxx.xxx.xx3:6000 - /srv/node/sdb1/objects/222228/7a4/d90536ed78c14cf9335ebff89e21f7a4/1355209796.68366.data
Content-Type: image/jpeg
Timestamp: 2012-12-11 16:09:56.683660 (1355209796.68366)
ETag: 3a650f6dd89d775ef02f48963e821706 (valid)
Content-Length: 211481 (valid)
User Metadata: {}

swift-get-nodesコマンドでも同じような情報がとれるんだけど、表示されたパスをみにいくとファイルがない・・・ 使い方まちがってるんだろうか。

2012年11月22日木曜日

Openstack Swift recon太郎

Swiftにreconっていう機能があって、loadとかmemoryとかの情報がとれるみたい。 これを使って監視とかしたらいんかな。 英語よめねからよくわかんね・・・
#proxyサーバからうつぞ
#load averageみる

root@swift-proxy01:~# curl http://xx.xx.xx.xx:6000/recon/load
{"5m": 2.3199999999999998, "15m": 2.27, "processes": 5311, "tasks": "2/364", "1m": 2.4700000000000002}

#memoryの情報チェックするぞ

curl http://xx.xx.xx.xx:6000/recon/mem
{"WritebackTmp": "0 kB", "SwapTotal": "1998840 kB", "Active(anon)": "337664 kB", "SwapFree": "1998840 kB", "DirectMap4k": "6756 kB", "KernelStack": "2936 kB", "MemFree": "128024 kB", "HugePages_Rsvd": "0", "Committed_AS": "4068192 kB", "Active(file)": "4061696 kB", "NFS_Unstable": "0 kB", "VmallocChunk": "34359370072 kB", "Writeback": "0 kB", "Inactive(file)": "15142944 kB", "MemTotal": "24731684 kB", "VmallocUsed": "331016 kB", "HugePages_Free": "0", "AnonPages": "368188 kB", "Active": "4399360 kB", "Inactive(anon)": "30712 kB", "CommitLimit": "14364680 kB", "Hugepagesize": "2048 kB", "Cached": "19014360 kB", "SwapCached": "0 kB", "VmallocTotal": "34359738367 kB", "Shmem": "252 kB", "Mapped": "9884 kB", "SUnreclaim": "811208 kB", "Unevictable": "64 kB", "SReclaimable": "3741636 kB", "Mlocked": "64 kB", "DirectMap2M": "25149440 kB", "HugePages_Surp": "0", "Bounce": "0 kB", "Inactive": "15173656 kB", "PageTables": "5080 kB", "HardwareCorrupted": "0 kB", "HugePages_Total": "0", "Slab": "4552844 kB", "Buffers": "190532 kB", "Dirty": "456 kB"}

#Diskの情報もとれるぞ

curl http://xx.xx.xx.xx:6000/recon/diskusage
[{"device": "sdb1", "avail": 198553079808, "mounted": true, "used": 57811726336, "size": 256364806144}]

#objectのreplicationタイムもとれる(´;ω;`)
curl http://xx.xx.xx.xx:6000/recon/replication
{"object_replication_time": 21.035725466410319}

#asyncの情報もとれるんだけど、nullかえってきてる・・・
#ここは調べときます。

curl http://10.200.32.41:6000/recon/async
{"async_pending": null}

#swift clientからもたたけるんだな

swift-recon object -r --zone 1
===============================================================================
--> Starting reconnaissance on 1 hosts
===============================================================================
[2012-11-16 14:31:19] Checking on replication
[replication_time] low: 21, high: 21, avg: 21.0, total: 21, Failed: 0.0%, no_result: 0, reported: 1
===============================================================================

Openstack Swift ACL太郎

SwiftのACLの方法でおじゃる。
#containerの作成
swift -A http://PROXY_VIP:8080/auth/v1.0 -U yattarou:yattarou -K yattarou post -r '.r:*' Container_Name
 
#indexの作成
swift -A http://PROXY_VIP:8080/auth/v1.0 -U yattarou:yattarou -K yattarou post -m 'web-index:index.html' Container_Name
 
#list設定
swift -A http://PROXY_VIP:8080/auth/v1.0 -U yattarou:yattarou -K yattarou post -m 'web-listings: true' Container_Name
 
#ACLの確認
swift -A http://PROXY_VIP:8080/auth/v1.0 -U yattarou:yattarou -K yattarou stat Container_Name
 
  Account: AUTH_system
Container: Container_Name
  Objects: 1
    Bytes: 12
 Read ACL: .r:*
Write ACL: 
  Sync To: 
 Sync Key: 
Meta Web-Listings: true
Meta Web-Index: index.html