rahul-ecsion / sample

0 stars 0 forks source link

EWM Server SetUp #1

Open rahul-ecsion opened 3 years ago

rahul-ecsion commented 3 years ago
sudo apt-get install
sudo apt-get update
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
rvm use 2.4.10 --default
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.4.10
ruby -v
gem install bundler
gem install rails -v 5.2.6
gem install nokogiri -v 1.10.10
gem install rails -v 5.2.6
gem install sprockets -v 3.7.2
gem install rails -v 5.2.6
rbenv rehash
rails -v
sudo apt update
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
sudo mysql_secure_installation
mysql -u root -p
sudo mysql
sudo service mysql restart
sudo apt-get install curl
sudo apt-get install libcurl
sudo apt-get install curl

https://gorails.com/setup/ubuntu/20.10#ruby-rvm

rahul-ecsion commented 3 years ago

Installing Ruby

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

Using RVM

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.4.10
rvm use 2.4.10 --default
ruby -v
rahul-ecsion commented 3 years ago

The last step is to install Bundler

gem install bundler

rahul-ecsion commented 3 years ago

Configuring Git

git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR@EMAIL.com"
rahul-ecsion commented 3 years ago

Installing Rails gem install rails -v 6.1.3.2

rahul-ecsion commented 3 years ago

Setting Up A Database

Setting Up MySQL You can install MySQL server and client from the packages in the Ubuntu repository. As part of the installation process, you'll set the password for the root user. This information will go into your Rails app's database.yml file in the future.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev Installing the libmysqlclient-dev gives you the necessary files to compile the mysql2 gem which is what Rails will use to connect to MySQL when you setup your Rails app.

rahul-ecsion commented 3 years ago

Took clone from below URLS:

EWM_API_APP:      git clone https://rahulecsion@bitbucket.org/ecsion/ewm_api.git
EWM_REPO_APP:   git clone https://rahulecsion@bitbucket.org/ecsion/ewm_repo.git
EWM_PROJECT_APP:  git clone https://rahulecsion@bitbucket.org/ecsion/ewm_project.git
rahul-ecsion commented 3 years ago

Branc on Server for each repo:

api_ewm: spaces

ewm_repo: master

ewm_project: user_managment

rahul-ecsion commented 3 years ago

Setting up the GIT SSH

AuthorizedKeysCommand:

file: /etc/ssh/sshd_config add below code:

AuthorizedKeysCommand /usr/local/bin/authorized_keys_command.rb root %u %k
AuthorizedKeysCommandUser root

/usr/local/bin/authorized_keys_command.rb

This file must have root:root chown and 0755 chmod

sudo chown root:root /usr/local/bin/authorized_keys_command.rb sudo chmod 0755 /usr/local/bin/authorized_keys_command.rb

#!/usr/bin/env ruby

  require 'rubygems'
  require 'net/http'
  require 'json'

  key        = ARGV[2]
  api_host   = 'http://3.209.118.102:8090'
  url        = "#{api_host}/api/v1/git_hooks/get_user_guid_from_ssh_key?key=#{ARGV[2]}"
  uri        = URI(url)
  response   = Net::HTTP.get(uri)
  response   = JSON.parse(response)
  guid       = response['user_guid']  
  user       = 'ecsion@ampxd-D46A6A046922'
  rsa        = 'ssh-rsa'

  env_string = 'environment="USER_GUID='+"#{guid}"+'"'

  puts "#{env_string} #{rsa} #{key} #{user}"

In the above file change api_host to the current server API HOST URL

rahul-ecsion commented 3 years ago

If any issues faced like below, then need to remove the ec2-instance-connect package from the server.

sudo apt remove ec2-instance-connect

Jun 11 09:19:09 ip-172-31-19-0 sshd[63022]: AuthorizedKeysCommand /usr/share/ec2-instance-connect/eic_run_authorized_keys ubuntu SHA256:Hk34ibfI1B9QaLjI1nLBhefT1FPY/1A/KP9f5YDG+2I failed, status 22
Jun 11 09:19:09 ip-172-31-19-0 sshd[63022]: Connection closed by authenticating user ubuntu 106.67.174.167 port 37975 [preauth]
Jun 11 09:33:01 ip-172-31-19-0 CRON[63055]: pam_unix(cron:session): session opened for user root by (uid=0)
Jun 11 09:33:01 ip-172-31-19-0 CRON[63055]: pam_unix(cron:session): session closed for user root
Timeout, server 35.175.82.213 not responding.
rahul-ecsion commented 3 years ago

add entries to /etc/hosts

54.69.151.55 iam.ecsion.com 44.224.142.1 ecsion.securevault.com