Error when building infrastructure with aws app

This time, referring to this article, I tried to build an infrastructure using AWS with the rails app I created for the first time. https://qiita.com/naoki_mochizuki/items/814e0979217b1a25aa3e

EC2 instance environment construction

$git make gcc-c++ patch git: 'make' is not a git command. See 'git --help'. The most similar commands are blame, merge, stage

I got the error. This had to be uncommented and run as a one-line command. $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 mysql mysql-server mysql-devel ImageMagick ImageMagick-devel epel-release

$sudo mkdir www mkdir: unable to create directory `www': File exists I got the error. It seems that it already exists, but I don't remember creating it ... I was wondering whether to use it as it is, but I created a file with another name (XYZ) and used it instead.

Cooperation with git, clone of application

$cat aws_git_rsa.pub cat: aws_git_rsa.pub: No such file or directory

This was because when I created the public key, the operation was different from normal command input, so I added a half-width space behind: aws_git_rsa. (General mistake ...) $ ssh-keygen -t rsa

Enter file in which to save the key (): aws_git_rsa (half-width space in this part) When I recreated the key, I was able to successfully reveal the contents of the public key.

MySQL settings

When I try to start Mysql, I get the following error $ sudo service mysqld start #start mysqld Redirecting to /bin/systemctl start mysqld.service Failed to start mysqld.service: Unit not found. I ran the following command with reference to the following article and it worked. https://qiita.com/yuta-38/items/4074f5ada9e22088c8dd $ sudo yum install -y mariadb-server $ sudo systemctl enable mariadb $ sudo service mariadb start

Also, on Amazon Linux 2, it seems that when you try to install mysql with yum, it tries to install mariaDB. I didn't practice it, but the following articles may be helpful. https://qiita.com/hamham/items/fd77bb0bb167a150dc8e#mysql57%E3%81%AE%E5%B0%8E%E5%85%A5

Start Nginx

I entered the following command, but Nginx does not start. $ sudo service nginx start Redirecting to /bin/systemctl start nginx.service Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

Execute the following command as instructed by the error $ systemctl status nginx.service nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since month 2020-07-13 09:10:04 UTC; 57s ago Process: 11360 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE) Process: 11356 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 11355 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

I didn't know the cause, so I also executed the following. $sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

There seemed to be no problem with the config file, so I was in trouble. I found the following command while researching various things. $ sudo service nginx status -l Redirecting to /bin/systemctl status -l nginx.service ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since month 2020-07-13 09:10:04 UTC; 27min ago Process: 11360 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE) Process: 11356 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 11355 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) July 13 09:10:02 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] bind () to [::]: 80 failed (98) : Address already in use) July 13 09:10:03 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] bind () to 0.0.0.0:80 failed (98: Address already in use) July 13 09:10:03 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] bind () to [::]: 80 failed (98) : Address already in use) July 13 09:10:03 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] bind () to 0.0.0.0:80 failed (98: Address already in use) July 13 09:10:03 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] bind () to [::]: 80 failed (98) : Address already in use) July 13 09:10:04 ip-10-0-10-10.ap-northeast-1.compute.internal nginx [11360]: nginx: [emerg] still could not bind () July 13 09:10:04 ip-10-0-10-10.ap-northeast-1.compute.internal systemd [1]: nginx.service: control process exited, code = exited status = 1 July 13 09:10:04 ip-10-0-10-10.ap-northeast-1.compute.internal systemd [1]: Failed to start The nginx HTTP and reverse proxy server. July 13 09:10:04 ip-10-0-10-10.ap-northeast-1.compute.internal systemd [1]: Unit nginx.service entered failed state. July 13 09:10:04 ip-10-0-10-10.ap-northeast-1.compute.internal systemd [1]: nginx.service failed.

According to the above, it seems that the set port 80 is already running. As a result of considering the cause, I remembered that I had installed Apache and set automatic startup in a certain web course before. $ sudo systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since day 2020-07-12 06:24:44 UTC; 2 days ago Docs: man:httpd.service(8) Main PID: 21760 (httpd) Status: "Total requests: 149; Idle/Busy workers 100/0;Requests/sec: 0.00084; Bytes served/sec: 2 B/sec" CGroup: /system.slice/httpd.service ├─20766 /usr/sbin/httpd -DFOREGROUND ├─21049 /usr/sbin/httpd -DFOREGROUND ├─21055 /usr/sbin/httpd -DFOREGROUND ├─21056 /usr/sbin/httpd -DFOREGROUND ├─21760 /usr/sbin/httpd -DFOREGROUND ├─21761 /usr/sbin/httpd -DFOREGROUND ├─21762 /usr/sbin/httpd -DFOREGROUND ├─21763 /usr/sbin/httpd -DFOREGROUND ├─21764 /usr/sbin/httpd -DFOREGROUND ├─21765 /usr/sbin/httpd -DFOREGROUND └─21887 /usr/sbin/httpd -DFOREGROUND Sure enough Apache was already working. After disabling & stopping the automatic start, I executed the start command of NginX and it was able to start safely.

I finished the final settings, but the following was displayed on the web page.

「We're sorry, but something went wrong. If you are the application owner check the logs for more information.」

For the time being, look at the error logs of Unicorn and Nginx. (Reference article Each setting has a description of the path to the error) $ tail -f /var/xyz/rails/circle_app/log/unicorn.log I, [2020-07-14T08:37:26.186843 #19212] INFO -- : listening on addr=/var/xyz/rails/circle_app/tmp/sockets/.unicorn.sock fd=9 I, [2020-07-14T08:37:26.203171 #19212] INFO -- : master process ready I, [2020-07-14T08:37:26.207382 #19214] INFO -- : worker=0 ready I, [2020-07-14T08:37:26.207617 #19215] INFO -- : worker=1 ready Unicorn doesn't seem to be a problem.

$ tail -f /var/xyz/rails/circle_app/log/nginx.error.log 2020/07/14 08:36:17 [crit] 19174#0: *1 connect() to unix:/var/xyz/rails/circle_app/tmp/sockets/.unicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 103.5.140.158, server: 46.51.239.151, request: "GET / HTTP/1.1", upstream: "http://unix:/var/xyz/rails/circle_app/tmp/sockets/.unicorn.sock:/", host: "46.51.239.151"

There seems to be a problem with Nginx. As you can see in the next article, it seems that you have to change the way to write the path from CentOS 7. https://qiita.com/emahiro/items/b2762a26bca35bbb0cf9

I changed the Unicorn and Nginx files by referring to the following article. https://qiita.com/noraworld/items/c8acf4bb981c8d8535df Also check the Unicorn running with the following command and stop it with the kill command $ ps aux | grep unicorn $ kill -9 pid ← Substitute the number displayed by the above command for the pid part Rebooted with the following command $ unicorn_rails -c / var / www / rails / (app name) /config/unicorn.conf.rb -D -E production After doing all the above, when I reloaded the web page, it was displayed safely! !! !!

The following courses I purchased at Udemy before building the infrastructure worked and I was able to understand at a good tempo. https://www.udemy.com/course/aws-and-infra/

Recommended Posts

Error when building infrastructure with aws app
Error when playing with java
[AWS] Publish rails app with nginx + puma
[Rails] Error resolution when generating tokens with PAYJP
error code 400 appears when deploying with release: perform
Error when starting JUnit with deprecated version of POI
Workaround for Bundler.require error when executing ruby with crontab
[Heroku] Associate AWS S3 with the deployed Rails app
When I bcrypt with node + docker, I got an error
Error when using SnapKit
A story stuck with an error when building Vagrant + Virtulbox CentOS7.8 and creating a shared folder
Error when bundle install
Error when deploying EC2
Rough procedure verbalized output when creating an app with Rails
Summary of initial work when creating an app with Rails
How to specify db when creating an app with rails
Specify the character code of the source when building with Maven
Gcc error solution with "pip install annoy" on AWS EC2
Measures for permissions when building MySQL with Docker on WSL2