티스토리 뷰

[필요한 것 : 서버(naver cloud centos7.2-mysql5.x 기준), helloworld 띄우는 스프링프로젝트 jar 파일)


[Ncloud 기준 서버생성]

console-> 서버생성 -> mysql-5.7 with centos-7.2-64선택 ->서버타입 아무거나 선택 -> 인증키생성후 선택 ->

기본 acg 선택 -> 포트포워딩 외부포트1024 설정 -> 공인ip 발급후 설정

 

[putty로 서버접속]

ncloud 서버정보의 포트포워딩 정보(서버접속용 공인ip, 외부포트 입력 후 접속)

-> ncloud 해당서버 비밀번호확인(오른쪽 클릭하면 있음) -> 서버접속 후, root/비밀번호 입력

 

[nginx 설치,설정]

1. nginx.repo 파일 생성

# vi /etc/yum.repos.d/nginx.repo

 

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

 

2. nginx 설치

yum install -y nginx

 

 

3. nginx 서비스 시작

systemctl start nginx

systemctl enable nginx

그 외 command

# systemctl status nginx // (상태확인)

# systemctl stop nginx // (종료)

 

[방화벽 설정]

CentOS 7.x 배포판부터는 방화벽 관리 데몬이 firewalld로 설정되어 있다. http https 포트를 열어주려고 한다.

 

$ firewall-cmd --list-all

FirewallD is not running

방화벽 프로그램이 실행되지 않았기 때문에 먼저 실행시켜주자.

 

$ sudo systemctl enable firewalld.service # 부팅시 firewalld 자동 실행하도록 설정

$ sudo systemctl start vsftpd.service # firewalld 실행 (= sudo service firewalld start)

$ firewall-cmd --list-all # 현재 방화벽에 상태 확인

 

나는 ftp, http, https, mysql 포트를 열어야 하므로 다음과 같이 서비스를 추가시킨다.

 

$ sudo firewall-cmd --permanent --add-service=ftp

$ sudo firewall-cmd --permanent --add-service=http

$ sudo firewall-cmd --permanent --add-service=https

$ sudo firewall-cmd --permanent --add-service=mysql

$ sudo firewall-cmd --permanent --zone=public --add-port=80/tcp

$ sudo firewall-cmd --reload          #변경사항을 적용시켜준다.

 

[자바 다운로드]

yum install java

 

[톰캣]

1. 톰캣 다운로드

# wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz

 

2. 압축해제

# tar -xvf apache-tomcat-8.5.15.tar.gz

 

3. 디렉토리 생성 및 이동

# mkdir /usr/local/server

# mv apache-tomcat-8.5.15 /usr/local/server

 

4. 방화벽 설정

# firewall-cmd --permenent --zone=public --add-port=8080/tcp

# firewall-cmd --reaload

 

6. 톰캣 실행

# /usr/loacl/server/apache-tomcat-8.5.15/bin/startup.sh

 종료 : startup.sh shutdown.sh로 변경.

 

7. 접속 확인

웹브라우저에 localhost:8080 입력 시 톰캣페이지 호출됨

 

[nginx, 톰캣연동]

1. Nginx config 수정

 

# vi /etc/nginx/conf.d/tomcat.conf (또는 gedit으로 실행)

tomcat.conf 파일을 새로 생성해주고 default.conf는 백업해둔다.

 

#tomcat.conf

server {

    listen       80;

    location / {

      # 80포트로 접속한 경우 로컬 8080 포트로 넘김

      proxy_pass         http://localhost:8080;

 

      # 넘겨받을 때의 버전을 지정

      proxy_http_version 1.1;

 

      # 넘겨받을 때의 헤더 정보를 지정

      # 호스트 명

      proxy_set_header   Host $host;

      # 클라이언트가 Host 헤더로 넘기는 오리지널 호스트명

      proxy_set_header   X_Forwarded-Host $host;     

      # 프록시 서버의 호스트명

      proxy_set_header   X-Forwarded-Server $host;

      # proxy 서버의 IP가 아닌, 실제 클라이언트이 IP정보

      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

      # proxy 에서 요청할때 사용하는 프로토콜 정보 (http or https)

      proxy_set_header   X-Forwarded-Proto $scheme;

    }

 

    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

파일 생성후

# mv /etc/nginx/conf.d/default.conf default.conf.bk

 

 

 

 

 

 

 

2. nginx.conf 설정(proxy 역할하게끔)

vi /etc/nginx/nginx.conf

글 내용 아랫부분의 *.conf --> tomcat.conf 로 수정

 

3.nginx 재구동, 연동확인

nginx -s stop

systemctl start nginx

lynx localhost:80

--> tomcat 나오면 성공

[스프링 파일 띄우기]

1. 스프링 application.properties 파일 설정

server.port=8081 추가(톰캣8080과 충돌 피하기위해)

 

2. 해당 프로젝트 Run as -> Maven install 설정

-> 해당프로젝트 target 폴더안에 jar파일 생성됨

-> 서버의 /usr/local/server/apache~~/webapps 폴더에 복사

-> java -jar 해당프로젝트명 &(백그라운드로 스프링 jar파일 실행)

-> curl localhost:설정한포트/hello

-> hello world 출력시 성공

 


[도움받은곳]

http://amoogi.azurewebsites.net/

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함