Server Deploy
1.EC 2インスタンスの作成/接続
$ chmod 400 키페어파일명
2.EC 2インスタンスでのサーバの実行
2.1インスタンスでの開発環境の構築
$ sudo apt update
// nvm install
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
$ nano ~/.bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This load$
アプリケーション
$ source ~/.bash_profile
// 잘 설치되었는지 nvm 버전확인
$ nvm --version
$ nvm install node
$ sudo apt install npm
// git에 있는 코드 클론받기 위해 git 설정
$ git config --global user.name "깃헙유저명"
$ git config --global user.email "깃헙이메일"
// keygen 생성하고 암호설정. 깃헙사이트에다 ssh키를 추가해준다
$ git clone 깃헙코드경로
// 위와 같이 깃헙 설정 잡아주고 클론해야 아무 문제없이 가져온다
// 해당 서버폴더로 이동 후 서버구동
$ cd im-sprint-pratice-deploy/server && npm start
// 1024번 포트 아래론 관리자 권한으로 실행해야 하기에
$ sudo npm start
2.2セキュリティグループの設定
セキュリティ・グループは、
2.3 PM2
node app.js &
$ npm install pm2 -g
// 백그라운드 실행
$ pm2 start 파일명
$ sudo apt-get update
$ sudo apt-get install authbind
$ sudo touch /etc/authbind/byport/80
$ sudo chown ubuntu /etc/authbind/byport/80
$ sudo chmod 755 /etc/authbind/byport/80
$ authbind --deep pm2 update
$ pm2 delete app.js
$ authbind --deep pm2 start app.js
3. app.jsバックグラウンド実行時エラー
ubuntu@ip-172-31-14-21:~/im-sprint-practice-deploy/server$ node app.js &
[2] 24950
ubuntu@ip-172-31-14-21:~/im-sprint-practice-deploy/server$ node:events:371
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (node:net:1302:21)
at listenInCluster (node:net:1367:12)
at Server.listen (node:net:1454:7)
at Function.listen (/home/ubuntu/im-sprint-practice-deploy/server/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/ubuntu/im-sprint-practice-deploy/server/app.js:49:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1346:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 80
}
$sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
4.特定のポートを特定したい場合
$sudo lsof -i :포트번호
$sudo kill -9 해당포트PID
Reference
この問題について(Server Deploy), 我々は、より多くの情報をここで見つけました https://velog.io/@dev_shu/Server-Deployテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol