0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

aws nginx、各種パッケージインストール、rubyインストール、mysql (小難しい権限取得とかは省いたよ)

Last updated at Posted at 2019-12-21

基本ベースこちらを参考に進めました。
初心者向け:AWS(EC2)にRailsのWebアプリをデプロイする方法 ②
https://qiita.com/iwaseasahi/items/4666f9a777ba3cf61a05

sshでec2に入り込んでからの作業になります。

~
[~]$ sudo yum update #サーバーのアップデート
[~]$ sudo yum install -y nginx 失敗(amazon linux2だからだと思われる。)(※1)
[~]$ amazon-linux-extras | grep nginx #利用可能なnginxを探す。
nginx1
[~]$ sudo amazon-linux-extras install nginx1  #インストール

[~]$ sudo systemctl start nginx.service   #起動

[~]$ sudo systemctl enable nginx.service  #ngincの自動起動設定

[~]$ systemctl is-enabled nginx.service #自動起動の反映のされているか確認
enable                               #enableと出ればオーケー


[~]$ sudo yum install git make gcc-c++ patch openssl-devel libyaml-devel libffi-devel libicu-devel libxml2 libxslt libxml2-devel libxslt-devel zlib-devel readline-devel ImageMagick ImageMagick-devel epel-release

[~]$ sudo yum install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm


[~]$ sudo yum install nodejs npm --enablerepo=epel  #node.jsのインストールで失敗(※2)
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
Error getting repository data for epel, repository not found          

[~]$ curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
[~]$ sudo yum -y install nodejs

// 確認 バージョンが表示されればOKです~
[~]$ npm -v
[~]$ node -v

rbenvをインストールします。~
[~]$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
[~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
[~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
[~]$ source ~/.bash_profile

ruby-buildをインストールします。~
[~]$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
[~]$ rbenv rehash

ここでは、バージョン2.5.0をインストールします。~
[~]$ rbenv install -v 2.5.0
[~]$ rbenv global 2.5.0
[~]$ rbenv rehash
[~]$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

[~]$ vi ~/.gitconfig
<.gitconfig中身↓↓↓>
---------------------------------
[user]
  name = Githubのユーザー名
  email = Githubに登録しているメールアドレス

[color]
  ui = true

[url "github:"]
  InsteadOf = https://github.com/
  InsteadOf = git@github.com:
------------------------------------
escキー→:wqで保存してviエディタから抜ける

www配下にRailsを格納するフォルダを作成します。
[~]$ cd /
[~]$ cd /var/www/
[~]$ sudo mkdir projects

[~]$ cd
[~]$ chmod 700 .ssh
[~]$ cd .ssh
[.ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ui7bIxjMd7eUn+ahy9CB5LDVI57KBx24vIxWCWDxoZc ec2-user@ip-10-0-10-225.ap-northeast-1.compute.internal
The key's randomart image is:
+---[RSA 2048]----+
|.o..             |
|..o o. .         |
| ..Eo = o        |
|  .o @ = .       |
| o  B * S.       |
|  +=.+.o+.       |
|  o+=.+o.o..     |
| .. oo.+..+.     |
|    .=+.++.      |
+----[SHA256]-----+
[ec2-user .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub
[.ssh]$ vi config
[.ssh]$ cat id_rsa.pub
[.ssh]$ chmod 600 config
[.ssh]$ ssh -T github  #失敗
The authenticity of host 'github.com (52.192.72.89)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.192.72.89' (RSA) to the list of known hosts.
no such identity: /home/ec2-user/.ssh/aws_git_rsa: No such file or directory
Permission denied (publickey).
[ec2-user@ip-10-0-10-225 .ssh]$ ssh -T git@github.com
Hi (account名)! You've successfully authenticated, but GitHub does not provide shell access.

RSDインスタンスにセキュリティグループを設定後の作業
エンドポイントをあらかじめコピーしておく。(RDS→データベース→対象インスタンス選択すると見つかる)
ここでエンドポイントを使用します。
$ mysql -h エンドポイント -P 3306 -u root -p
例
$ mysql -h christchurches-map-mysql.cbev6lgaewnk.ap-northeast-1.rds.amazonaws.com -P 3306 -u root -p
パスワードを入力します。
Enter password:
RDSにアクセスできました。(※出来ない場合タイポ、パス間違え(※3)、アクセス権限間違えが原因かも)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 75
Server version: 5.6.27-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
データベースを確認します。
mysql> show databases;
+-------------------------------+
| Database                      |
+-------------------------------+
| information_schema            |
| christchurches_map_production |
| innodb                        |
| mysql                         |
| performance_schema            |
| sys                           |
+-------------------------------+
6 rows in set (0.00 sec)
退出します。
$ exit;


[ec2-user@ip-10-0-10-225 ~]$ cd /
[ec2-user@ip-10-0-10-225 /]$ mkdir var
[ec2-user@ip-10-0-10-225 /]$ sudo chown ec2-user var
[ec2-user@ip-10-0-10-225 /]$ cd var
[ec2-user@ip-10-0-10-225 var]$ mkdir www
[ec2-user@ip-10-0-10-225 var]$ sudo chown ec2-user www
[ec2-user@ip-10-0-10-225 var]$ cd www
[ec2-user@ip-10-0-10-225 www]$ mkdir projects
[ec2-user@ip-10-0-10-225 www]$ sudo chown ec2-user projects
[ec2-user@ip-10-0-10-225 www]$ git clone git@github.com:KoyoIshikawa/memos.git
[ec2-user@ip-10-0-10-225 projects]$ git clone git@github.com:KoyoIshikawa/memos.git
Cloning into 'memos'...
remote: Enumerating objects: 183, done.
remote: Counting objects: 100% (183/183), done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 183 (delta 56), reused 151 (delta 30), pack-reused 0
Receiving objects: 100% (183/183), 32.63 KiB | 4.66 MiB/s, done.
Resolving deltas: 100% (56/56), done.



[ec2-user@ip-10-0-10-225 memos]$ gem install bundler
Successfully installed bundler-2.1.2
Parsing documentation for bundler-2.1.2
Done installing documentation for bundler after 3 seconds
1 gem installed
[ec2-user@ip-10-0-10-225 memos]$ bundler -v
Traceback (most recent call last):
	2: from /home/ec2-user/.rbenv/versions/2.5.0/bin/bundler:23:in `<main>'
	1: from /home/ec2-user/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/ec2-user/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)
[ec2-user@ip-10-0-10-225 memos]$ vim Gemfile.lock

<Gemfile.lockの中身>
--------------------------------------------------------------------------------------------
BUNDLED WITH
   2.1.2   ※cloneしたアプリとec2のbundlerのversionを合わせる。
--------------------------------------------------------------------------------------------
[ec2-user@ip-10-0-10-225 memos]$ bundle exec rake secret
a3883c3f5042ba9683db5090839416ac7291e1e67f165cc7dbc8312999eda68d0f5fed1f13fce63563398540a3b9456beeb8d6dcb35b38dacc8877ab86f997dd

シークレットを表示します。
$ bundle exec rake secret
数字が表示
設定ファイルに記載します。
$ vi config/secrets.yml
production:
  secret_key_base: ここにsecretを貼り付ける





(※1)Amazon Linux2にnginxをinstallするメモ
https://qiita.com/takayuki_tk/items/aa8e1898743458cebd45
(※2)EC2にRDSの為のmysqlコマンドのみをインストールする
https://joppot.info/2017/04/28/3877
(※3)Amazon RDS DB インスタンスのマスターユーザーパスワードをリセットするにはどうすればよいですか?
https://aws.amazon.com/jp/premiumsupport/knowledge-center/reset-master-user-password-rds/
(※4)[エラーメッセージ] can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)
https://qiita.com/MotohiroSiobara/items/c0d343a160cffc2902ef

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?