Triển khai ứng dụng trên Linux Instance

Triển khai ứng dụng trên Linux

  1. Chúng ta sử dụng git để clone source code. Trước hết, cài đặt git bằng lệnh sau:
sudo yum install git

create vpc for linux instance

  1. Kiểm tra cài đặt git thành công bằng lệnh
git version

create vpc for linux instance

  1. Thực hiện clone repository code ứng dụng
cd ~ec2-user 
git clone https://github.com/First-Cloud-Journey/000004-EC2.git

create vpc for linux instance

  1. Đến thư mục của bài lab 000004-EC2 và kiểm tra các file
cd 000004-EC2
ls

create vpc for linux instance

  1. NPM là viết tắt của Node package manager là một công cụ tạo và quản lý các thư viện lập trình Javascript cho Node.js. Sử dụng npm init khởi tạo project sẽ tạo ra file package.json mẫu.
npm init

Bạn tiến hành cấu hình thông tin của ứng dụng và được lưu trong file package.json

create vpc for linux instance

  1. Tiếp theo chúng ta thực hiện dependencies installation
  • express
  • Dotenv
  • express-handlebars
  • body-parser
  • mysql
npm install express dotenv express-handlebars body-parser mysql

create vpc for linux instance

create vpc for linux instance

  1. Kiểm tra các dependencies đã cài đặt. Thư mục node_modules xuất hiện.
ls

create vpc for linux instance

  1. Tạo file .env
touch .env

create vpc for linux instance

  1. Sử dụng vi để chỉnh sửa file .env. Ta thực hiện cấu hình database:
DB_HOST = 'localhost'
DB_NAME = 'DB_NAME'
DB_USER = 'root'
DB_PASS = 'password'

create vpc for linux instance

Trong bài lab chúng ta sử dụng database name là awsuser và thông tin database đã được cấu hình ở bước cấu hình bảo mật database (password: 123Admin)

  1. Kiểm tra cấu hình database
ls -a

create vpc for linux instance

  1. Khởi động lại Express server. Sử dụng Nodemon để tiết kiệm thời gian
npm install --save-dev nodemon

create vpc for linux instance

12.Khởi động local server

npm start

create vpc for linux instance

  1. Trong giao diện EC2
  • Chọn Instances
  • Chọn Linux-instance
  • Sao chép Public IPv4 DNS address

create vpc for linux instance

  1. Dán Public IPv4 DNS address vào trình duyệt và cổng 5000. Quan sát giao diện AWS FCJ Management

create vpc for linux instance

create vpc for linux instance

  1. Trong giao diện phpMyAdmin, chúng ta thực hiện SQL Dummy Data
  • Chọn awsuser database
  • Chọn SQL
  • Dán đoạn code SQL query vào
INSERT INTO `user` 
(`id`, `first_name`,  `last_name`,    `email`,                 `phone`,         `comments`, `status`) VALUES
(NULL, 'Amanda',      'Nunes',        'anunes@ufc.com',        '012345 678910', '',          'active'),
(NULL, 'Alexander',   'Volkanovski',  'avolkanovski@ufc.com',  '012345 678910', '',          'active'),
(NULL, 'Khabib',      'Nurmagomedov', 'knurmagomedov@ufc.com', '012345 678910', '',          'active'),
(NULL, 'Kamaru',      'Usman',        'kusman@ufc.com',        '012345 678910', '',          'active'),
(NULL, 'Israel',      'Adesanya',     'iadesanya@ufc.com',     '012345 678910', '',          'active'),
(NULL, 'Henry',       'Cejudo',       'hcejudo@ufc.com',       '012345 678910', '',          'active'),
(NULL, 'Valentina',   'Shevchenko',   'vshevchenko@ufc.com',   '012345 678910', '',          'active'),
(NULL, 'Tyron',       'Woodley',      'twoodley@ufc.com',      '012345 678910', '',          'active'),
(NULL, 'Rose',        'Namajunas ',   'rnamajunas@ufc.com',    '012345 678910', '',          'active'),
(NULL, 'Tony',        'Ferguson ',    'tferguson@ufc.com',     '012345 678910', '',          'active'),
(NULL, 'Jorge',       'Masvidal ',    'jmasvidal@ufc.com',     '012345 678910', '',          'active'),
(NULL, 'Nate',        'Diaz ',        'ndiaz@ufc.com',         '012345 678910', '',          'active'),
(NULL, 'Conor',       'McGregor ',    'cmcGregor@ufc.com',     '012345 678910', '',          'active'),
(NULL, 'Cris',        'Cyborg ',      'ccyborg@ufc.com',       '012345 678910', '',          'active'),
(NULL, 'Tecia',       'Torres ',      'ttorres@ufc.com',       '012345 678910', '',          'active'),
(NULL, 'Ronda',       'Rousey ',      'rrousey@ufc.com',       '012345 678910', '',          'active'),
(NULL, 'Holly',       'Holm ',        'hholm@ufc.com',         '012345 678910', '',          'active'),
(NULL, 'Joanna',      'Jedrzejczyk ', 'jjedrzejczyk@ufc.com',  '012345 678910', '',          'active')
  • Chọn Format
  • Chọn Go

create vpc for linux instance

create vpc for linux instance

  1. Refresh giao diện ứng dụng

create vpc for linux instance

  1. Xem user

create vpc for linux instance

  1. Chỉnh sửa user

create vpc for linux instance

  1. Thêm user

create vpc for linux instance

  1. Tìm kiếm user

create vpc for linux instance

  1. Database sau khi insert item

create vpc for linux instance

  1. Giao diện của instance khi khởi động local server

create vpc for linux instance