[Rails] AWS EC2 instance environment construction

This time, we will build an environment for launching applications in AWS EC2 instances.

Prerequisites

You can log in to your EC2 instance by making an SSH connection between your computer and your EC2 instance.

Install tools for configuration

First, use the command yum to update the original program on this server. Such a program is called a package.

yum command

It is a software management mechanism in Linux. It plays the same role as Homebrew for MacOS. By using the yum command, you can manage the versions of programs under the control of yum and update them in a batch.

package

A set of programs with a certain role / function under LinuxOS. It can be called software or library. In Linux OS, a set of programs with a certain role / function is called a package.

Package update

We will carry it out in the production environment.

[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y update

Install various other packages required for environment construction.

[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install git make gcc-c++ patch libyaml-devel libffi-devel libicu-devel zlib-devel readline-devel libxml2-devel libxslt-devel ImageMagick ImageMagick-devel openssl-devel libcurl libcurl-devel curl

The -y command is a command that sets all questions to be answered automatically with Yes.

Install Node.js

Next, install Node.js to run JavaScript on EC2.

[ec2-user@ip-172-31-25-189 ~]$ sudo curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash -
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install nodejs

Node.js A JavaScript package that runs on the server side. It will be used when compressing CSS and images in the work for future deployment.

Install rbenv and ruby-build

I used it when building the Mac environment, but I will explain it briefly again. rbenv and ruby-build are tools that are used in combination when managing Ruby versions. These need to be installed before installing Ruby. ruby-build is a plugin for rbenv that allows you to install different versions of Ruby (such as 2.0.0) with ruby-build. You can switch the ruby version by using rbenv.

#Install rbenv
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv 
#Pass through
[ec2-user@ip-172-31-25-189 ~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile 
#Description for calling rbenv
[ec2-user@ip-172-31-25-189 ~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
#.bash_Load profile
[ec2-user@ip-172-31-25-189 ~]$ source .bash_profile
#ruby-install build
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
#Do rehash
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash

The second and third commands are the commands you need to pass through the path. Passing the path means making the application callable from any directory. Then, with the fourth command, the set path is read. The last command is the command you need to be able to use gem commands in your version of Ruby.

Install Ruby

Please change the command group to be executed below according to the version of Ruby to be installed and the version of Ruby used in your application.

#Ruby 2.5.Install version 1
[ec2-user@ip-172-31-25-189 ~]$ rbenv install 2.5.1
#Decide which version of Ruby to use within your EC2 instance
[ec2-user@ip-172-31-25-189 ~]$ rbenv global 2.5.1
#Do rehash
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash
[ec2-user@ip-172-31-25-189 ~]$ ruby -v

MySQL settings

This time, we will use MySQL, which is a typical RDBMS (relational database management system). The image of the system configuration this time is as follows. スクリーンショット 2020-06-06 22.27.24.png

MySQL An RDBMS developed and provided by Oracle. You can create, edit, delete, etc. the database. It is released as open source software and anyone can use it free of charge.

MySQL installation

If you are using Amazon Linux, you can install MySQL from the yum command. This time I will install MySQL version 5.6.

[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install mysql56-server mysql56-devel mysql56

Start MySQL

Use the service command to start MySQL. This is included in Amazon Linux and CentOS, and is a tool that allows you to start the installed software all at once.

[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld start

The d in mysqld is an acronym for "daemon" which means "server" in Linux terms.

You can check if it can be started with the following.

[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld status
mysqld (pid  15692) is running...

Setting a MySQL root password

By default, MySQL installed with yum can be accessed by the user root, but no password is set.

Therefore, let's set a password with the following command. For the part of'password you want to set', for example, if you set the character string password0000, write'password0000'. Avoid passwords that start with 0, as they often do not read. (For example, '0331higuchi')

[ec2-user@ip-172-31-25-189 ~]$ sudo /usr/libexec/mysql56/mysqladmin -u root password 'Please change this to the password you want to set and then execute the command.'

How to connect to MySQL

[ec2-user@ip-172-31-25-189 ~]$ mysql -u root -p

After entering the above command, you will be prompted to enter the password you set earlier, so you can connect by entering it.

The settings of the Web server and Application server for publishing the application will be described in the next article.

Recommended Posts

[Rails] AWS EC2 instance environment construction
Rails Docker environment construction
How to publish an application using AWS (3) EC2 instance environment construction
Rails engineer environment construction ruby2.7.1
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
[Docker] Rails 5.2 environment construction with docker
[Rails / MySQL] Mac environment construction
Rails + MySQL environment construction with Docker
Ruby on Rails 6.0 environment construction memo
Rails on Docker environment construction procedure
[Environment construction with Docker] Rails 6 & MySQL 8
Troublesome Rails environment construction flow [Windows 10]
[Environment construction] Uninstall rails from local
Deployed using Docker + Rails + AWS (EC2 + RDS)
Easy deployment with Capistrano + AWS (EC2) + Rails
Rails API server environment construction using docker-compose
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
[Rails] Image posting by CarrierWave [AWS EC2]
[Note] Update to production environment (AWS EC2)
Rails & React & Webpacker & MySQL Environment Construction Manual
Muscle Ruby on Rails Day 1 ~ Environment Construction ~
CentOS8.2 (x86_64) + ruby2.5 + Rails5.2 + MariaDB (10.3.17) environment construction
Java environment construction
[Spring] Environment construction
Docker environment construction
How to link Rails6 Vue (from environment construction)
Environment construction command memo with Docker on AWS
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Error installing ruby execution environment on EC2 instance
Build a Laravel environment on an AWS instance
Ruby on Rails development environment construction on M1 Mac
Penronse environment construction [Windows]
Install docker-compose on a Graviton 2 instance of AWS EC2
How to install Ruby on an EC2 instance on AWS
Memo to build a Servlet environment on AWS EC2
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
[Flutter] Ubuntu 20.04 environment construction
Launch Rails on EC2
Build a Ruby on Rails development environment on AWS Cloud9
virtulbox + vagrant + Docker + nginx + puma + MySQL Rails environment construction
Deploy laravel using docker on EC2 on AWS ① (Create EC2 instance)
Stable development environment construction manual for "Rails6" with "Docker-compose"
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
Deploy RAILS on EC2
Circle CI environment construction
[Environment construction Mac] Ruby on Rails (+ Webpacker handles errors)
java development environment construction
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
From 0 to Ruby on Rails environment construction [macOS] (From Homebrew installation to Rails installation)
[AWS] Link memory usage of Ubuntu EC2 instance to CloudWatch
How to create an application server on an EC2 instance on AWS
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
[CCNA] Construction of Cisco device emulator environment (EC2 + Ubuntu + GNS3)
I tried automatic deployment with CircleCI + Capistrano + AWS (EC2) + Rails
For beginners! Automatic deployment with Rails6 + CircleCI + Capistrano + AWS (EC2)
[Spring Boot] Environment construction (macOS)
EC-CUBE4 environment construction (local edition)
I tried node-jt400 (Environment construction)
Rails6 (MySQL, Ubuntu environment, Cloud9)
MySQL 5.7 (Docker) environment construction memo