{"id":94,"date":"2014-09-24T19:58:07","date_gmt":"2014-09-24T19:58:07","guid":{"rendered":"https:\/\/www.pendragonsfolly.com\/?p=94"},"modified":"2014-09-24T20:07:40","modified_gmt":"2014-09-24T20:07:40","slug":"aws-linux-ec2-instance-creation-checklist","status":"publish","type":"post","link":"https:\/\/www.pendragonsfolly.com\/?p=94","title":{"rendered":"AWS Linux EC2 Instance Creation Checklist"},"content":{"rendered":"<p>This is intended to be an ongoing check list of tasks (with implementation notes) to perform when creating a new Linux instances on AWS<\/p>\n<ol>\n<li>Choose OS (I am trying to use Ubuntu for instances that don&#8217;t specifically require RHEL )<\/li>\n<li>Create the instance with desired root volume size. \u00a0RHEL seems to create a volume with the specified size, but then allocates a 6GB root partition.<\/li>\n<li>Choose appropriate VPC, subnet (considerations: public, private, AZ, what RDS or other instances need to communicate with it)<\/li>\n<li>Select the appropriate Key (will create additional accounts and assign keys as needed)<\/li>\n<li>Select or Configure Initial security rules<\/li>\n<li>Start instance<\/li>\n<li>Resize root partition if necessary (currently only necessary for RHEL 7 instances)\n<ol>\n<li>Stop the instance<\/li>\n<li>If you have done any configuration already, take a snapshot of the volume to protect your work (only if restoring the snapshot would be worthwhile should something go wrong)<\/li>\n<li>Note the mount point and volume name of the root volume<\/li>\n<li>detach the volume and attach it to another instance (preferable running the same OS\u00a0\u2013 spin a temporary one up if needed). \u00a0You do not need (nor want) to mount it.<\/li>\n<li>See:\u00a0<a class=\"external-link\" href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/storage_expand_partition.html#prepare-linux-root-part\" rel=\"nofollow\">http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/storage_expand_partition.html#prepare-linux-root-part<\/a>\u00a0 (read this to verify the next steps still hold\u00a0\u2013 and to see example output)<\/li>\n<li>make sure that the filesystem is OK<span style=\"text-decoration: underline;\"><strong> BEFORE<\/strong> <\/span>you resize it. \u00a0(the URL above skips this step): \u00a0 xfs_repair \/dev\/xvdf1 \u00a0(<em>for xfs used by RHEL 7<\/em>) <strong><span style=\"text-decoration: underline;\">OR<\/span> for <em>ext4<\/em>:<\/strong> sudo e2fsck -f \/dev\/xvdf1 \u00a0(or whatever device you attached the volume as)<\/li>\n<li>parted \/dev\/xvdf (or whatever device you attached it as)<\/li>\n<li>(parted) unit s<\/li>\n<li>(parted) print<\/li>\n<li>(parted) rm 1<\/li>\n<li>(parted) mkpart primary 2048s 100% <strong><span style=\"text-decoration: underline;\">OR<\/span> (<em>for gpt partitions<\/em>)<\/strong> (parted) mkpart Linux 4096s 100%<\/li>\n<li>(parted) print<\/li>\n<li>(parted) set 1 boot on<\/li>\n<li>(parted) quit<\/li>\n<li>xfs_repair \/dev\/xvdf1 \u00a0(<em>for xfs used by RHEL 7<\/em>)\u00a0<strong><span style=\"text-decoration: underline;\">OR<\/span>\u00a0for\u00a0<em>ext4<\/em>:<\/strong>\u00a0e2fsck -f \/dev\/xvdf1 \u00a0(or whatever device you attached the volume as)<\/li>\n<li>detach the volume and reattach it in the proper place on the new instance<\/li>\n<li>start the instance<\/li>\n<\/ol>\n<\/li>\n<li>Allocate desired swap space as a swap file\n<ol>\n<li>This example will assume an 8 GB swap file (\/var\/swap.1)<\/li>\n<li>sudo\u00a0\u00a0\/bin\/dd if=\/dev\/zero of=\/var\/swap.1 bs=1M count=8000<\/li>\n<li>chmod 600 \/var\/swap.1<\/li>\n<li>sudo \/sbin\/mkswap \/var\/swap.1<\/li>\n<li>sudo \/sbin\/swapon \/var\/swap.1<\/li>\n<li>To enable it by default after reboot, add this line to \/etc\/fstab:\u00a0\/var\/swap.1 swap swap defaults 0 0<\/li>\n<\/ol>\n<\/li>\n<li>Configure hostname\n<ol>\n<li>hostnamectl set-hostname &lt;hostname.FQDN&gt;<\/li>\n<li>add hostname and FQHN to \/etc\/hosts<\/li>\n<li>modify \/etc\/cloud\/cloud.cfg and comment out the set_hostname, update-hostname, and update_etc_hosts lines<\/li>\n<\/ol>\n<\/li>\n<li>Set timezone\n<ol>\n<li>(RHEL 7) \u00a0timedatectl set-timezone America\/Chicago<\/li>\n<li>ln -sf \/usr\/share\/zoneinfo\/America\/Chicago \/etc\/localtime \u00a0 \u00a0(verify that timedatectl did this for RHEL 7 \u2013 if not, do it!)<\/li>\n<\/ol>\n<\/li>\n<li>Create additional accounts\n<ol>\n<li>groups ubuntu (or ec2-user)<\/li>\n<li>useradd -s \/bin\/bash -m -d \/home\/newuser -G adm,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev\u00a0newuser<\/li>\n<li>edit \/etc\/sudoers:<br \/>\nnewuser ALL=(ALL) NOPASSWD:ALLOR change%sudo ALL=(ALL:ALL) NOPASSWD:ALL \u00a0(put NOPASSWD: into existing line\u00a0\u2013 for some reason this works for ubuntu but not for the second user without spec&#8217;ing this)<\/li>\n<li>mkdir ~newuser\/.ssh<\/li>\n<li>vi ~newuser\/.ssh\/authorized_keys<\/li>\n<li>add in the contents of the newuser.pub file from the my\u00a0repository<\/li>\n<li>chmod 700 ~newuser\/.ssh<\/li>\n<li>chmod 600 ~newuser\/.ssh\/authorized_keys<\/li>\n<li>chown -R newuser:newuser ~newuser\/.ssh<\/li>\n<li>test logging into the account from another machine and verify that &#8220;sudo bash&#8221; works.<\/li>\n<\/ol>\n<\/li>\n<li>Allow passwords for SSH (ONLY if required\/desired)\n<ol>\n<li>edit \/etc\/ssh\/sshd_config and set PasswordAuthentication yes<\/li>\n<li>restart sshd<\/li>\n<\/ol>\n<\/li>\n<li>Create and mount additional volumes<\/li>\n<li>Configure automatic backups\n<ol>\n<li>set the Autosnapshot tag to True for all volumes that you want backed up automatically<\/li>\n<\/ol>\n<\/li>\n<li>Install additional software<\/li>\n<li>Do initial software update\n<ol>\n<li>apt-get update &amp;&amp; apt-get dist-upgrade<\/li>\n<li>yum update<\/li>\n<\/ol>\n<\/li>\n<li>Configure automatic updates\n<ol>\n<li>RHEL: yum install yum-cron\n<ol>\n<li>for RHEL &lt; 7, edit \/etc\/sysconfig\/yum-cron<\/li>\n<li>\/etc\/init.d\/yum-cron start<\/li>\n<li>chkconfig yum-cron on<\/li>\n<li>For RHEL &gt;= 7, edit \/etc\/yum\/yum-cron.conf<\/li>\n<li>if you only want security updates =&gt; update_cmd = security<\/li>\n<li>apply_updates = yes (also download_updates)<\/li>\n<\/ol>\n<\/li>\n<li>Ubuntu:\n<ol>\n<li>apt-get install unattended-upgrades<\/li>\n<li>dpkg-reconfigure -plow unattended-upgrades<\/li>\n<li>verify\u00a0\/etc\/apt\/apt.conf.d\/20auto-upgrades<\/li>\n<li>verify\u00a0\/etc\/apt\/apt.conf.d\/50unattended-upgrades (verify reboot time and that automatic reboot is true)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Tag volumes for automatic backup\n<ol>\n<li>set the Autosnap tag to True<\/li>\n<\/ol>\n<\/li>\n<li>Configure and test additional security rules<\/li>\n<li>Create a restore AMI! \u00a0(Since this creates a snapshot, I don&#8217;t &lt;think&gt; this will take up a lot of extra space for instances that we plan to backup anyway.) \u00a0This is a REALLY good idea since restoring a snapshot relies on you to first create a new instance based off the same AMI as the original and then replace or attach the volume on that instance. \u00a0We can&#8217;t guarentee that the original instance will still be available.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This is intended to be an ongoing check list of tasks (with implementation notes) to perform when creating a new Linux instances on AWS Choose OS (I am trying to use Ubuntu for instances that don&#8217;t specifically require RHEL ) &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/www.pendragonsfolly.com\/?p=94\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,1,3],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-aws","category-linux","category-uncategorized","category-work"],"_links":{"self":[{"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":3,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":100,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/100"}],"wp:attachment":[{"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pendragonsfolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}