반응형

 

최근에 파이썬에 대한 관심이 증가 하면서 여러 분야에서 사용이 되고 있다.

다양한 분야중에 웹 크롤러도 주목을 받고 있다.

나도 관심을 갖고는 있었지만 그저 막연하게만 생각하고 있었다. 어떤 방법들이 있는지, 무엇을 먼저 해야 하는지 모르고 있었다.

그런 의미에서 이 책은 웹 크롤러에 대해서 기초부터 고급까지 차근차근 알아 볼수 있는 책이다.

 

읽으면서 몇가지 필요한 것들에 대해서 생각해 보았다.

 

1. 파이썬에 대한 기초적인 문법들은 알고 있어야 코드를 이해할 수 있다.

2. 웹 에 대해서도 기초적인 코드는 알고 있어야 한다. (html, javascript등)

3. 정규 표현식도 알고 있으면 도움이 된다.

4. 크롤러 라는건 생각보다 간단하지 않다. 인내력이 필요하다. 데이터 분석과 거의 동일한 작업이라는 생각이 든다.

 

그리고 책 마지막 부분에 있듯이 크롤러라는 것이 다른 웹 페이지에 있는 내용들을 수집하는 기술 이기 때문에 저작권 문제가 생길 수 있다. 정기적으로 크롤링 하는 것에 대해서는 반드시 원작자에 허락을 받아야 한다.

 

파이썬으로 웹 크롤러를 만들어 보려고 하는 분들이 많을 거라 생각이 든다. 이책은 그 분들에게 많은 도움이 될것이다.

 "한빛미디어 <나는 리뷰어다> 활동을 위해서 책을 제공받아 작성된 서평입니다."

728x90
반응형
반응형

인용

> 인용문입니다.

인용문입니다.

인용문이 여러 줄일 경우 (라인 끝에 스페이스2개 넣어야 한다)

> 인용문1  
인용문2  
인용문3

인용문1
인용문2
인용문3

728x90
반응형
반응형

1. icarusn 모듈 설치

먼저 로컬에 있는 blog 소스가 있는 폴더 안에서 git submodule 을 추가해준다.

내가 설치하려고 하는 테마는 icarus 라는 테마인데 설치 방법은 여러가지가 있다.

Document를 보니 git submodule 을 추가하는 방법도 있고 npm 으로 설치하는방법도 있다.

 

git submodule add https://github.com/ppoffice/hexo-theme-icarus.git themes/icarus

 

이렇게 하면 blog 하위에 themes 폴더 안에 icarus 라는 항목이 생긴다.

 

또는

 

npm install -S hexo-theme-icarus

 

나는 submodule 을 추가 하는 방법을 사용했다.

 

2. 설정파일 변경

_config.yml 파일을 수정해준다.

 

theme: icarus

 

3. 반영 확인

설치 완료 후 hexo server 명령어를 통해서 로컬에서 기동 시켜보면 테마가 변경 된 것을 확인 할 수 있다.

 

4. 에러 발생시?

혹시라도 아래와 같이 dependencies 에러가 난다면 에러난 항목들을 설치해 주면 된다.

아래 bold 처리한 부분을 설치해 주면 된다.

 

INFO  === Checking package dependencies ===
ERROR Package bulma-stylus is not installed.
ERROR Package hexo-renderer-inferno is not installed.
ERROR Package hexo-component-inferno is not installed.
ERROR Package inferno is not installed.
ERROR Package inferno-create-element is not installed.
ERROR Please install the missing dependencies your Hexo site root directory:
ERROR npm install --save bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3 hexo-component-inferno@^0.10.1 inferno@^7.3.3 inferno-create-element@^7.3.3
ERROR or:
ERROR yarn add bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3 hexo-component-inferno@^0.10.1 inferno@^7.3.3 inferno-create-element@^7.3.3

 

5. git submodule 관련 사항

- 설치 잘못해서 재 설치시 나왔던 에러

git 레파지토리에 submodule을 추가했다가 제거한 후 다시 추가 하려고 하니 다음과 같은 에러가 발생했다.

 

A git directory for 'themes/icarus' is found locally with remote(s):

 

그런데 분명한것은 현재 로컬에는 저 폴더가 없는 상태이다. 하짐나  .git/modules 하위에 themes/icarus 라는 폴더가 남아있었다. 그래서 그 폴더를 삭제한 후 submodule  을 추가 하니 정상적으로 동작을 했다.

 

- 다른 곳에서 submodule 을 포함한 소스 내려 받기

 

최초 내려 받기 : git clone --recursive git_url

이미 내려받는 곳에서 submodule 만 받기 : git submodule update --init --recursive

 

 

참고 사이트 

github.com/ppoffice/hexo-theme-icarus

blog.zhangruipeng.me/hexo-theme-icarus/uncategorized/getting-started-with-icarus/

www.vogella.com/tutorials/GitSubmodules/article.html

728x90
반응형
반응형

잠깐 필요에 의해서 만든 소스

 

def changeStringInFile(filePath, orgValue, newValue):
    with open(filePath, "r+") as file_object:
        fileContents = file_object.read()
        newFileContents = fileContents.replace(orgValue, newValue)   
        file_object.seek(0)
        file_object.write(newFileContents)
        file_object.close()

 

파일을 오픈 한 후에 orgValue 를 찾아서 newValue 로 변경을 한다.

변경을 한 후 열었던 파일에 다시 덮어쓴다.

다시 write 할 때에 기존 파일 뒤에 append 되는것을 막기 위해서 seek(0) 를 사용한다.

 

728x90
반응형
반응형

1. PV (Persistent Volume)

 

- PV는 클러스터 리소스 이다. 

 

- volumeModes

  Filesystem : Pod 의 디렉토리에 마운트 된다.

  Block

 

- PersistentVolumeReclaimPolicy (PVC 삭제시 PV 데이터에 대한 정책)

  - Retail : 그대로 보존

  - Recycle : 재사용시 기존 pv 데이터들 삭제 후 재사용 (이건 사용 안함)

  - Delete : 볼륨 삭제 

 

- RecaimPolicy Update

  kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'

 

2. PVC (Persistent Volume Claim)

 

pv 와 pvc 는 1:1 바인딩이며 pvc 가 요청하는 볼륨이 pv 에 없으면 무한 대기 한다.

따라서 바인딩을 위해서는 pv와 pvc 의 storageClassName 이 같아야 한다.

 

pod 이 사용중인 pvc 는 삭제가 불가능 하다.

 

3. 생성 Yaml (mysql 에서 사용하려고 만든 yaml 파일 이다.)

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: spring
  name: mysql-pv
spec:
  storageClassName: local-path
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 2Gi
  hostPath:
    path: /home/master01/k8s/mysql-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: spring
  name: mysql-pvc
spec:
  storageClassName: local-path
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

 

참고 사이트

 

https://kubernetes.io/ko/docs/concepts/storage/persistent-volumes/

https://kubernetes.io/ko/docs/tasks/administer-cluster/change-pv-reclaim-policy/

 

728x90
반응형
반응형

1. github 에 레파지토리 생성

레파지토리 이름은 다음과 같이 만든다.

[ID].github.io

일단 이렇게 하면 저장소 준비는 완료된다.

 

2. hexo 설치 (설치전에 node 는 설치 되어있다고 가정한다.)

- hexo-cli 설치 (혹시 권한 관련 Error 가 나면 앞에 sudo 추가)

npm install hexo-cli -g

- hexo 기본 구성 하기

hexo init [폴더명]

여기에서 폴더는 기존에 있던것은 안되고 새로 생성하거나 그냥 이름을 적으면 자동으로 생성해준다.

실제 폴더에 들어가면 아래와 같이 구성이 되어있다.

- _config.yml 파일 설정 하기

간단하게 다음 두개 항목만 설정해준다.

# Site (사이트 설명 : 자신에게 맞게 설정해주면 된다.)

title: Hexo

subtitle: ''

description: ''

keywords:

author: John Doe

language: en

timezone: ''

 

# Deployment (배포)

## Docs: https://hexo.io/docs/one-command-deployment

deploy:

type: git

repo: 위에 생성한 git 주소를 넣어주면 된다.

branch: main (안쓰면 master로 올라가는듯..)

 

- 로컬 실행

hexo server

 

이렇게 하면 기본적으로 4000번 포트로 실행이 된다.

 

 

3. github 에 배포하기

아래 명령어로 static 파일을 생성한다.

hexo generate 

그리고 deploy 를 한다.

hexo deploy

위와 같이 에러가 나면 다음과 같이 실행해준다.

npm install hexo-deployer-git --save

혹시라도 delpoy를 완료 하고 github 주소로 접속을 했는데 404 에러가 날 경우 다음 설정을 확인해 보면 된다.

Source 항목의 Branch 가 내가 실제 배포한 Branch 와 일치 하는지 확인해 본다. github 의 default 브랜치가 기존에는 master 였는데 최근에 main 으로 변경 되면서 당연히 master 라고 착각하는 경우가 생길 수 있다. (실제로 내가 그랬다.. ㅠㅠ)

 

4. Blog Repository 추가

이건 해도 그만 안해도 그만이다. 본인이 관리하기 쉬운쪽으로 하면 된다.

우선 실제 Blog 가 배포된 Repository 가 존재한다. (github.io 이런 이름으로)

 

그런데 실제 Blog 소스를 배포를 하는 작업을 하나의 PC 가 아닌 여러 PC 에서 작업을 할 경우가 있다. 그래서 이 소스를 관리하기 위한 레파지토리가 하나 더 필요 하다. 

 

- ~.github.io : 실재 배포 버전이 올라가는 repository

- blog : 배포를 하기위한 소스를 관리하가 위한 repository

 

이렇게 나누어 놓으면 어디서든지 github 에서 내려받아서 변경을 하고 배포가 가능하다. 

 

 

참고 사이트

hexo.io/ko/index.html

728x90
반응형
반응형

[K8S] ## K8S 설치시 Trouble Shooting

- kubeadm init 했는데 다음과 같이 나오는 경우

[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.

Unfortunately, an error has occurred:
timed out waiting for the condition
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'

Additionally, a control plane component may have crashed or exited when started by the container runtime.
To troubleshoot, list all containers using your preferred container runtimes CLI, e.g. docker.
Here is one example how you may list all Kubernetes containers running in docker:
- 'docker ps -a | grep kube | grep -v pause'
Once you have found the failing container, you can inspect its logs with:
- 'docker logs CONTAINERID'
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster

 

1. docker Cgroup 이 systemd 로 설정되어있을 경우

/etc/docker/daemon.json 파일에 아래 문구 추가한다.

{
	"exec-opts": ["native.cgroupdriver=systemd"]
}

그리고
systemctl daemon-reload
systemctl restart docker

2. 로그 확인

- 'journalctl -xeu kubelet' 

이 명령어를 실행 하면 아래와 같이 로그가 남았다. 

Apr 30 22:19:38 master kubelet: W0430 22:19:38.226441    2372 cni.go:157] Unable to update cni config: No networks found in /etc/cni/net.d
Apr 30 22:19:38 master kubelet: E0430 22:19:38.226587    2372 kubelet.go:2067] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized

 

내 경우에는 위에 2.  /env/environment 설정 에 보면 **no_proxy** 항목에 현재 K8S 가 설치된 Machine 의 IP 를 추가했더니 해결이 되었다.

- kubeadm join 했는데 다음과 같이 나올 경우

[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
    [ERROR Port-10250]: Port 10250 is in use
    [ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

    VM 에서 다음과 같이 kubeadm join 을 했는데 에러가 났을경우 (node가 2개인데 2번째 노드 구성시)

    kubeadm reset 을 한번 실행하고 다시 join 명령어를 실행해준다.

728x90
반응형
반응형

몇번의 시도 끝에 Virtual Box 에 Kubernetes 설치를 성공했다.

총 Master1 개, Worker 2 개로 구성을 했다.

 

1. Virtual BOX 환경설정

    - 네트워크 

        - 네트워크 이름 : k8s-network

        - 네트워크 CIDR : 10.0.1.0/24

        - 네트워크 옵션 : DHCP 지원 체크

2. Machine 설정 (화면캡쳐 없음 ㅠㅠ)

    - 일반 : 고급

        - 클립보드 공유 : 양방향

        - 드래그 앤 드롭 : 양방향

    - 시스템 : 프로세서 

        - 개수 : 2

    - 네트워크 : 어댑터 1

        - 다음에 연결됨 : Nat 네트워크

        - 이름 : k8s-network  (미리 만들어야된다.)

    - 네트워크 : 어댑터 2

        - 다음에 연결됨 : Nat    

    - 공유폴더 (Optional)

        - 폴더 설정, 마운트 지정

3. 설치

4. 완료후 설정 (Optional) 

    - 장치 : 게스트 확장 CD 삽입 -> 설치

5. Ubuntu 설정 

    1. 관리자 계정으로 시작

        sudo -i

    2.  /etc/environment 설정 (Optional proxy를 사용하는 경우만 해당됨) 

        export http_proxy=http://[IP]:[PORT]

        export https_proxy=http://[IP]:[PORT]

        export no_proxy=IP...

    3. 가상메모리 미사용

swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab

    4. 인증서 설정 (Optional) 

        /usr/local/share/ca-certificates/ 에 인증서 복사

        update-ca-certificates 실행

    5. 도커 설치

apt update
apt install -y docker.io
cat << EOF > /etc/docker/daemon.json
{
	"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

    6. 프록시 추가 (Optional) 

vi /lib/systemd/system/docker.service

        [Service]

        Environment="HTTP_PROXY=http://[IP]:[PORT]/" "HTTPS_PROXY=http://[IP]:[PORT]/" "NO_PROXY=localhost,127.0.0.1,10.0.1.7"

 

    7. 도커 재기동

systemctl daemon-reload
systemctl restart docker

    8. K8S 패키지 매니저 레파지토리 추가

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg -k | apt-key add -
cat << EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

    9. K8S 설치

apt update -y
apt-get update
apt-get install -y kubelet kubeadm kubectl

        1. Master Node 설정

            1. kubeadm init

kubeadm init --pod-network-cidr=10.244.0.0/16

                설치후 아래와 같이 메세지가 나오면 정상적으로 설치 완료

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.1.7:6443 --token bfq4lq.1k5qiesq8norkwck \

--discovery-token-ca-cert-hash sha256:66249ed983b26844267631ae0a061c7d02386941e154341bc669c72add72afeb    

            2. kubectl 구성

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

            3. pod network 플러그인 설치

kubectl apply -f http://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

        2. Worker Node 설정

kubeadm join 10.0.1.7:6443 --token bfq4lq.1k5qiesq8norkwck \

--discovery-token-ca-cert-hash sha256:66249ed983b26844267631ae0a061c7d02386941e154341bc669c72add72afeb    

 

참고

docs.docker.com/engine/install/ubuntu/

kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

728x90
반응형

'Development > Docker&Kubernetes' 카테고리의 다른 글

[K8S] PV & PVC  (0) 2020.10.16
[K8S] Kubernetes 설치시 오류 조치  (2) 2020.10.13
VirtualBox 에 Kubernetes 올리기(k3s)  (0) 2020.09.11
맥북에 도커 설치.  (0) 2020.07.10
[K8S] Kubernetes secret 생성  (0) 2020.04.14
반응형

공부하다가 과정이 좀 많아서 적어두기로 함.

 

1. 가상환경 만들기

python -m venv [이름]

ex) python -m venv my_venv

 

2. 가상환경 실행

source my_venv/bin/activate

my_venv/Scripts/activate (윈도우일 경우)

 

3. django 설치 

(3번 부터는 가상환경 안에서 모두 실행한다.)

pip install django

 

4. 프로젝트 만들기

django-admin startproject [이름] .

 

5. 데이터 베이스 만들기

python manage.py migrate

 

6. 프로젝트 실행

python manage.py runserver

 

7. 앱 만들기

python manage.py startapp [앱이름]

 

 

# Model Migration

python manage.py makemigrations [앱이름]

python manage.py migrate

728x90
반응형

+ Recent posts