DRY

Web関連の技術の事、食事/お酒の事、旅行の事など

AzureにCentOSのイメージをMacから作成する方法

AWSGCPを併用しているのですが、Azureは使ってませんでした。
理由はLinuxUbuntuのイメージだったのですが使ってみようかと思いまして。

ただ、ChefのレシピがCentoOSとかAWSLinux向けなので、そこでまたUbuntu用に作るの面倒くさすぎるため、AzureでCentOS6.6を動かしてみた時の方法です。

コマンドのホストはMacです。

CLIインストール

http://azure.microsoft.com/ja-jp/downloads/ からMac用のAzure コマンドライン インターフェイスをインストールします。

アカウント情報ファイルのダウンロード

$ azure account download
を実行するとブラウザが開きpublishSettingsファイルがダウンロードされます。

アカウント情報のインポート

$ azure account import [ダウンロードしたファイル]

仮想マシン作成のコマンド時にSSHするので、鍵を生成します

$ cd ~/.ssh
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout azure.key -out azure.pem

Generating a 2048 bit RSA private key
......+++
............................................+++
writing new private key to 'azure.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

ssh -iする時にパスフレーズを聞かれてしまうので、パスフレーズつけます

$ openssl rsa -des -in azure.key -out azure.key

writing RSA key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:

権限適切にします

$ chmod 600 azure.key
$ chmod 600 azure.pem

インストール可能なVMイメージの一覧

$ azure vm image list

今回はその中から、「0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.6-x64-v14.2.1」を使う事にします。

仮想マシンの作成

$ sudo azure vm create -z Basic_A0 --location "Japan West" --ssh 22 --ssh-cert ~/.ssh/azure.pem -P azure-test 0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.6-x64-v14.2.1 azureuser

info:    Executing command vm create
+ Looking up image 0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.6-x64-v14.2.1
+ Looking up cloud service
warn:    --location option will be ignored
+ Getting cloud service properties
+ Looking up deployment
+ Retrieving storage accounts
+ Configuring certificate
+ Creating VM
info:    OK
info:    vm create command OK

作成済み仮想マシンの確認

$ azure vm list

info:    Executing command vm list
+ Getting virtual machines
data:    Name                  Status            Location    DNS Name                           IP Address
data:    --------------------  ----------------  ----------  ---------------------------------  -------------
data:    azure-test            RoleStateUnknown  Japan West  azure-test.cloudapp.net            xxx.xxx.xx.xx

SSHログイン

$ ssh -i ~/.ssh/azure.key azureuser@azure-test.cloudapp.net

Saving password to keychain failed
Identity added: /Users/xxxx/.ssh/azure.key (/Users/xxxx/.ssh/azure.key)
     ___   _        __   __   ____            __
    / _ \ (_)___ _ / /  / /_ / __/____ ___ _ / /___
   / , _// // _ `// _ \/ __/_\ \ / __// _ `// // -_)
  /_/|_|/_/ \_, //_//_/\__//___/ \__/ \_,_//_/ \__/
           /___/

Welcome to a virtual machine image brought to you by RightScale!


[azureuser@azure-test ~]$ cat /etc/redhat-release
CentOS release 6.6 (Final)

無事OSが入りましたので、後はいつものChefレシピでAzure上でもサーバ完成です。