{"id":4983,"date":"2022-03-01T18:49:57","date_gmt":"2022-03-01T09:49:57","guid":{"rendered":"https:\/\/suzutukiblog.com\/?p=4983"},"modified":"2022-03-07T19:16:27","modified_gmt":"2022-03-07T10:16:27","slug":"ec2","status":"publish","type":"post","link":"https:\/\/suzutukiblog.com\/index.php\/2022\/03\/01\/ec2\/","title":{"rendered":"\u30dd\u30fc\u30c8\u30d5\u30a9\u30ea\u30aa\u3092\u30c7\u30d7\u30ed\u30a4\u3057\u305f\u3068\u304d\u306eEC2\u306e\u8a2d\u5b9a1(EC2+RDS+NGINX+Puma)"},"content":{"rendered":"<h3>\u30dd\u30fc\u30c8\u30d5\u30a9\u30ea\u30aa\u3092AWS\u306eEC2\u306b\u30c7\u30d7\u30ed\u30a4\u3057\u305f\u6642\u306b\u3084\u3063\u305f\u3053\u3068<\/h3>\n<h3>EC2\u3092\u4f5c\u6210<\/h3>\n<p>\u7121\u6599\u5229\u7528\u67a0\u3067\u4f5c\u6210\u3059\u308b\u8a73\u3057\u304f\u306f<\/p>\n<h3>0:EC2\u306b\u63a5\u7d9a\u3059\u308b<\/h3>\n<p>EC2\u306e\u63a5\u7d9a\u304b\u3089<strong>\u4f8b\uff1a<\/strong>\u306e\u90e8\u5206\u3092\u30b3\u30d4\u30fc\u3057\u3066\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u884c\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5042\" src=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8.png\" alt=\"\" width=\"1075\" height=\"828\" srcset=\"https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8.png 1075w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8-300x231.png 300w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8-1024x789.png 1024w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8-768x592.png 768w, https:\/\/suzutukiblog.com\/wp-content\/uploads\/2022\/03\/42b051b206474922afeb4860ab0e69e8-624x481.png 624w\" sizes=\"auto, (max-width: 1075px) 100vw, 1075px\" \/><\/p>\n<pre>ssh -i \"EC2\u306e\u79d8\u5bc6\u9375.pem\" ec2-user@\u81ea\u5206\u306eElasticIP\u30a2\u30c9\u30ec\u30b9<\/pre>\n<h3 class=\"p1\">1:\u30e6\u30fc\u30b6\u30fc\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<pre class=\"p1\"><strong>sudo adduser newuser<\/strong>\r\n\r\n<strong>sudo passwd newuser<\/strong><\/pre>\n<h3><strong>2:root<\/strong><strong>\u6a29\u9650\u3092\u4ed8\u52a0(root\u306e\u2193\u306b\u8ffd\u52a0\u3057\u307e\u3059)<\/strong><\/h3>\n<pre class=\"p1\">sudo visudo\r\n\r\nroot <span class=\"Apple-converted-space\">\u00a0 <\/span>ALL=(ALL)<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>ALL\r\nnewuser <span class=\"Apple-converted-space\">\u00a0 <\/span>ALL=(ALL)<span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>ALL<\/pre>\n<h3 class=\"p1\">3:\u4eca\u4f5c\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u3092\u5909\u66f4<\/h3>\n<p><!--more--><\/p>\n<pre class=\"p1\">sudo su - newuser<\/pre>\n<h3 class=\"p1\">4:\u30ed\u30fc\u30ab\u30eb(\u81ea\u5206\u306ePC\u4e0a)\u3067\u884c\u3046(\u8a8d\u8a3c\u7528\u306e\u9375\u306e\u4f5c\u6210\u3068\u8a2d\u5b9a\u3092\u66f8\u304f)<\/h3>\n<pre class=\"p1\">cd ~\/.ssh<\/pre>\n<h3 class=\"p1\">5:\u8a8d\u8a3c\u7528\u306e\u9375\u306e\u4f5c\u6210<\/h3>\n<pre class=\"p1\">ssh-keygen -t rsa<\/pre>\n<h3>6:\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3093\u3067\u30b7\u30e7\u30fc\u30c8\u30cf\u30f3\u30c9\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3002<\/h3>\n<pre class=\"p1\"><strong>vi ~\/.ssh\/config<\/strong><\/pre>\n<pre>Host aws\r\nHostname 123.456.789.10    \uff03\u2190\u81ea\u5206\u306eElasticIP\u3092\u66f8\u304d\u307e\u3059\r\nPort 22\r\nUser newuser     #\u2190\u5148\u7a0bEC2\u3067\u4f5c\u6210\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u540d\r\nIdentityFile ~\/.ssh\/id_rsa         #\u2190\u79d8\u5bc6\u9375\u306e\u5834\u6240\u3092\u66f8\u304d\u307e\u3059<\/pre>\n<h3 class=\"p1\">7:\u4f5c\u6210\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b(authorized_keys\u306b\u30ed\u30fc\u30ab\u30eb\u3067\u4f5c\u3063\u305f\u516c\u958b\u9375\u3092\u767b\u9332\u3059\u308b\u3002)<\/h3>\n<pre>ssh -i \"EC2\u306e\u79d8\u5bc6\u9375.pem\" ec2-user@ElasticIP\u30a2\u30c9\u30ec\u30b9<\/pre>\n<pre class=\"p1\">mkdir .ssh\r\n\r\nchmod 700 .ssh\r\n\r\ncd .ssh\r\n\r\nvim authorized_keys\r\n\r\n#\u516c\u958b\u9375\u3092\u8a18\u8ff0\u3057\u3066\u30bb\u30fc\u30d6\u3057\u307e\u3059\r\n\r\nchmod 600 authorized_keys\r\n\r\nexit\r\n\r\nexit<\/pre>\n<h3 class=\"p1\">8:\u4f5c\u6210\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u3067\u63a5\u7d9a\u3067\u304d\u308b\u304b\u78ba\u8a8d\u3059\u308b(aws\u306e\u90e8\u5206\u306fHost\u540d\u3067\u5909\u308f\u308a\u307e\u3059)<\/h3>\n<pre class=\"p1\">ssh aws\r\n\r\n#ec2-user(\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u305f\u3081\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30e6\u30fc\u30b6\u30fc\u3092\u524a\u9664\u3057\u307e\u3059)\r\nsudo userdel -r ec2-user<\/pre>\n<h3>9:\u8272\u3005\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h3>\n<pre class=\"p1\">sudo yum<span class=\"Apple-converted-space\">\u00a0 <\/span>-y update\r\n\r\n#\u307e\u3068\u3081\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b(\u3059\u3079\u3066\u30b3\u30d4\u30fc\u3057\u3066\u5b9f\u884c)\r\nsudo yum install \\\r\n\r\ngit make gcc-c++ patch \\\r\n\r\nopenssl-devel \\\r\n\r\nzlib-devel readline-devel \\\r\n\r\nmysql mysql-devel \\\r\n\r\neadline-devel \\\r\n\r\nepel-release<\/pre>\n<h3 class=\"p1\"><b>10.rbenv\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/b><\/h3>\n<pre class=\"p1\">git clone https:\/\/github.com\/sstephenson\/rbenv.git ~\/.rbenv<\/pre>\n<h3>11:\u30d1\u30b9\u3092\u901a\u3057\u3057\u307e\u3059\u3002<\/h3>\n<pre class=\"p1\">echo 'export PATH=\"$HOME\/.rbenv\/bin:$PATH\"' &gt;&gt; ~\/.bash_profile\r\n\r\necho 'eval \"$(rbenv init -)\"' &gt;&gt; ~\/.bash_profile\r\n\r\nsource .bash_profile<\/pre>\n<h3>12:ruby\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"p1\">git clone https:\/\/github.com\/sstephenson\/ruby-build.git ~\/.rbenv\/plugins\/ruby-build\r\n\r\nrbenv rehash\r\n\r\nrbenv install -v 2.5.1\r\n\r\nrbenv global 2.5.1\r\n\r\nrbenv rehash\r\n\r\nruby -v<\/pre>\n<h3>13:node.js\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"p1\">curl -sL https:\/\/rpm.nodesource.com\/setup_14.x | sudo bash -\r\n\r\nsudo yum -y install nodejs\r\n\r\nnode -v<\/pre>\n<h3>14:yarn\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"p1\">curl -sL https:\/\/dl.yarnpkg.com\/rpm\/yarn.repo | sudo tee \/etc\/yum.repos.d\/yarn.repo\r\n\r\nsudo yum -y install yarn\r\n\r\nyarn -v<\/pre>\n<h3>15:\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210(\/var\/www)<\/h3>\n<p class=\"p1\">\/(\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea)\u3067\u884c\u3046<\/p>\n<pre class=\"p1\">cd \/\r\n\r\nsudo chown newuser:newuser \/var\r\n\r\ncd \/var\r\n\r\nmkdir www<\/pre>\n<p><a href=\"https:\/\/suzutukiblog.com\/index.php\/2022\/03\/07\/ec2-2\/\">\u305d\u306e\uff12\u306b\u7d9a\u304f<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30dd\u30fc\u30c8\u30d5\u30a9\u30ea\u30aa\u3092AWS\u306eEC2\u306b\u30c7\u30d7\u30ed\u30a4\u3057\u305f\u6642\u306b\u3084\u3063\u305f\u3053\u3068 EC2\u3092\u4f5c\u6210 \u7121\u6599\u5229\u7528\u67a0\u3067\u4f5c\u6210\u3059\u308b\u8a73\u3057\u304f\u306f 0:EC2\u306b\u63a5\u7d9a\u3059\u308b EC2\u306e\u63a5\u7d9a\u304b\u3089\u4f8b\uff1a\u306e\u90e8\u5206\u3092\u30b3\u30d4\u30fc\u3057\u3066\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u884c\u3046\u3002 ssh -i &#8220;EC2\u306e\u79d8\u5bc6\u9375.pe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[30,27],"tags":[],"class_list":["post-4983","post","type-post","status-publish","format-standard","hentry","category-aws","category-programming-note"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/4983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=4983"}],"version-history":[{"count":15,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/4983\/revisions"}],"predecessor-version":[{"id":5056,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/posts\/4983\/revisions\/5056"}],"wp:attachment":[{"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=4983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=4983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suzutukiblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=4983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}