CloudFormationでVPC環境を作ってみる
今回はCloudFormationを使ってVPC環境を作ってみました。
githubにアップロードしました。
使えそうなら使ってみていただけるとうれしいです。
環境
-
- Availabirityzoneを2つ
- Subnetは計4つ(10.0.1.0/24~10.0.4.0/24)
- Subnet1(10.0.1.0/24), Subnet2(10.0.2.0/24)のサブネットはInternetGatewayをゲートウェイとして使う
- Subnet3(10.0.3.0/24), Subnet4(10.0.4.0/24)のサブネットはNATインスタンスをゲートウェイとして使う
- Subnet1(10.0.1.0/24)にNATインスタンスを作成、EIPを付与
- NATインスタンスにはSubnet3(10.0.3.0/24), Subnet4(10.0.4.0/24)からHTTP(80), HTTPS(443)を許可、VPC内部(10.0.0.0/16)からSSHとICMPを許可
環境はこんな感じです。
今日はこんなところで。
AWS Directory Serviceを試す
AWS Directory Serviceを試してみます。
ほぼ参考をなぞりながら同じ事をやった感じですが、、
自分メモということで。
今回は「Simple AD」を使ってみます。
SimpleADの作成
まずは「AWS Directory Service」から「Simple AD」を選択します。
ディレクトリの情報を入力します。
内容を確認してディレクトリを作成します。
ディレクトリが作成されました。
次に後ほどWindows Serverをドメインに参加させますが、VPCの「DHCP Options Sets」を変更しておきます。
「domain-name-servers」に「Simple AD」のIPアドレスを記載します。
Windows Serverのドメイン追加
続いてEC2でWindows Serverのインスタンスを起動し、Simple AD上のドメインに参加させます。
問題無くドメインが追加できました。一度OSを再起動します。
CloudWatch Logsを試す
今日はCloudWatch Logsを試します。
IAMの設定
CloudWatch Logsを使うために、IAM Roleを用意しておきます。
以下のようなIAM Roleを用意しておきます。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:*" ], "Resource": [ "arn:aws:logs:*:*:*" ] } ] }
インスタンス起動時に、このIAM Roleを設定します。
セットアップ(Amazon Linux)
Amazon Linuxは「amzn-ami-hvm-2014.09.1.x86_64-ebs (ami-4985b048)」を選択しました。
Amazon Linuxの場合は、yumでエージェントをインストールすればOKです。
$ sudo yum install awslogs
その後、エージェントを起動させます。
$ sudo chkconfig awslogs on $ sudo service awslogs start
セットアップ(CentOS)
CentOSは「CentOS 6 x86_64 (2014_09_29) EBS HVM-74e73035-3435-48d6-88e0-89cc02ad83ee-ami-a8a117c0.2 (ami-13614b12)」を選択しました。
CentOSの場合はセットアップスクリプトをダウンロード、実行します。
初期設定で東京リージョンを指定しました。
$ wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py $ sudo python ./awslogs-agent-setup.py --region ap-northeast-1 Launching interactive setup of CloudWatch Logs agent ... Step 1 of 5: Installing pip ...DONE Step 2 of 5: Downloading the latest CloudWatch Logs agent bits ... DONE Step 3 of 5: Configuring AWS CLI ... AWS Access Key ID [None]: AWS Secret Access Key [None]: Default region name [ap-northeast-1]: Default output format [None]: Step 4 of 5: Configuring the CloudWatch Logs Agent ... Path of log file to upload [/var/log/messages]: Destination Log Group name [/var/log/messages]: Choose Log Stream name: 1. Use EC2 instance id. 2. Use hostname. 3. Custom. Enter choice [1]: 1 Choose Log Event timestamp format: 1. %b %d %H:%M:%S (Dec 31 23:59:59) 2. %d/%b/%Y:%H:%M:%S (10/Oct/2000:13:55:36) 3. %Y-%m-%d %H:%M:%S (2008-09-08 11:52:54) 4. Custom Enter choice [1]: 1 Choose initial position of upload: 1. From start of file. 2. From end of file. Enter choice [1]: 1 More log files to configure? [Y]: N Step 5 of 5: Setting up agent as a daemon ...DONE ------------------------------------------------------ - Configuration file successfully saved at: /var/awslogs/etc/awslogs.conf - You can begin accessing new log events after a few moments at https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs: - You can use 'sudo service awslogs start|stop|status|restart' to control the daemon. - To see diagnostic information for the CloudWatch Logs Agent, see /var/log/awslogs.log - You can rerun interactive setup using 'sudo ./awslogs-agent-setup.py --region ap-northeast-1 --only-generate-config' ------------------------------------------------------
その後、エージェントを起動させます。
$ sudo chkconfig awslogs on $ sudo service awslogs start
セットアップ(Redhat Enterprise Linux)
Redhat Enterprise Linuxは「RHEL-6.5_HVM_GA-x86_64-7-HVM-Hourly2 (ami-53641e52)」を選択しました。
セットアップ方法はCentOSと同じ手法で問題ありませんでした。
セットアップ(Windows Server)
Windows Serverは「Windows_Server-2012-R2_RTM-English-64Bit-Base-2014.12.10 (ami-b67e73b7)」を選択しました。
作業前に日本語化を行っておきます。
スタートメニューからアプリケーション一覧を選択し、「EC2ConfigService Settings」をクリックします。
「Enable CloudWatch Logs integration」のチェックをオンにし、設定を有効にします。
以下のファイルをテキストエディタで編集します。
「%PROGRAMFILES%\Amazon\Ec2ConfigService\Settings\AWS.EC2.Windows.CloudWatch.json」
今回はログの転送先を東京リージョンに変更します。
{ "Id": "CloudWatchLogs", "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatchLogsOutput,AWS.EC2.Windows.CloudWatch", "Parameters": { "AccessKey": "", "SecretKey": "", "Region": "ap-northeast-1", "LogGroup": "Default-Log-Group", "LogStream": "{instance_id}" } },
最後に、EC2Configサービスを再起動します。
マネジメントコンソールから確認してみる
設定ができていれば、マネジメントコンソールからログを確認することができます。
下はWindows Serverのイベントログを表示させたものです。
今日はこんなところで。
test-kitchenのTIPS
test-kitchenのTIPS的なメモです。
kitchen のアップロード先を変更する
デフォルトは「/tmp/kitchen」以下に各種ファイルがアップロードされますが、
アップロードされるファイルが大量にあるとエラーになることがあるため、
私は「/var/tmp/kitchen」以下にルートディレクトリを変えて使っています。
「client.rb」も変更にあわせて指定するとパスを変えることができました。
provisioner: name: chef_zero client_rb: file_cache_path: /var/tmp/kitchen/cache checksum_path: /var/tmp/kitchen/checksums file_cache_path: /var/tmp/kitchen/cache file_backup_path: /var/tmp/kitchen/backup cookbook_path: - /var/tmp/kitchen/cookbooks - /var/tmp/kitchen/site-cookbooks data_bag_path: /var/tmp/kitchen/data_bags environment_path: /var/tmp/kitchen/environments node_path: /var/tmp/kitchen/nodes role_path: /var/tmp/kitchen/roles client_path: /var/tmp/kitchen/clients user_path: /var/tmp/kitchen/users validation_key: /var/tmp/kitchen/validation.pem client_key: /var/tmp/kitchen/client.pem encrypted_data_bag_secret: /var/tmp/kitchen/encrypted_data_bag_secret root_path: /var/tmp/kitchen
Chef Client のバージョンを固定する
以下のように記述すると、Chefレシピ適用対象のノードにインストールするChef Clientのバージョンを固定できます。
provisioner: name: chef_zero require_chef_omnibus: 11.16.4
今日はこんなところで。
test-kitchenを並列実行する
タイトル通りのちょっとしたメモです。
test-kitchenを並列実行したいときは、-p(--parallel)オプションをつけると並列でレシピの適用を行えます。
$ kitchen help converge Usage: kitchen converge [INSTANCE|REGEXP|all] Options: -c, [--concurrency=N] # Run a converge against all matching instances concurrently. Only N instances will run at the same time if a number is given. -p, [--parallel], [--no-parallel] # [Future DEPRECATION, use --concurrency] Run a converge against all matching instances concurrently. -l, [--log-level=LOG_LEVEL] # Set the log level (debug, info, warn, error, fatal) Description: The instance states are in order: destroy, create, converge, setup, verify, destroy. Change one or more instances from the current state to the converge state. Actions for all intermediate states will be executed. See http://kitchen.ci for further explanation.
以下は実行してみた例です。
# kitchen converge -c 2 -p -----> Starting Kitchen (v1.2.2.dev) -----> Converging <centos5-32-base-centos>... Preparing files for transfer Resolving cookbook dependencies with Berkshelf 3.1.3... -----> Converging <centos5-64-base-centos>... Preparing files for transfer Resolving cookbook dependencies with Berkshelf 3.1.3... Removing non-cookbook files before transfer Preparing data bags Preparing environments Preparing nodes Preparing roles -----> Installing Chef Omnibus (11.16.4) downloading https://www.getchef.com/chef/install.sh to file /tmp/install.sh trying wget... trying curl... curl: (51) SSL: certificate subject name '*.chef.io' does not match target host name 'www.getchef.com' trying perl... A URI can't be a ARRAY reference at /usr/lib/perl5/vendor_perl/5.8.8/LWP/Simple.pm line 94 trying python... Downloading Chef 11.16.4 for el... downloading https://www.chef.io/chef/metadata?v=11.16.4&prerelease=false&nightlies=false&p=el&pv=5&m=i686 to file /tmp/install.sh.4791/metadata.txt trying wget... url https://opscode-omnibus-packages.s3.amazonaws.com/el/5/i686/chef-11.16.4-1.el5.i686.rpm md5 b83a4dd153f65ef771af50f082951cae sha256 733508a72f16d998d6713a72b514e439f473fb1da5a7593b7c340a0c09cad4ef downloaded metadata file looks valid... downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/5/i686/chef-11.16.4-1.el5.i686.rpm to file /tmp/install.sh.4791/chef-11.16.4-1.el5.i686.rpm trying wget... Removing non-cookbook files before transfer Preparing data bags Preparing environments Preparing nodes Preparing roles -----> Installing Chef Omnibus (11.16.4) downloading https://www.getchef.com/chef/install.sh
今日はこんなところで。
参考
- [What means the opts attribute in Test-Kitchen commands?:title=http://stackoverflow.com/questions/22178777/what-means-the-opts-attribute-in-test-kitchen-commands]