[Cloud] Import VMDK to Amazon EC2

1.從ESXi Server先將虛擬機export 出來

export出後會得到如下圖的內容,裡面的vmdk就是我們要匯入到EC2的東東啦!!

2.安裝EC2的Command Line Tool可由此下載
解壓後就算完成安裝,別忘了設定EC2_HOME及JAVA_HOME,所有的指令才能正常使用
Linux : export EC2_HOME=/opt/ec2-api-tools
            export JAVA_HOME=/usr/local/java/jdk-1.6.0_43

M$Win : set EC2_HOME=C:\ec2-api-tools
              set JAVA_HOME=C:\java\jdk1.6.0_31

3.利用ec2-import-instance command來直接匯入VMDK並利用它產生EC2的instance.


/EC2_HOME/bin/ec2-import-instance /PATH_TO_VMDK_FILE/Win8x64.vmdk -f VMDK -t m1.small -a x86_64 -b vmdk2ec2 -o AKIAJQ6QAZ2H3LHOPMDQ -w Kt/G8SfqwertyU3eNaO/kQUb123tjm1Qa/YN -O AKIAJQ6QAZ2H3LHOPMDQ -W Kt/G8SfqwertyU3eNaO/kQUb123tjm1Qa/YN --region ap-southeast-1

其中 -t : Instance Type(m1.small,m1.medium,m1.large...etc),指的是要使用的機器效能
       -a : architecture (i386, x86_64)
       -f  : format (VMDK, VHD...etc)
       -b : S3 的bucket名稱
       -o/O  : owner id (可由Security credential取得)
       -w/W : security key (可由Security credential取得)

執行結果如下:

4.上傳後可透過 ec2-describe-conversion-tasks 來確認上傳後的轉檔過程與階段
請注意StatusMessage 狀態會由 Pending -> Completed

/EC2_HOME/bin/ec2-describe-conversion-tasks import-i-fg7n41ey -O AKIAJQ6QAZ2H3LHOPMDQ -W Kt/G8SfqwertyU3eNaO/kQUb123tjm1Qa/YN --region ap-southeast-1
執行結果如下:
(Pending)
(Completed)

進到EC2 Console啟動它!!



小提醒:
如果你這個Instance不用了你要terminate掉,別忘了在Terminate後要到Volume去把這個Instance相對應用到的 volume 也刪除!!

[Postgres] Postgres-XC 安裝手冊

1.Download, untar, make, install
$groupadd pgxc
$useradd pgxc -g pgxc
$passwd pgxc
$mkdir /pgdata_xc
$chown -R pgxc:pgxc /pgdata_xc
$tar -zxvf pgxc-v1.0.3.tar.gz
$cd postgres-xc/
$yum install gcc flex perl readline-devel zlib-devel openssl-devel pam-devel libxml2-devel libxml2 libxslt libxslt-devel openldap openldap-devel python-devel bison
$./configure --prefix=/opt/pgsql_xc  --with-segsize=8 --with-wal-segsize=64 --with-wal-blocksize=64 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety
$gmake
$gmake install

Global setting (edit ~/.bash_profile)
-------------------------------------
(Optional)
export PGPORT=XXXX
export PGDATA=/pgdata_xc/XXXXXX
export LANG=en_US.utf8

(Conv)
export PGHOME=/opt/pgsql_xc
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
alias rm='rm -i'
alias ll='ls -lh'
--------------------------------------

2.Config Data Node
### data node 1 ###
$mkdir -p /pgdata_xc/db_data
$initdb -D /pgdata_xc/db_data --nodename db_data_1  -E UTF8 -U postgres -W

modify postgresql.conf
-----------------------
port = 15431
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = '192.168.1.53'
gtm_port = 6666
#pgxc_node_name = 'db_data_1'
pooler_port = 6667
max_pool_size = 100
-----------------------

modify pg_hba.conf
-----------------------
host all all 192.168.38.0/24 trust
or
host all all gtm_server_ip/32 trust
-----------------------

### data node 2 ###
$mkdir -p /pgdata_xc/db_data   <- data="" node="" p="" second="">$initdb -D /pgdata_xc/db_data --nodename db_data_2  -E UTF8 -U postgres -W

modify postgresql.conf
-----------------------
port = 15432
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = '192.168.1.53'
gtm_port = 6666
#pgxc_node_name = 'db_data_2'
pooler_port = 6667
max_pool_size = 100
-----------------------

modify pg_hba.conf
-----------------------
host all all 192.168.38.0/24 trust
or
host all all gtm_server_ip/32 trust
-----------------------

3.Config GTM
$mkdir -p /pgdata_xc/gtm
$initgtm -Z gtm -D /pgdata_xc/gtm


4.Config Coordinator Node
### coordinator node 1 ###
$mkdir -p /pgdata_xc/coord1
$initdb -D /pgdata_xc/coord1 --nodename coord1  -E UTF8 -U postgres -W

modify postgresql.conf
-----------------------
listen_addresses = '*'
port = 1921
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = '192.168.38.53'
gtm_port = 6666
#pgxc_node_name = 'coord1'
pooler_port = 6667
max_pool_size = 100
-----------------------

modify pg_hba.conf
-----------------------
host all all 192.168.38.0/24 trust
or
host all all data_node_ip/32 trust
-----------------------

### coordinator node 2 ###
$mkdir -p /pgdata_xc/coord2
$initdb -D /pgdata_xc/coord2 --nodename coord2  -E UTF8 -U postgres -W

modify postgresql.conf
-----------------------
listen_addresses = '*'
port = 1921
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
gtm_host = '192.168.38.53'
gtm_port = 6666
#pgxc_node_name = 'coord2'
pooler_port = 6667
max_pool_size = 100
-----------------------

modify pg_hba.conf
-----------------------
host all all 192.168.38.0/24 trust
or
host all all data_node_ip/32 trust
-----------------------

5.Startup (su - pgxc)
a)GTM
$gtm -D /pgdata_xc/gtm &
b)Data node
$postgres -X -D /pgdata_xc/db_data -p 15431  -i &   <- data="" first="" node="" p=""> $postgres -X -D /pgdata_xc/db_data -p 15431  -i &   <- data="" node="" p="" second="">c)Coordinator node
$postgres -C -D /pgdata_xc/coord2 -p 1921  -i &
$postgres -C -D /pgdata_xc/coord1 -p 1921  -i &

d) stop all service
#pg_ctl stop -D /pgdata_xc/coord2 -p 1921    (node2)
#pg_ctl stop -D /pgdata_xc/coord1 -p 1921    (node1)
#pg_ctl stop -D /pgdata_xc/db_data -p 15431  (node1)
#pg_ctl stop -D /pgdata_xc/db_data -p 15431  (node2)
#pg_ctl stop -D /pgdata_xc/db_data_slave -p 15432 (node1)
#pg_ctl stop -D /pgdata_xc/db_data_slave -p 15432 (node2)
#gtm_ctl stop -Z gtm -D /pgdata_xc/gtm       (gtm server)

6.check status
a)GTM
[pgxc@pgxc-1 ~]$ gtm_ctl status -Z gtm -D /pgdata_xc/gtm
gtm_ctl: server is running (PID: 1551)
  "-D" "/pgdata_xc/gtm"
1 master
b)Data node and Coordinator node
[pgxc@pgxc-1 ~]$ ps -ef | grep pgxc
pgxc      1551  1526  0 11:36 pts/0    00:00:00 gtm -D /pgdata_xc/gtm   <-gtm p=""> pgxc      1561  1526  0 11:38 pts/0    00:00:00 postgres -X -D /pgdata_xc/db_1/pg_root -p 15431 -i    <-datanode nbsp="" p=""> pgxc      1569  1526  0 11:39 pts/0    00:00:00 postgres -C -D /pgdata_xc/coord_1 -p 1921 -i    <-coordinatornode p=""> pgxc      1572  1569  0 11:39 ?        00:00:00 postgres: pooler process  <-pooler atanode="" oordinator="" p="" process="">

7.在CoordinatorNode上註冊DataNode
### coordinator node 1 ###
#psql -p 1921 -U postgres
postgres=# CREATE NODE db_data_1 WITH (TYPE='datanode',HOST = '192.168.38.53', PORT=15431);
postgres=# CREATE NODE db_data_2 WITH (TYPE='datanode',HOST = '192.168.38.54', PORT=15431);
postgres=# CREATE NODE coord2 WITH (TYPE='coordinator',HOST = '192.168.38.54', PORT=1921);
postgres=# select * from pgxc_node;
node_name | node_type | node_port |   node_host   | nodeis_primary | nodeis_preferred |   node_id
-----------+-----------+-----------+---------------+----------------+------------------+-------------
coord1    | C         |      5432 | localhost     | f              | f                |  1885696643
db_data_1 | D         |     15431 | 192.168.38.53 | t              | t                |  1356996994
db_data_2 | D         |     15431 | 192.168.38.54 | t              | t                |  -822936791
coord2    | C         |      1921 | 192.168.38.54 | f              | f                | -1197102633

#SELECT pgxc_pool_reload();  (if alter node, execute it)

### coordinator node 2 ###
#psql -p 1921 -U postgres
postgres=# CREATE NODE db_data_1 WITH (TYPE='datanode',HOST = '192.168.38.53', PORT=15431);
postgres=# CREATE NODE db_data_2 WITH (TYPE='datanode',HOST = '192.168.38.54', PORT=15431);
postgres=# CREATE NODE coord1 WITH (TYPE='coordinator',HOST = '192.168.38.53', PORT=1921);
postgres=# select * from pgxc_node;
node_name | node_type | node_port |   node_host   | nodeis_primary | nodeis_preferred |   node_id
-----------+-----------+-----------+---------------+----------------+------------------+-------------
coord2    | C         |      5432 | localhost     | f              | f                | -1197102633
db_data_1 | D         |     15431 | 192.168.38.53 | t              | t                |  1356996994
db_data_2 | D         |     15431 | 192.168.38.54 | t              | t                |  -822936791
coord1    | C         |      1921 | 192.168.38.53 | f              | f                |  1885696643

#SELECT pgxc_pool_reload();  (if alter node, execute it)

8.Test (在Coordinator1做的create database, table and insert data,會在Coordinator2看到一樣的結果,反之亦然)
### Coordinator node 1 ###
$psql -p 1921 -U postgres
postgres=# \l
postgres=# create database test_xc;
postgres=# \l
postgres=# \c test_xc
test_xc=# create table test_1 (id integer,name varchar(32));
test_xc=# insert into test_1 select generate_series(1,100),'test_xc';
test_xc=# select count(*) from test_1;
count
-------
  402
(1 row)

### Coordinator node 2 ###
$psql -p 1921 -U postgres
postgres=# \l
postgres=# \c test_xc
test_xc=# \d
test_xc=# select count(*) from test_1;
count
-------
  402
(1 row)

### Data node 1 ### (可以看到每個Data node的筆數不同,表示他會平均分散資料存放,可減少IO增進Query performance)
$psql -p 15431 -U postgres -d test_xc
test_xc=# \d
test_xc=# select count(*) from test_1;
  count
-------
    204
(1 row)

### Data node 2 ###
$psql -p 15431 -U postgres -d test_xc
test_xc=# \d
test_xc=# select count(*) from test_1;
count
-------
  198
(1 row)