CentOS에 Maven 설치하기

|

Install Maven on CentOS

Maven을 설치하기 전에 먼저 Java가 설치되어 있어야 합니다.


Maven 다운로드

Maven 다운로드는 여기에서 할 수 있습니다.

$ wget http://apache.tt.co.kr/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz


압축해제 및 파일 이동, 링크 생성

tar -xvzf apache-maven-3.5.2-bin.tar.gz
sudo mv apache-maven-3.5.2 /usr/local/maven
sudo ln -s /usr/local/maven/bin/mvn /usr/bin/mvn


환경 변수 추가

sudo su
cat< /etc/profile.d/maven.sh
#!/bin/bash 
MAVEN_HOME=/srv/maven 
PATH=$MAVEN_HOME/bin:$PATH 
export PATH MAVEN_HOME 
export CLASSPATH=.
EOF
exit
</pre>


## 설치 확인
mvn -version

Visual Studio Code를 이용해서 AWS의 EC2 인스턴스내 파일 수정하기

|

Visual Studio Code와 AWS EC2 인스턴스와 연결

Visual Studio Code(이하 vscode)를 이용해서 AWS의 EC2 인스턴스내의 파일을 수정하는 방법입니다. 사실 WinSCP를 사용해도 되고 다양한 방법들이 있지만 여기서는 간단하게 vscode를 이용해서 접근하는 방법을 소개합니다.


ftp-simple 설치

먼저 vscode 마켓에서 ftp-simple를 설치합니다.


ftp-simple 설정

설치를 한다음 ‘다시로드(Reload)’를 한 번 해주고, F1 키를 눌러서 ftp-simple : Config을 검색합니다.

image

그러면 아래와 같은 템플릿이 뜨는데,

[
	{
		"name": "localhost",
		"host": "",
		"port": 21,
		"type": "ftp",
		"username": "",
		"password": "",
		"path": "/",
		"autosave": true,
		"confirm": true
	}
]

여기에 서버 접속 정보를 작성하면 됩니다. 예를 들어 저는 다음과 같이 작성했습니다.

[
	{
		"name": "AWS 개발 서버",
		"host": "111.222.333.444",
		"port": 22,
		"type": "sftp",
		"username": "centos",
		"path": "/",
		"autosave": true,
		"confirm": true
        "privateKeyPath": "D:\\aws-key\\snowdeerAWS.pem"
	}
]


접속 확인

이제 F1 키를 눌러서 ftp-simple : Remote directory open to workspace를 선택합니다.

image

그러면 위와같이 조금 전에 작성한 접속 설정 리스트가 뜨고, 원하는 항목을 선택해서 접속합니다. 그 이후 접속할 디렉토리를 지정해주면 해당 디렉토리 내부의 파일들을 vscode를 이용해서 수정할 수 있게 됩니다.

CentOS에 Python 3.x 설치하는 방법

|

CentOS에 Python 3.x 설치

Repository를 yum에 추가

$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm


yum search로 python 3.x 버전 확인

아래 명령어를 수행하면 python3으로 시작하는 라이브러리들을 확인할 수 있습니다.

$ yum search python3

</pre>

필요 라이브러리들 설치

$ sudo yum install -y python36u python36u-libs python36u-devel python36u-pip


Python 설치 및 버전 확인

$ python -V
Python 2.7.5

$ python3.6 -V
Python 3.6.4

기본적으로 python 명령어는 Python 2.x를 가리키고 있기 때문에 Alias 수정으로 이를 변경해줍니다.


Alias 수정

먼저 Python 3.x가 설치되어 있는 디렉토리 위치를 찾습니다.

 $ which python3.6
 /usr/bin/python3.6
 

그 다음 현재 Alias 확인을 합니다.

$ ls -l /bin/python*

Alias 수정을 합니다.

$ sudo unlink /bin/python

$ sudo ln -s /bin/python3.6 /bin/python3

$ sudo ln -s /bin/python3.6 /bin/python

$ sudo ln -s /bin/pip3.6 /bin/pip

Simple Web Server

|

Simple Web Server

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class SimpleWebServer {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello. Simple Web Server.");

        HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
        server.createContext("/", indexHandler);
        server.createContext("/test", mHandler);
        server.setExecutor(null);
        server.start();
    }

    private static HttpHandler indexHandler = new HttpHandler() {

        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            byte[] response = "This is an index page.".getBytes();
            httpExchange.sendResponseHeaders(200, response.length);
            OutputStream os = httpExchange.getResponseBody();
            os.write(response);
            os.close();
        }
    };

    private static HttpHandler mHandler = new HttpHandler() {

        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            byte[] response = "This is a test page.".getBytes();
            httpExchange.sendResponseHeaders(200, response.length);
            OutputStream os = httpExchange.getResponseBody();
            os.write(response);
            os.close();
        }
    };
}

Dockerfile for Python

|

Dockerfile for Python

Python 용 어플리케이션을 위한 Dockerfile 템플릿입니다.


Dockerfile

Python 3.x 버전의 경우는

FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./your-daemon-or-script.py" ]

와 같으며,


Python 2.x 버전에서는 다음과 같이 작성합니다.

FROM python:2

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./your-daemon-or-script.py" ]


requirements.txt

flask