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


CentOS에 Java 설치하기

|

Install Java on CentOS

설치 가능 버전 확인

yum list java*jdk-devel 명령으로 현재 설치 가능한 Java 패키지 버전을 확인합니다.

$ yum list java*jdk-devel

Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/4): extras/7/x86_64/primary_db                          | 166 kB   00:00
(2/4): base/7/x86_64/group_gz                              | 156 kB   00:00
(3/4): updates/7/x86_64/primary_db                         | 6.0 MB   00:00
(4/4): base/7/x86_64/primary_db                                                             | 5.7 MB  00:00:05
Determining fastest mirrors
 * base: ftp.daumkakao.com
 * extras: ftp.daumkakao.com
 * updates: ftp.daumkakao.com
Available Packages
java-1.6.0-openjdk-devel.x86_64                         1:1.6.0.41-1.13.13.1.el7_3                          base
java-1.7.0-openjdk-devel.x86_64                         1:1.7.0.171-2.6.13.0.el7_4                          updates
java-1.8.0-openjdk-devel.i686                           1:1.8.0.161-0.b14.el7_4                             updates
java-1.8.0-openjdk-devel.x86_64                         1:1.8.0.161-0.b14.el7_4                             updates


설치

위에서 확인한 패키지 명을 보고 설치를 원하는 Java 패키지를 선택합니다.

sudo yum install -y java-1.8.0-openjdk-devel.x86_64


확인

$ java -version

openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

Docker Architecture

|

Docker Architecture

Image

Docker 구조는 위 그림과 같습니다.

가운데의 도커 호스트(Docker Host)안에 도커 데몬(Docker Daemon)이 존재하며 컨테이너의 생성, 실행, 모니터링 및 이미지 관리 등의 역할을 합니다.

도커 클라이언트(Docker Client)는 도커 데몬에게 명령을 내릴 수 있는 인터페이스 역할을 하며, 도커 데몬과는 HTTP 통신을 합니다. 기본적으로 유닉스 도메인 소켓(Unix Domain Socket)을 통해 통신을 하지만, 원격 클라이언트 또는 systemd가 관리하는 소켓의 파일 디스크립터(File Descriptor)를 통해 TCP 통신을 하기도 합니다.

도커 레지스트리(Docker Registry)는 이미지들을 저장하고 배포하는 역할을 합니다. 보통 도커 허브(Docker Hub)를 통해 이미지를 배포하며 독자적인 사설 레지스트리를 생성해서 운영할 수도 있습니다.