-
Notifications
You must be signed in to change notification settings - Fork 6
nodejs mysql aws ec2 aws rds
egoing edited this page Nov 19, 2021
·
10 revisions
- github.com ๊ฐ์
- git : https://git-scm.com/
- visual studio code : https://code.visualstudio.com/
simple.js
var http = require('http');
var app = http.createServer(function(request,response){
response.end(`
<h1><a href="index.html">WEB</a></h1>
<ul>
<li><a href="html.html">html</a></li>
<li><a href="nodejs.html">nodejs</a></li>
<li><a href="mysql.html">mysql</a></li>
</ul>
<h2>Welcome</h2>
Hello WEB!!
`);
});
app.listen(80);node simple.js
npm install --global pm2pm2 simple.js --watch --no-daemonpm2 statuspm2 delete PROCESS_ID
-
git init -
git add simple.js && git commit -m "simple.js"
git push -u origin master
- os : ubuntu 20
- instance type : micro
- security group : 22, 80, 3000 port ๊ฐ๋ฐฉ
- key-pair๋ฅผ ์์ฑํ๊ณ ๋ค์ด๋ก๋ ๋ฐ์ต๋๋ค.
- ssh -i KEY_PAIR_NAME.pem ubuntu@PUBLIC_IP_ADDRESS
ssh-keygen-
cat ~/.ssh/id.rsa.pub๋ก ํ์ผ์ ๋ด์ฉ์ ๋ณต์ฌํด์ github.com > settings > SSH ์ ๋ฑ๋กํฉ๋๋ค. -
git clone RPOSITORY_URL .์ ์ฅ์๋ฅผ ๋ณต์ ํฉ๋๋ค.
- sudo apt update && sudo apt install -y nodejs
sudo node simple.js
- sudo apt update && sudo apt install npm -y
npm install --global pm2pm2 start simple.js
- ์์ฑ๋ฐฉ์ : ์์ฌ์ด ์์ฑ
- ๊ตฌ์ฑ : MySQL
- ์ธ์คํด์ค ํฌ๊ธฐ : ํ๋ฆฌํฐ์ด
- ๋ง์คํฐ ์ฌ์ฉ์ ์ด๋ฆ : admin
- ๋ง์คํฐ ์ํธ : 111111
- db ์ธ์คํด์ค์ VPC ๋ณด์๊ทธ๋ฃน์ ํด๋ฆญํฉ๋๋ค.
- ์ธ๋ฐ์ด๋ ํธ์ง์ ์ ํํฉ๋๋ค.
- ์ ํ์ MySQL์ ์ ํํฉ๋๋ค. ์์ค์ EC2์ ๋ณด์๊ทธ๋ฃน์ ์ด๋ฆ์ ์ ๋ ฅํฉ๋๋ค.
- sudo apt update && sudo apt install mysql-client -y
- mysql -hHOST_NAME -uadmin -p
- create database myapp;
- use myapp;
--
-- Table structure for table `author`
--
CREATE TABLE `author` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`profile` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
);
--
-- Dumping data for table `author`
--
INSERT INTO `author` VALUES (1,'egoing','developer');
INSERT INTO `author` VALUES (2,'duru','database administrator');
INSERT INTO `author` VALUES (3,'taeho','data scientist, developer');
--
-- Table structure for table `topic`
--
CREATE TABLE `topic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`description` text,
`created` datetime NOT NULL,
`author_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
--
-- Dumping data for table `topic`
--
INSERT INTO `topic` VALUES (1,'MySQL','MySQL is...','2018-01-01 12:10:11',1);
INSERT INTO `topic` VALUES (2,'Oracle','Oracle is ...','2018-01-03 13:01:10',1);
INSERT INTO `topic` VALUES (3,'SQL Server','SQL Server is ...','2018-01-20 11:01:10',2);
INSERT INTO `topic` VALUES (4,'PostgreSQL','PostgreSQL is ...','2018-01-23 01:03:03',3);
INSERT INTO `topic` VALUES (5,'MongoDB','MongoDB is ...','2018-01-30 12:31:03',1);mysql 8.0 ์ด์ ๋ฒ์ ์ ์ฌ์ฉํ๋ค๋ฉด ์๋ ๋ช ๋ น์ผ๋ก ์ธ์ฆ๋ฐฉ์์ ๋ณ๊ฒฝํด์ค์ผ ํฉ๋๋ค.
- ALTER USER 'USER_ID'@'%' IDENTIFIED WITH mysql_native_password BY 'PASSWORD'; ์ฐธ๊ณ : https://kogle.tistory.com/87
- git clone https://github.com/web-n/node.js-mysql.git
- cd node.js-mysql
- cd lib
- cp db.template.js db.js
- nano db.js
- host, user, password, database๋ฅผ ๋ณ๊ฒฝํฉ๋๋ค.
- cd ..
- npm install ๋ก ์์กด์ฑ์ ์ค์นํฉ๋๋ค.
pm2 main.js
http://PUBLIC_DNS_URL:3000
-
sudo crontab -e์์ ์๋ ๋ด์ฉ์ ์ถ๊ฐ @reboot sudo pm2 start /home/ubuntu/nodejs-aws/3.js