블로그 이미지
훅크선장

카테고리

분류 전체보기 (360)
사진이야기 (23)
펭귄컴퓨팅 (120)
컴퓨터보안 (83)
절름발이 프로그래머 (59)
하드웨어개조 (23)
멀알려줄까 (35)
홈베이킹&홈쿠킹 (2)
잡다한것들 (15)
Total
Today
Yesterday

달력

« » 2024.3
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
31

공지사항

태그목록

최근에 올라온 글

참조 1: www.programmersought.com/article/36393758843/
참조 2: stackoverflow.com/questions/47031394/scrapy-file-download-how-to-use-custom-filename
https:stackoverflow.com/questions/54737465/unable-to-rename-downloaded-images-through-pipelines-without-the-usage-of-item-p/54741148#54741148
참조 3: docs.scrapy.org/en/latest/topics/media-pipeline.html
참조 4: coderecode.com/download-files-scrapy/
참조 5: heodolf.tistory.com/19

www.hanumoka.net/2020/07/11/python-20200711-python-scrapy-selenium/

iosroid.tistory.com/28

 

scrapy 프로젝트를 생성하고 나서, 다음의 과정을 수행한다.

$ scrapy startproject apt_collection

$ scrapy genspider -t basic reports_spider github.com

 

 

1. items.py 파일에 아이템을 추가한다.
디폴트로 생성되어 있는 아이템 클래스를 그대로 이용할 수도 있고, 새로운 아이템 클래스를 생성해도 된다.
보통 디폴트 아이템 클래스는 아무것도 없다.

class AptCollectionItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()

    pass

 

그래서, 새로운 아이템 클래스를 생성한다.
반드시 필요한 항목은 files와 file_urls 이다. 
일반파일을 다운로드하려면 FilesPipeline을 이용하는 것이고, 이미지 파일을 다운로드 하려면 ImagesPipeline을 이용하는 것이다.
현재는 일반파일을 다운로드 하는 것이므로, 아래는 FilesPipeline을 이용하는 경우를 설명한다.

class reportItem(scrapy.Item):
    title = scrapy.Field()   # 제목
    date = scrapy.Field()  # 날짜
    publisher = scrapy.Field()  # 작성회사명
    url = scrapy.Field() # 원본 URL
    files = scrapy.Field() # file_urls에 지정된 파일들에 대한 다운로드 결과가 저장되는 항목으로, 파일 1개에 대해서, url, path, checksum, status 가  dictionary 형태로 저장된다. ex) [{'url': 'http://.....', 'path': 'abcdefg.pdf', 'checksum': '2f88dd877d61e287fc1135a7ec0a2fa5', 'status': 'downloaded'}]

    file_urls = scrapy.Field()  # URL을 기준으로 scrapy가 다운로드 저장할 파일의 목록 ※ 반드시 List 자료형으로 넘겨줘야 함!!

 

files와 file_urls를 scrapy.Field()로 정의하면 된다.

※ files와 file_urls 이름을 바꾸고 싶다면,  settings.py에서 아래와 같이 정의하면 된다.

#DEFAULT_FILES_URLS_FIELD = 'file_urls'
#DEFAULT_FILES_RESULT_FIELD = 'files'

ImagesPipeline을 이용하는 경우라면, images와 image_urls 명칭을 사용한다.

    image_urls = scrapy.Field()

    images = scrapy.Field()

 

images와 image_urls 명칭을 바꾸고 싶다면, settings.py에서 아래와 같이 정의하면 된다.
IMAGES_URLS_FIELD = 'field_name_for_your_images_urls'
IMAGES_RESULT_FIELD = 'field_name_for_your_processed_images'

 

2. settings.py에 있는 ITEM_PIPELINES 설정을 해준다.

robots.txt 방어가 있을 수 있으니, 

ROBOTSTXT_OBEY = False

로, 설정을 바꾸는 것을 잊지 않도록 한다.


디폴트의 ITEM_PIPELINES은 다음과 같다.
#ITEM_PIPELINES = 

#    'apt_collection.pipelines.AptCollectionPipeline': 300,
#}

또는,

ITEM_PIPELINES = {

        'scrapy.pipelines.images.ImagesPipeline': 1,

        'scrapy.pipelines.files.FilesPipeline': 1,

}

이렇게 되어 있을 것인데, 이를 파일을 다운로드하도록, 바꾸어줘야 한다. 

ITEM_PIPELINES = {

        'apt_collection.pipelines.AptCollectionPipeline': 1

}

FILES_STORE = r'./download' # 파일이 저장되는 경로를 지정

이런 식으로 바꾸던가, 아니면, 

ITEM_PIPELINES = {

         'my.pipelines.MyFilesPipeline': 200,

         'scrapy.pipelines.files.FilesPipeline': None,

}

기존에 있는 FilesPipeline 들은 모두 None 처리해주거나, 아예 지우는 것이 매우 중요하다.
FILES_STORE 변수를 지정해서, 다운로드 되는 파일들이 저장되는 경로를 지정할 수 있다. 항상 하는 것이 좋다.

3. pipelines.py에 있는 파이프라인을 재정의한다.
디폴트로 생성되는 파이프라인은 다음과 같이 되어 있다.

class AptCollectionPipeline:
    def process_item(self, item, spider):

        return item
    
이것을 다음과 같이, FilesPipeline 이나 ImagesPipeline 을 가지도록 다시 써야한다.
Class 라인에서 Pipeline 클래스 이름 옆에 반드시 (FilesPipeline)이나 (ImagesPipeline) 구문이 추가되어야 한다.
FilesPipeline과 ImagesPipeline 모듈 임포트도 해준다.

from scrapy.pipelines.files import FilesPipeline
from scrapy.pipelines.files import ImagesPipeline

class AptCollectionPipeline(FilesPipeline):
    # 디폴트 처리를 주석처리하고, 파일명을 정해진 규칙대로 지정하기 위한 Override 함수 정의
    def file_path(self, request, response=None, info=None, *, item=None):
        file_name: str = request.url.split("/")[-1] # 파일 수집 URL에 파일명이 있는 경우에는 URL 에서 파일명을 추출해서 사용

        #file_name : str = request.meta['filename'] # 메타 정보를 이용하여, 이전 request 함수에서 파일명을 전달받은 수 있음

        #file_name: str = item['filename']  # 추출되는 Item의 항목에 별도의 파일명을 지정할 수 있다면, 그 파일명을 가져와, 저장하는 파일 이름으로 사용 가능(파일의 저장 경로는 settings.py에 설정되어 있음!)
        # print("filename :  ", file_name)
        return file_name

Pipeline을 재정의하면서, 반드시 필요한 파일명 지정에 대한 함수를 Override 하게 해야 한다.

파일명을 spider 함수쪽에서 item 항목으로 전달하거나, 또는 meta 항목에 넣어서 전달할 수도 있다.
아니면, request.url 쪽의 내용을 파싱해서 사용하는 방법도 있다.
또는, 다운로드 대상 파일 URL을 수집요청하는 호출 쪽에서 meta 값을 다음과 같이 정의해서 넘겨주면 된다.

        meta = {'filename': item['name']}
        yield Request(url=file_url, meta=meta)

 

※ get_media_requests 함수도 Override 해야한다는 의견도 있는데, 확인해보니 각 Item에 수집되는 파일이 1개 인 경우에는 아무 상관이 없었다. 또한 한 Item에서 수집되는 파일이 여러개이더라도, 파일명을 위의 file_path 함수에서와 같이 url로부터 추출되는 경우라면 이상이 없었다. 그러나 한 Item에서 여러개의 파일이 수집되어야 하고, 파일명을 별도로 지정해야 하는 경우에는 get_media_requests 함수에서 파일명을 file_path로 넘겨줘야만 하므로, 다음과 같이  get_media_requests 함수를 재정의해서 추가해야 한다. 
※ v2.3 버전에서는 item 이 파이프라인으로 정상적으로 넘어오지 않는 것 같은 현상이 있다. get_media_requests 함수를 반드시 정의해서 meta 값을 Request 인자로 사용해야만 했다. v2.4에서는 get_media_requests 함수가 없이 file_path 만 재 정의하여도 잘 동작하였다.
  def get_media_requests(self, item, info):
      for idx, file_url in enumerate(item['file_urls']):  # 수집되어야할 파일들의 URL은 반드시 List 자료형으로 입력된다.
     #print("filename : ", item['file_names'][idx])
     yield scrapy.Request(file_url, meta={'filename': item['file_names'][idx]}) # 각각 다운받을 파일  URL에 대한 요청을 하면서, meta 딕셔너리 값의 하나로 파일명 리스트에서 순번에 맞게 파일명을 넘겨준다. 이것때문에 이 함수를 재정의하였다.

        
※ 파일이 다운로드 되고나서, 처리를 해주는 함수도 있다. (아마 파일이 정상적이지 않은지 확인하는 방법으로 유용할 듯 하다.)
from itemadapter import ItemAdapter
from scrapy.exceptions import DropItem

 

def item_completed(self, results, item, info):
    file_paths = [x['path'] for ok, x in results if ok]
    if not file_paths:
        raise DropItem("Item contains no files")
    adapter = ItemAdapter(item)
    adapter['file_paths'] = file_paths
    return item
    
4. spider 함수에서 item을 생성하면, Scrapy에 의해 파일이 자동으로 수집된다.

            item['file_urls'] = [url_1, url_2, url_3] # URL을 기준으로 scrapy가 다운로드 저장할 파일의 목록 ※ 반드시 List 자료형으로 넘겨줘야 함!!
            yield item

 

5. 만약 crawl 하는 과정에서 파일 다운로드가 되지 않고, 302 에러가 발생한다면, 파일 다운로드 URL이 redirect되는 경우이므로, 

settings.py 파일안에, 아래의 변수를 추가하면 해결된다.

 

MEDIA_ALLOW_REDIRECTS = True

Posted by 훅크선장
, |

www.nxp.com/design/software/development-software/codewarrior-development-tools/run-control-devices/codewarrior-tap:CW_TAP

 

CodeWarrior® TAP | NXP

Distributor Name Region Inventory Inventory Date Upon selection of a preferred distributor, you will be directed to their web site to place and service your order. Please be aware that distributors are independent businesses and set their own prices, terms

www.nxp.com

NXP 사의 JTAG Debugger인 CodeWarrior TAP 장비에는 반드시 케이블을 연결해야만, 장비 디버깅이 가능하다.

왜냐하면, CodeWarrior TAP 장비에 연결포트는 30pin 이고, 우리가 일반적인으로 보고 있는 디버깅 대상 장비(표준 개발 장비)는 보통 20pin 이나 16pin과 같은 표준 JTAG 포트를 쓰기 때문이다.

무슨 이유인지 몰라도, CodeWarrior TAP  장비의 전용 케이블들은 본 장비와 별도로 구매해야 하고, 가격도 70달러 즈음이라 안 살 수가 없다는 것이 날벼락이다.

 

표준 JTAG 포트와 같이 pin map을 알려주면, JTAG 포트가 표준이 아닌 장비에도 JTAG 케이블 없이 바로 장비 포트에 연결해서 사용할 있을 것 같은데... 케이블 팔아서 부자되려고 하는지? 30pin의 pin map을 공개하지 않고 있다. (아무리 찾아봐도 안보인다!!) 

 

결국 NXP가 판매하는 전용 케이블, 16pin JTAG 케이블인 CWH-CTP-COP-YE 를 구해서, Pin Map을 그려보았다.

www.nxp.com/design/software/development-software/codewarrior-development-tools/run-control-devices/power-architecture-processor-cop-probe-tips-for-codewarrior-tap:CWH-CTP-COP-YE

 

Pin Map of CWH-CTP-COP-YE :

Posted by 훅크선장
, |

[재료]

양파 1/2, 대파 1/2, 샐러리 1/2, 파프리카 1/2

마늘 6, (다진마늘 1 스푼), 청양고추 1, 

포두부 3, 닭가슴살 150g

숙주 120g, 달걀 1, 레몬즙 약간만

 

멸치액젓 1Ts, 간장 1/2Ts, 굴소스 1Ts, 3Ts , 설탕 2ts

 

  1. 양파, 대파, 샐러리, 파프리카를 얇게 썰어준다.
  2. 닭가슴살도 얇게 썰어준다. 소금과 후추로 약간 간을 해둔다.
  3. 마늘을 얇게 편썰기하고, 청양고추도 얇게 썰어준다.
  4. 포두부를 끝부터 말아서, 썬다. 그리고 손으로 각각 풀어준다.
  5. 물에 소금 약간을 넣고, 포두부를 조금씩 풀어서 넣어주고 30초간 데친다. (건져서 찬물로 씻어두면 식감이 좋다고 하는데안해봤다.)
  6. 양념장을 만든다. 청양고추 것을 넣어둔다.
  7. 양파, 샐러리, 대판, 파프리카를 기름에 볶는다. 숨이 죽을때까지, 굽듯이 충분히 볶아준다.
  8. 야채에 윤기가 나기 시작하면, 마늘을 넣어준다. (다진 마늘 스푼을 추가해도 좋다~) ※ 마늘의 전분때문에 타지 않도록 눌러붙지 않도록 하기 위해서 나중에 넣는다.
  9. 닭가슴살을 넣고 굽듯이 한쪽이 완전히 익을때까지 두었다가 뒤집는다.
  10. 양념장을 넣고 끓인다.
  11. 건두부 데친 물을 1국자 넣어서, 국물이 졸이게 중불이하로 서서히 끓인다.
  12. 다른 팬에 기름을 살짝 두르고, 숙주를 살짝만 볶아준다. 소금과 후추를 살짝 추가한다.
  13. 데친 숙주를 덜어내고, 계란을 볶는다.
  14. 계란은 살짝 익으면, 전체를 저어주어 스크램블 형태로 만들고, 불을 끄고 잔불로만 나머지를 살짝 익힌다.
  15. 포두부를 넣고, 비빈다. 이때 국물이 너무 없다면, 포두부 데친 물을 넣고 강한 불로 끓여준다. 
  16. 마지막에 레몬즙 살짝 투하 (없어도 상관없어요.)
  17. 접시에 포두부 볶음을 담고, 위에 데친 숙주와 주변부에 스크램블된 달걀을 배치한다.

국물의 점도를 유지하는 것이 중요함~~!!

Posted by 훅크선장
, |

[재료]

두부 100g 

청양고추 1 

홍고추 1 

고추기름 2Ts 

다진 마늘 1Ts 

두반장 1Ts 

굴소스 1/2Ts

추가 : 양파 반개와 대파 반개를 썰어서 넣는게 좋다.

 

 

1. 건두부는 썰어 뜨거운 물에 데쳐 찬물에 씻어 물기를 제거한다.

2. 청양고추, 홍고추는 어슷 썰어 준다.

3. 프라이팬에 고추기름, 다진 마늘을 넣고 볶는다.

4. 마늘의 향이 나면, 건두부와 고추를 넣는다.

건두부 넣기전에, 양파와 대파도 같이 넣고 볶아준 다음에, 

    건두부와 고추를 넣는다.

5. 두반장, 굴소스를 넣고 볶는다.

 

-주의사항

* 간이 조금 강할 수도 있어서 두반장은 절반만 먼저 넣으세요.

Posted by 훅크선장
, |

Arduino에 비해, 성능이 훨씬 낫다고 하는 ESP32를 배워보고 있다.

참고할만한 정보를 모아봤다.

 

1. 맥에서 프로그래밍 환경 설정

docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/macos-setup.html#install-prerequisites

 

Standard Setup of Toolchain for Mac OS - ESP32 - — ESP-IDF Programming Guide latest documentation

© Copyright 2016 - 2020, Espressif Systems (Shanghai) CO., LTD

docs.espressif.com

2. ESP32로 IoT 장치를 만드는 정보가 모아진 곳 

esp32.net/

 

The Internet of Things with ESP32

Created by Espressif Systems, ESP32 is a low-cost, low-power system on a chip (SoC) series with Wi-Fi & dual-mode Bluetooth capabilities! The ESP32 family includes the chips ESP32-D0WDQ6 (and ESP32-D0WD), ESP32-D2WD, ESP32-S0WD, and the system in package (

esp32.net

3. ESP32 개발보드 공부를 시작하기 좋은 곳 

randomnerdtutorials.com/getting-started-with-esp32/

 

Getting Started with the ESP32 Development Board | Random Nerd Tutorials

This is a getting started guide for the ESP32 Development board. The ESP32 is the ESP8266 sucessor. Loaded with new features: WiFi, Bluetooth, dual core, ...

randomnerdtutorials.com

4. ESP32에서 별도의 UART 송수신 예제인 UART_ECHO 실험을 할때, 문제가 되는 부분인 가상 에뮬레이터 설정에 관련된 내용이 맞게 쓰여진 참고 사이트 (일본어)

tech.yoshimax.net/archives/107

 

[ESP32-EVB][esp-idf][UART] サンプルの uart_echo を試してみる – yoshimax::tech

ESP32-EVBを使って、esp-idfのuart_echoサンプルを試してみたいと思います。 esp-idf/examples/peripherals/uart_echo/main/uart_echo_example_main.c サンプルをコピーします $ cp -r esp-idf/examples/peripherals/uart_echo ./ $ cp -r

tech.yoshimax.net

5. ESP32 교육을 듣게된 계기가 된 온라인 워크숍의  자료 공유 장소인 밴드 

band.us/band/80474328/attachment

 

(온라인 워크숍) ESP32 (초급+중급 과정) | 밴드

밴드는 그룹 멤버와 함께 하는 공간입니다. 동호회, 스터디, 주제별 모임을 밴드로 시작하세요.

band.us

6. 실습에 사용된 ESP32보드와 센서 쉴드 구매한 곳 

mechasolution.com/shop/goods/goods_view.php?goodsno=577245&category=

mechasolution.com/shop/goods/goods_view.php?goodsno=583929&category=

(센서 쉴드만 사면 된다. 코어보드 살 필요 없다!!)

 

전자부품 전문 쇼핑몰 메카솔루션입니다.

국내 최대 전자부품 쇼핑몰, 아두이노 키트, 라즈베리파이 등 당일발송, 예제 제공, 쇼핑 그 이상을 제공합니다.

mechasolution.com

 

Posted by 훅크선장
, |

이미 유·무선공유기가 존재하는 환경에서 특정한 이유로 무선 접속 반경을 넓혀야만 하는 경우가 종종 발생한다. 

※ 대표적으로 아파트에서 거실에 있는 유·무선공유기의 무선신호가 화장실등에 특정지역에서 너무 속도가 안나오는 상황!

 

인터넷 회선을 이미 공유해서, 하나의 유·무선공유기로 사용하고 있는데, 무선 접속 반경을 넓히는 방법은 두 가지가 있다.

1) 무선 신호를 중계해주는 Wireless Extender 등을 사용하는 방법

   - Wireless Extender, WiFi Range Extender, Wifi repeater 등의 이름으로 불리는 장비를 하나 사면 된다. 

   - 가격이 비싸지 않고, 손쉽게 무선 접속 반경을 늘릴 수 있다. 전기만 있으면 되므로, 아주 편리한 방법이다.

   - 무선 장치의 특성으로, 거리 제한이 있고 유선에 비해서 속도가 떨어지고 동시접속의 한계가 존재한다. (일반 개인의 가정에서는 신경쓸 필요가 없는 단점이다!)

※ 일반 가정의 경우에는 그냥 1번 방법을 추천한다. 2번은 소규모 사업장이나 정말 속도에 목매는 사람에게만 권장한다. 

2) 유선 연결이 가능한 또다른 공유기(구형 모델이더라도 가능)를 가지고 Dumb AP(또는  Bridged AP)로 만들어서, 유선과 무선 네트워크를 모두 확장하는 방법 

   - 집에서 놀고 있는 구형 공유기를 가지고, 네트워크를 공부할 수 있는 좋은 사례가 된다?!

   - 유선 네트워크와 무선 네트워크 둘 다를 확장할 수 있으며, 네트워크 속도가 단순 무선 확장방식(1번 방법)보다는 빠르다.

   - 유선이 연결되는 거리안에서 자유롭게 넓은 범위로 무선네트워크 반경을 확장할 수 있으며, 네트워크를 체계적으로 관리가 가능하다.(네트워크를 잘 아는 사람에게만 유리한 것이다.)

 

2번 경우를 가정하고, 기존에 운영하고 있는 유·무선공유기(이후 “메인 라우터”라고 지칭)이외에 구형의 OpenWRT가 설치된 유·무선공유기를 대상으로 작업하는 것을 설명한다.

 

0. 사전 준비

    - 최대한 최신 OpenWRT 펌웨어를 설치한 유·무선공유기를 준비한다.

    - Dumb AP(또는  Bridged AP)는 WAN 포트를 사용하지 않는다.

       ※ WAN 포트를 LAN 포트를 용도변경해서 사용할 수 있기도 하지만, 보통 4개 정도인 유선 LAN 포트가 사용하기에 충분하기에 굳이 어렵게 설정을 변경해서 WAN 포트를 사용하지 않아도 된다. 괜히 나중에 설정을 복구할때 헷갈릴 수도 있다!

    - 무선 네트워크 설정은 웹 UI에서 하는 것이 훨씬 편리하다.

    - 유선 네트워크 설정을 바꾸는 작업은 맨 마지막에 하며, 가능하면 SSH 접속을 이용해서 command line 명령으로 하는 것이 좋다.

    - 공유기의 LAN 포트와 작업하는 컴퓨터를 연결하고,(WAN은 절대 연결하지 않는다!) 공유기에 로그인 한다.

 

1. 무선 네트워크 설정

LUCI 기반의 웹 환경에서 로그인해서, 무선 네트워크를 먼저 설정한다. 메인라우터의 무선 설정과 동일하게 설정해도 되지만, 물리적인  주파수 채널은 다르게 해주는 것이 좋다.

 

2. LAN 영역에서 DHCP와 IPv6 비활성화 

Network → Interfaces 화면으로 가서 LAN interface 를 선택한다.

 “Ignore interface: Disable DHCP for this interface.” 항목을 찾아서, 체크 선택을 한다. 그리고 “IPv6 Settings” 탭으로 이동해서 모든 것을 “disabled”로 선택한다. IPv6 관련 기능은 아예 안쓰는 것으로 해야한다.

 

3. 방화벽과 DNSmasq, 그리고 odhcpd 비활성화

System → Startup 메뉴로 이동한 다음, Startup scripts 목록에 있는 firewall, dnsmasq, odhcpd을 disable 시킨다.

맨 아래에 있는 Save and Apply 버튼을 눌러서 적용시킨다.

 

4. 메인라우터와의 Bridged 네트워크를 설정

다시 Network → Interfaces 화면으로 가서 LAN interface 를 선택한다.

이제 유선 네트워크를 실제로 바꾸는 곳이다. 가능하면 SSH 상에서 Command line 명령이라, 설정파일 수정으로 하는 것이 좋지만,

어쪌 수 없다면, 웹 UI 상에서 “IPv4 address”는  메인라우터 IP 주소의 다음번으로 선정하는 것이 좋다. 예를 들어 OpenWRT 장비의 기본 IP 주소는 192.168.1.1 인데, 그대로 사용하고 있다면, 추가로 연결되는  Dump AP의 주소는 192.168.1.2 를 선정하는 것이 좋다. 해당 네트워크 대역의 마지막 IP 주소인 192.168.1.254도 괜찮은 선택이다.

Gateway는 메인라우터의 IP 주소, 일반적인 OpenWRT의 메인라우터를 그대로 쓰고 있다면, 위에 말한 바와 같이 192.168.1.1을 적는다.

Netmask는 대부분 255.255.255.0 로,

DNS는 국내 KT의 DNS IP 주소인 168.126.63.1 또는 국외 구글의 DNS IP 주소인 8.8.8.8 을 적어두면 된다. 우선순위는 바꾸어도 상관없다.

 

위의 4번 유선네트워크 설정 과정은 SSH 상에서 작업은 다음과 같이 설정파일을 직접 수정하여 빠르게 한꺼번에 할 수도 있지만,

설정파일 내용을 잘 이해하기 어려운 경우에는 권장하지 않는다.

 

4. 유선네트워크 설정(/etc/config/network)

/etc/config/network 파일에 들어가서, 아래와 같이  ipaddr, netmask, gateway, dns를 수정·추가해준다.

Dump AP의 IP 주소는 192.168.1.2 이고, 메인라우터의 IP 주소는 192.168.1.1 이다.

config interface 'lan'

           option type 'bridge'

           option ifname 'eth0.1'

           option proto 'static'

           option ipaddr '192.168.1.2'

           option netmask '255.255.255.0'

           option gateway '192.168.1.1'

           option dns '192.168.1.1'

           option ip6assign '60'

 

설정이 완료되었으면, 장비의 네트워크 서비스만을 재시작 하거나, 아니면 장비를 재부팅한다.

root@OpenWRT:~# /etc/init.d/network restart

 

또는

 

root@OpenWRT:~# reboot

 

이제 dump AP의 랜 포트중의 하나와 메인라우터의 랜 포트중의 하나를 랜선으로 연결해준다. 그러면 유선이든 무선이든 메인라우터에도 접근할 수 있고, 인터넷도 사용할 수 있다. Dump AP로의 접근은 앞에서 설정한  Dumb AP IP 주소로 쉽게 할 수 있다.

Posted by 훅크선장
, |

Go 언어 연습을 위해서, CentOS 7 Linux 환경에서 Go 언어 환경을 설치해 본 것입니다.

 

0. GoLang 설치하기 

# cd

# wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz

# tar -zxvf go1.14.2.linux-amd64.tar.gz 

# mv go/ /usr/local/

 

GoLang 사용을 위한 환경변수 설정 

# cd

# vi .bashrc

다음을 추가한다.

export PATH=/usr/local/go/bin:$PATH

 

Go 언어 테스트해보기

# vi helloworld.go

예제 파일 내용을 다음과 같이 만든다.

package main

import "fmt"

func main() {
fmt.Println("Hello World")
}

 

# go build helloworld.go

# ./helloworld

Hello World

 

1. 기존 vim 패치키 제거 

# yum remove vim-common vim-enhanced vim-filesystem vim-minimal

 

2. 필요한 라이브러리 등 설치 

# yum install gcc make ncurses ncurses-devel cmake

# yum install ctags git tcl-devel  ruby ruby-devel  lua lua-devel  luajit luajit-devel  python python-devel  perl perl-devel  perl-ExtUtils-ParseXS  perl-ExtUtils-XSpp  perl-ExtUtils-CBuilder  perl-ExtUtils-Embed

 

3. vim 8 다운로드 및 빌드와 설치 

# cd

# git clone https://github.com/vim/vim.git

# cd vim

# ./configure --with-features=huge --enable-multibyte --enable-rubyinterp  --enable-python3interp --enable-perlinterp --enable-luainterp

# make

# make install

 

설치가 완료되면, 버전 확인하기

# vim --version

 

4. Pathogon은 vim 플러그인과 런타임 파일을 쉽게 관리 할 수 있도록 도와주는 vim 환경관리 툴이다. 먼저 pathogon을 설치한다.
~/.vim/autoload 디렉토리 밑에 vim-pathogon을 클론(clone)한다.

# mkdir -p ~/.vim/autoload

# cd ~/.vim/autoload
# git clone https://github.com/tpope/vim-pathogen.git
pathogen.vim을 ~/.vim/autoload 디렉토리에 복사한다.

# cp vim-pathogen/autoload/pathogen.vim ./


아래와 같이 vim-go 스크립트를 다운로드 한다.

# mkdir -p ~/.vim/bundle

# cd ~/.vim/bundle
# git clone https://github.com/fatih/vim-go.git

 

홈 디렉토리에 .vimrc 파일을 생성하고, 다음과 같이 작성한다.

# vi ~/.vimrc 
execute pathogen#infect()
syntax on
filetype plugin indent on

vim을 실행하고 :GoInstallBinaries명령을 실행하면, vim-go 관련된 플러그인들이 자동으로 설치된다.

 

4. YouCompleteMe(이하 YCM)은 VIM을 위한 자동코드완성 엔진이다. YCM은 C, C++, Object-C, Object-C++, CUDA, Python2, Pyton3, C#, Go 등 다양한 언어에 대한 자동완성기능을 제공한다.
YCM을 클론하고 컴파일 한다. Go 자동완성을 지원하고 싶다면 --go-completer 를 컴파일 옵션으로 설정해야 한다.

 

# cd ~/.vim/bundle
# git clone https://github.com/Valloric/YouCompleteMe.git
# cd ~/.vim/bundle/YouCompleteMe
# git submodule update --init --recursive
# ./install.sh --go-completer 

 

5.Tagbar
Tagbar 플러그인을 이용해서 현재 파일의 태그를 탐색해서, 코드의 대략적인 구조를 빠르게 살펴볼수 있다.

#cd ~/.vim/bundle
# git clone https://github.com/majutsushi/tagbar.git

 

6. NerdTree
NERDTree는 Vim용 파일 탐색기다. 이 플러그인은 디렉토리의 구조를 계층적으로 보여줘서, 파일을 쉽게 탐색하고 편집할 수 있도록 도와준다.

# cd ~/.vim/bundle
# git clone https://github.com/scrooloose/nerdtree.git

 

 

참조 사이트 : 

https://golang.org/dl/

 

Downloads - The Go Programming Language

Downloads After downloading a binary release suitable for your system, please follow the installation instructions. If you are building from source, follow the source installation instructions. See the release history for more information about Go releases

golang.org

https://www.joinc.co.kr/w/man/12/golang/Start

 

golang 시작하기 - 개발환경 만들기

 

www.joinc.co.kr

http://www.programmersought.com/article/6244238683/

 

Centos7 install vim8.0 + YouCompleteMe + support python 3.6 - Programmer Sought

Install python3.6:https://blog.csdn.net/wanormi/article/details/82900782 Upgrade vim and gcc Upgrade gcc sudo yum install centos-release-scl -y sudo yum install devtoolset-3-toolchain -y sudo yum install gcc-c++ sudo scl enable devtoolset-3 bash Upgrade vi

www.programmersought.com

https://phoenixnap.com/kb/how-to-install-vim-centos-7

 

How to Install Vim 8.2 on CentOS 7? (Latest Version)

You don't need to wait for the latest version of Vim to appear in official repositories. In tutorial learn how to install Vim 8.2 on CentOS 7. Get Started!

phoenixnap.com

 

Posted by 훅크선장
, |

참조 : https://www.ostechnix.com/bat-a-cat-clone-with-syntax-highlighting-and-git-integration/

 

Bat - A Cat Clone With Syntax Highlighting And Git Integration

Bat command is a clone to the cat command, with some additional cool features such as syntax highlighting, git integration and automatic paging etc.

www.ostechnix.com

리눅스에서의 cat 명령어를 대체하는  rust 기반의 bat 이라는 명령어를 설치하는 과정입니다.

 

1. 먼저 rust 환경을 설치합니다.

# curl https://sh.rustup.rs -sSf |sh

# source $HOME/.cargo/env

 

2. 필요 패키지 설치

# yum install clang

 

3. bat 빌드와 설치 

# cargo install bat

 

-----------------------------------------------------------------------------------------

실제 진행상황

[root@server ~]# curl https://sh.rustup.rs -sSf |sh

info: downloading installer

 

Welcome to Rust!

 

This will download and install the official compiler for the Rust

programming language, and its package manager, Cargo.

 

It will add the cargo, rustc, rustup and other commands to

Cargo's bin directory, located at:

 

  /root/.cargo/bin

 

This can be modified with the CARGO_HOME environment variable.

 

Rustup metadata and toolchains will be installed into the Rustup

home directory, located at:

 

  /root/.rustup

 

This can be modified with the RUSTUP_HOME environment variable.

 

This path will then be added to your PATH environment variable by

modifying the profile files located at:

 

  /root/.profile

/root/.bash_profile

 

You can uninstall at any time with rustup self uninstall and

these changes will be reverted.

 

Current installation options:

 

 

   default host triple: x86_64-unknown-linux-gnu

     default toolchain: stable

               profile: default

  modify PATH variable: yes

 

1) Proceed with installation (default)

2) Customize installation

3) Cancel installation

>1

 

info: profile set to 'default'

info: default host triple is x86_64-unknown-linux-gnu

info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

info: latest update on 2020-03-12, rust version 1.42.0 (b8cedc004 2020-03-09)

info: downloading component 'cargo'

info: downloading component 'clippy'

info: downloading component 'rust-docs'

 12.0 MiB /  12.0 MiB (100 %)  11.1 MiB/s in  1s ETA:  0s

info: downloading component 'rust-std'

 17.1 MiB /  17.1 MiB (100 %)  10.9 MiB/s in  1s ETA:  0s

info: downloading component 'rustc'

 58.6 MiB /  58.6 MiB (100 %)  11.1 MiB/s in  5s ETA:  0s

info: downloading component 'rustfmt'

info: installing component 'cargo'

info: installing component 'clippy'

info: installing component 'rust-docs'

 12.0 MiB /  12.0 MiB (100 %)   7.4 MiB/s in  1s ETA:  0s

info: installing component 'rust-std'

 17.1 MiB /  17.1 MiB (100 %)  11.8 MiB/s in  1s ETA:  0s

info: installing component 'rustc'

 58.6 MiB /  58.6 MiB (100 %)  11.5 MiB/s in  5s ETA:  0s

info: installing component 'rustfmt'

info: default toolchain set to 'stable'

 

  stable installed - rustc 1.42.0 (b8cedc004 2020-03-09)

 

 

Rust is installed now. Great!

 

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH

environment variable. Next time you log in this will be done

automatically.

 

To configure your current shell run source $HOME/.cargo/env

[root@server ~]# source $HOME/.cargo/env

[root@server ~]# yum install

clang

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirror.kakao.com

 * extras: mirror.kakao.com

 * updates: mirror.kakao.com

Resolving Dependencies

--> Running transaction check

---> Package clang.x86_64 0:3.4.2-8.el7 will be installed

--> Processing Dependency: llvm(x86-64) = 3.4.2-8.el7 for package: clang-3.4.2-8.el7.x86_64

--> Processing Dependency: libLLVM-3.4.so()(64bit) for package: clang-3.4.2-8.el7.x86_64

--> Running transaction check

---> Package llvm.x86_64 0:3.4.2-8.el7 will be installed

---> Package llvm-libs.x86_64 0:3.4.2-8.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=================================================================================================================================================

 Package                            Arch                            Version                                Repository                       Size

=================================================================================================================================================

Installing:

 clang                              x86_64                          3.4.2-8.el7                            extras                           19 M

Installing for dependencies:

 llvm                               x86_64                          3.4.2-8.el7                            extras                          1.3 M

 llvm-libs                          x86_64                          3.4.2-8.el7                            extras                          7.6 M

 

Transaction Summary

=================================================================================================================================================

Install  1 Package (+2 Dependent packages)

 

Total download size: 28 M

Installed size: 93 M

Is this ok [y/d/N]: y

Downloading packages:

(1/3): llvm-libs-3.4.2-8.el7.x86_64.rpm                                                                                   | 7.6 MB  00:00:01     

(2/3): llvm-3.4.2-8.el7.x86_64.rpm                                                                                        | 1.3 MB  00:00:01     

(3/3): clang-3.4.2-8.el7.x86_64.rpm                                                                                       |  19 MB  00:00:03     

-------------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                            8.6 MB/s |  28 MB  00:00:03     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : llvm-libs-3.4.2-8.el7.x86_64                                                                                                  1/3 

  Installing : llvm-3.4.2-8.el7.x86_64                                                                                                       2/3 

  Installing : clang-3.4.2-8.el7.x86_64                                                                                                      3/3 

  Verifying  : clang-3.4.2-8.el7.x86_64                                                                                                      1/3 

  Verifying  : llvm-libs-3.4.2-8.el7.x86_64                                                                                                  2/3 

  Verifying  : llvm-3.4.2-8.el7.x86_64                                                                                                       3/3 

 

Installed:

  clang.x86_64 0:3.4.2-8.el7                                                                                                                     

 

Dependency Installed:

  llvm.x86_64 0:3.4.2-8.el7                                            llvm-libs.x86_64 0:3.4.2-8.el7                                           

 

Complete!

[root@server ~]# cargo install bat

    Updating crates.io index

  Installing bat v0.13.0

   Compiling libc v0.2.69

   Compiling memchr v2.3.3

   Compiling proc-macro2 v1.0.10

   Compiling unicode-xid v0.2.0

   Compiling cfg-if v0.1.10

   Compiling syn v1.0.17

   Compiling proc-macro2 v0.4.30

   Compiling lazy_static v1.4.0

   Compiling unicode-xid v0.1.0

   Compiling autocfg v1.0.0

   Compiling serde v1.0.106

   Compiling regex-syntax v0.6.17

   Compiling byteorder v1.3.4

   Compiling bitflags v1.2.1

   Compiling pkg-config v0.3.17

   Compiling log v0.4.8

   Compiling unicode-width v0.1.7

   Compiling version_check v0.1.5

   Compiling glob v0.3.0

   Compiling ucd-trie v0.1.3

   Compiling matches v0.1.8

   Compiling rustc-demangle v0.1.16

   Compiling vec_map v0.8.1

   Compiling ansi_term v0.11.0

   Compiling quick-error v1.2.3

   Compiling strsim v0.8.0

   Compiling smallvec v1.3.0

   Compiling maplit v1.0.2

   Compiling either v1.5.3

   Compiling bindgen v0.50.1

   Compiling syn v0.15.44

   Compiling liquid-error v0.19.0

   Compiling termcolor v1.1.0

   Compiling shlex v0.1.1

   Compiling proc-macro-hack v0.5.15

   Compiling encoding_index_tests v0.1.4

   Compiling peeking_take_while v0.1.2

   Compiling anymap v0.12.1

   Compiling doc-comment v0.3.3

   Compiling crc32fast v1.2.0

   Compiling percent-encoding v1.0.1

   Compiling ryu v1.0.3

   Compiling version_check v0.9.1

   Compiling adler32 v1.0.4

   Compiling deunicode v1.1.0

   Compiling unicode-segmentation v1.6.0

   Compiling safemem v0.3.3

   Compiling itoa v0.4.5

   Compiling percent-encoding v2.1.0

   Compiling xml-rs v0.8.2

   Compiling same-file v1.0.6

   Compiling linked-hash-map v0.5.2

   Compiling fnv v1.0.6

   Compiling lazycell v1.2.1

   Compiling ansi_term v0.12.1

   Compiling shell-words v0.1.0

   Compiling wild v2.0.2

   Compiling unicode-bidi v0.3.4

   Compiling encoding-index-singlebyte v1.20141219.5

   Compiling encoding-index-japanese v1.20141219.5

   Compiling encoding-index-simpchinese v1.20141219.5

   Compiling encoding-index-tradchinese v1.20141219.5

   Compiling encoding-index-korean v1.20141219.5

   Compiling thread_local v1.0.1

   Compiling humantime v1.3.0

   Compiling line-wrap v0.1.1

   Compiling miniz_oxide v0.3.6

   Compiling pest v2.1.3

   Compiling walkdir v2.3.1

   Compiling itertools v0.8.2

   Compiling unicode-normalization v0.1.12

   Compiling yaml-rust v0.4.3

   Compiling encoding v0.2.33

   Compiling aho-corasick v0.7.10

   Compiling bstr v0.2.12

   Compiling content_inspector v0.2.4

   Compiling num-traits v0.2.11

   Compiling num-integer v0.1.42

   Compiling quote v0.6.13

   Compiling nom v4.2.3

   Compiling error-chain v0.12.2

   Compiling quote v1.0.3

   Compiling idna v0.1.5

   Compiling idna v0.2.0

   Compiling clang-sys v0.28.1

   Compiling fxhash v0.2.1

   Compiling base64 v0.10.1

   Compiling pest_meta v2.1.3

   Compiling jobserver v0.1.21

   Compiling atty v0.2.14

   Compiling term_size v0.3.1

   Compiling time v0.1.42

   Compiling flate2 v1.0.14

   Compiling termios v0.3.2

   Compiling clicolors-control v1.0.1

   Compiling dirs-sys v0.3.4

   Compiling textwrap v0.11.0

   Compiling cc v1.0.50

   Compiling url v1.7.2

   Compiling dirs v2.0.2

   Compiling url v2.1.1

   Compiling clap v2.33.0

   Compiling cexpr v0.3.6

   Compiling regex v1.3.6

   Compiling chrono v0.4.11

   Compiling proc-quote-impl v0.2.2

   Compiling pest_generator v2.1.3

   Compiling env_logger v0.6.2

   Compiling console v0.10.0

   Compiling globset v0.4.5

   Compiling proc-quote v0.2.2

   Compiling backtrace-sys v0.1.35

   Compiling libloading v0.5.2

   Compiling libz-sys v1.0.25

   Compiling libgit2-sys v0.12.3+1.0.0

   Compiling ansi_colours v1.0.1

   Compiling serde_derive v1.0.106

   Compiling backtrace v0.3.46

   Compiling pest_derive v2.1.0

   Compiling failure v0.1.7

   Compiling which v2.0.1

   Compiling git2 v0.13.2

   Compiling onig_sys v69.2.0

   Compiling onig v5.0.0

   Compiling liquid-value v0.19.1

   Compiling serde_json v1.0.51

   Compiling plist v0.4.2

   Compiling bincode v1.2.1

   Compiling liquid-interpreter v0.19.0

   Compiling liquid-compiler v0.19.0

   Compiling syntect v3.3.0

   Compiling liquid-derive v0.19.0

   Compiling liquid v0.19.0

   Compiling bat v0.13.0

    Finished release [optimized] target(s) in 1m 43s

  Installing /root/.cargo/bin/bat

   Installed package `bat v0.13.0` (executable `bat`)

[root@server ~]#

 

Posted by 훅크선장
, |

https://www.2daygeek.com/exa-a-modern-replacement-for-ls-command-linux/

 

Exa – A modern and colorful replacement for list(ls) command written in Rust

ls(list) is one of the very basic & essential Linux command for administrator that can be used in most of the actions (in other hands, Linux administrator can’t live without ls command). …

www.2daygeek.com

 

Rust로 쓰여진 ls 명령어의 대체, 새롭고 색상이 다채로운 exa 설치하기 (CentOS 7에서 성공)

 

1. 먼저 사전 필요한 프로그램 환경 설치

# curl https://sh.rustup.rs -sSf |sh

# source $HOME/.cargo/env

 

2. 필요 패키지 설치

# yum install libgit2 cmake git http-parser

 

3. exa 소스코드 다운로드 및 빌드 

# git clone https://github.com/ogham/exa.git && cd exa

# make install

 

-----------------------------------------------------------------------------------------

실제 진행상황

[root@server ~]# curl https://sh.rustup.rs -sSf |sh

info: downloading installer

 

Welcome to Rust!

 

This will download and install the official compiler for the Rust

programming language, and its package manager, Cargo.

 

It will add the cargo, rustc, rustup and other commands to

Cargo's bin directory, located at:

 

  /root/.cargo/bin

 

This can be modified with the CARGO_HOME environment variable.

 

Rustup metadata and toolchains will be installed into the Rustup

home directory, located at:

 

  /root/.rustup

 

This can be modified with the RUSTUP_HOME environment variable.

 

This path will then be added to your PATH environment variable by

modifying the profile files located at:

 

  /root/.profile

/root/.bash_profile

 

You can uninstall at any time with rustup self uninstall and

these changes will be reverted.

 

Current installation options:

 

 

   default host triple: x86_64-unknown-linux-gnu

     default toolchain: stable

               profile: default

  modify PATH variable: yes

 

1) Proceed with installation (default)

2) Customize installation

3) Cancel installation

>1

 

info: profile set to 'default'

info: default host triple is x86_64-unknown-linux-gnu

info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

info: latest update on 2020-03-12, rust version 1.42.0 (b8cedc004 2020-03-09)

info: downloading component 'cargo'

info: downloading component 'clippy'

info: downloading component 'rust-docs'

 12.0 MiB /  12.0 MiB (100 %)  11.1 MiB/s in  1s ETA:  0s

info: downloading component 'rust-std'

 17.1 MiB /  17.1 MiB (100 %)  10.9 MiB/s in  1s ETA:  0s

info: downloading component 'rustc'

 58.6 MiB /  58.6 MiB (100 %)  11.1 MiB/s in  5s ETA:  0s

info: downloading component 'rustfmt'

info: installing component 'cargo'

info: installing component 'clippy'

info: installing component 'rust-docs'

 12.0 MiB /  12.0 MiB (100 %)   7.4 MiB/s in  1s ETA:  0s

info: installing component 'rust-std'

 17.1 MiB /  17.1 MiB (100 %)  11.8 MiB/s in  1s ETA:  0s

info: installing component 'rustc'

 58.6 MiB /  58.6 MiB (100 %)  11.5 MiB/s in  5s ETA:  0s

info: installing component 'rustfmt'

info: default toolchain set to 'stable'

 

  stable installed - rustc 1.42.0 (b8cedc004 2020-03-09)

 

 

Rust is installed now. Great!

 

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH

environment variable. Next time you log in this will be done

automatically.

 

To configure your current shell run source $HOME/.cargo/env

[root@server ~]# source $HOME/.cargo/env

[root@server ~]# yum install libgit2 cmake git http-parser

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirror.kakao.com

 * extras: mirror.kakao.com

 * updates: mirror.kakao.com

Package git-1.8.3.1-21.el7_7.x86_64 already installed and latest version

Resolving Dependencies

--> Running transaction check

---> Package cmake.x86_64 0:2.8.12.2-2.el7 will be installed

--> Processing Dependency: libarchive.so.13()(64bit) for package: cmake-2.8.12.2-2.el7.x86_64

---> Package http-parser.x86_64 0:2.7.1-8.el7_7.2 will be installed

---> Package libgit2.x86_64 0:0.26.6-1.el7 will be installed

--> Running transaction check

---> Package libarchive.x86_64 0:3.1.2-14.el7_7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=================================================================================================================================================================================

 Package                                    Arch                                  Version                                           Repository                              Size

=================================================================================================================================================================================

Installing:

 cmake                                      x86_64                                2.8.12.2-2.el7                                    base                                   7.1 M

 http-parser                                x86_64                                2.7.1-8.el7_7.2                                   updates                                 29 k

 libgit2                                    x86_64                                0.26.6-1.el7                                      extras                                 429 k

Installing for dependencies:

 libarchive                                 x86_64                                3.1.2-14.el7_7                                    updates                                319 k

 

Transaction Summary

=================================================================================================================================================================================

Install  3 Packages (+1 Dependent package)

 

Total download size: 7.8 M

Installed size: 29 M

Is this ok [y/d/N]: y

Downloading packages:

(1/4): http-parser-2.7.1-8.el7_7.2.x86_64.rpm                                                                                                             |  29 kB  00:00:00     

(2/4): libgit2-0.26.6-1.el7.x86_64.rpm                                                                                                                    | 429 kB  00:00:00     

(3/4): libarchive-3.1.2-14.el7_7.x86_64.rpm                                                                                                               | 319 kB  00:00:00     

(4/4): cmake-2.8.12.2-2.el7.x86_64.rpm                                                                                                                    | 7.1 MB  00:00:00     

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                                                            8.0 MB/s | 7.8 MB  00:00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : libarchive-3.1.2-14.el7_7.x86_64                                                                                                                              1/4 

  Installing : http-parser-2.7.1-8.el7_7.2.x86_64                                                                                                                            2/4 

  Installing : libgit2-0.26.6-1.el7.x86_64                                                                                                                                   3/4 

  Installing : cmake-2.8.12.2-2.el7.x86_64                                                                                                                                   4/4 

  Verifying  : http-parser-2.7.1-8.el7_7.2.x86_64                                                                                                                            1/4 

  Verifying  : libgit2-0.26.6-1.el7.x86_64                                                                                                                                   2/4 

  Verifying  : cmake-2.8.12.2-2.el7.x86_64                                                                                                                                   3/4 

  Verifying  : libarchive-3.1.2-14.el7_7.x86_64                                                                                                                              4/4 

 

Installed:

  cmake.x86_64 0:2.8.12.2-2.el7                           http-parser.x86_64 0:2.7.1-8.el7_7.2                           libgit2.x86_64 0:0.26.6-1.el7                          

 

Dependency Installed:

  libarchive.x86_64 0:3.1.2-14.el7_7                                                                                                                                             

 

Complete!

[root@server ~]# git clone https://github.com/ogham/exa.git && cd exa

Cloning into 'exa'...

remote: Enumerating objects: 6, done.

remote: Counting objects: 100% (6/6), done.

remote: Compressing objects: 100% (6/6), done.

remote: Total 6903 (delta 0), reused 1 (delta 0), pack-reused 6897

Receiving objects: 100% (6903/6903), 3.24 MiB | 1.53 MiB/s, done.

Resolving deltas: 100% (4914/4914), done.

[root@server exa]# make install

cargo build --release --no-default-features --features "default"

    Updating crates.io index

  Downloaded glob v0.3.0

  Downloaded ansi_term v0.12.0

  Downloaded term_grid v0.1.7

  Downloaded locale v0.2.2

  Downloaded env_logger v0.6.2

  Downloaded users v0.9.1

  Downloaded natord v1.0.9

  Downloaded unicode-width v0.1.5

  Downloaded term_size v0.3.1

  Downloaded scoped_threadpool v0.1.9

  Downloaded number_prefix v0.3.0

  Downloaded zoneinfo_compiled v0.4.8

  Downloaded git2 v0.9.1

  Downloaded datetime v0.4.7

  Downloaded libc v0.2.60

  Downloaded num-traits v0.1.43

  Downloaded num_cpus v1.10.1

  Downloaded lazy_static v1.3.0

  Downloaded byteorder v1.3.2

  Downloaded log v0.4.7

  Downloaded termcolor v1.0.5

  Downloaded pad v0.1.5

  Downloaded iso8601 v0.1.1

  Downloaded url v1.7.2

  Downloaded libgit2-sys v0.8.1

  Downloaded humantime v1.2.0

  Downloaded atty v0.2.13

  Downloaded matches v0.1.8

  Downloaded percent-encoding v1.0.1

  Downloaded bitflags v1.1.0

  Downloaded pkg-config v0.3.14

  Downloaded regex v1.1.9

  Downloaded num-traits v0.2.8

  Downloaded idna v0.1.5

  Downloaded cfg-if v0.1.9

  Downloaded libz-sys v1.0.25

  Downloaded nom v1.2.4

  Downloaded cc v1.0.37

  Downloaded quick-error v1.2.2

  Downloaded autocfg v0.1.5

  Downloaded thread_local v0.3.6

  Downloaded unicode-bidi v0.3.4

  Downloaded unicode-normalization v0.1.8

  Downloaded memchr v2.2.1

  Downloaded utf8-ranges v1.0.3

  Downloaded aho-corasick v0.7.4

  Downloaded regex-syntax v0.6.8

  Downloaded ucd-util v0.1.3

  Downloaded smallvec v0.6.10

   Compiling libc v0.2.60

   Compiling autocfg v0.1.5

   Compiling pkg-config v0.3.14

   Compiling cc v1.0.37

   Compiling memchr v2.2.1

   Compiling smallvec v0.6.10

   Compiling unicode-width v0.1.5

   Compiling nom v1.2.4

   Compiling matches v0.1.8

   Compiling log v0.4.7

   Compiling regex v1.1.9

   Compiling cfg-if v0.1.9

   Compiling bitflags v1.1.0

   Compiling byteorder v1.3.2

   Compiling ucd-util v0.1.3

   Compiling lazy_static v1.3.0

   Compiling utf8-ranges v1.0.3

   Compiling percent-encoding v1.0.1

   Compiling quick-error v1.2.2

   Compiling termcolor v1.0.5

   Compiling glob v0.3.0

   Compiling number_prefix v0.3.0

   Compiling ansi_term v0.12.0

   Compiling natord v1.0.9

   Compiling scoped_threadpool v0.1.9

   Compiling unicode-bidi v0.3.4

   Compiling thread_local v0.3.6

   Compiling pad v0.1.5

   Compiling term_grid v0.1.7

   Compiling humantime v1.2.0

   Compiling regex-syntax v0.6.8

   Compiling unicode-normalization v0.1.8

   Compiling iso8601 v0.1.1

   Compiling num-traits v0.2.8

   Compiling aho-corasick v0.7.4

   Compiling locale v0.2.2

   Compiling atty v0.2.13

   Compiling term_size v0.3.1

   Compiling users v0.9.1

   Compiling num_cpus v1.10.1

   Compiling idna v0.1.5

   Compiling num-traits v0.1.43

   Compiling datetime v0.4.7

   Compiling url v1.7.2

   Compiling zoneinfo_compiled v0.4.8

   Compiling exa v0.9.0 (/root/exa)

   Compiling libz-sys v1.0.25

   Compiling libgit2-sys v0.8.1

   Compiling env_logger v0.6.2

   Compiling git2 v0.9.1

    Finished release [optimized] target(s) in 1m 14s

install -m755 -- target/release/exa "/usr/local/bin/"

install -dm755 -- "/usr/local/bin/" "/usr/local/share/man/man1/"

install -m644  -- contrib/man/exa.1 "/usr/local/share/man/man1/"

[root@server exa]# 

Posted by 훅크선장
, |

OpenWRT 18.06 버전에서 원격 관리 목적으로 SSH 포트를 하나 열어놓았더니, 온 세상에서 계속 로그인 시도를 합니다.

물론 당연히 패스워드 인증은 안하도록 설정되어 있지만, 그래도 너무 많은 시도가 있기에 그러한 무차별 대입 공격(Brute Force)를 어느정도 걸러내기 위하여, iptables 룰을 이용해보기도 하였습니다.

 

인터넷 검색을 통하면, 몇 개의 예제가 나오는데, iptables 버전이 업데이트 되면서, 몇 몇 키워드가 바뀌었습니다. 

특히 -m state, --state NEW 나 -m recent 옵션에서 에러가 나옵니다.

 

일단 -m recent 옵션을 쓰고 싶으면, kmod-ipt-conntrack-extra 와 iptables-mod-conntrack-extra 패키지가 설치되어 있어야 합니다.

다음, -m state 옵션은 -m conntrack 옵션으로 변경되었으며, --state 옵션은 --ctstate 옵션으로 이름이 변경되었습니다.

 

다음과 같은 방식으로 설정파일에 추가하면 됩니다.

※ 주의할 점은 외부에 포트를 열어주는 rule이 먼저 존재하고, 그 다음에 conntrack를 사용하는 rule 두 개를 추가해야 한다는 것입니다.

※ rule 중에서 연결을 ACCEPT 하는 유사한 설정이 두 개가 있다고 해서, 합쳐서 사용할 수 없습니다. 하나는 input 룰이고, 다른 하나는 forward 룰이기 때문인 것 같습니다. 둘이 합치게 되면, 그냥  forward 룰만 남기 때문에, input 룰이 없어서 아예 접속이 안됩니다.

 

config rule
        option target 'ACCEPT'
        option src 'wan'
        option dest_port '22'
        option name 'Allow-SSH'
        option proto 'tcp'

config rule
        option target 'ACCEPT'
        option src 'wan'
        option dest '*'
        option dest_port '22'
        option name 'SSH_CheckAccept'
        option proto 'tcp'
        option family 'ipv4'
        option extra '-m conntrack --ctstate NEW -m recent --set --name SSH --rsource'

config rule
        option src 'wan'
        option name 'SSH_CheckDrop'
        option family 'ipv4'
        option proto 'tcp'
        option dest '*'
        option dest_port '22'
        option target 'DROP'
        option extra '-m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 3 --name SSH --rttl --rsource'

 

위의 세 개 룰을 그대로 쓰셔도 됩니다. 만약  ssh 데몬 포트번호가 22번이 아니면, 그 포트번호만 고치면 바로 사용할 수 있습니다.

--name SSH 에서 SSH 라는 것은 룰셋의 이름으로 원하는 대로 바꿔서 쓰면 됩니다.

-seconds 60 --hitcount 3 부분이 중요한데, 이것은 60초 즉 1분 동안에 3번이상의 잘못된 로그인 시도가 이루어지면, 그 IP에서는 더이상 네트워크로 접근하지 못하도록 한다는 것입니다. 시간과 횟수를 잘 고려해서 설정하면 됩니다.

※ 요즘 SSH Brute Force의 양상을 보면, IP주소도 자주 바꾸고 로그인 시도도 꽤 긴 시간동안에 다시 하는 것 같아서, 설정시에 잘 고려해야 합니다. 제가 본 양상으로는 5분(300초)동안에 2번 이상의 잘못된 로그인 시도가 있으면, 바로 막는 것이 맞는 것 같았습니다.

 

참조 : https://www.rackaid.com/blog/how-to-block-ssh-brute-force-attacks/

 

Block SSH Brute Force Attacks with IPTables

Block ssh brute force attacks using some simple IPTables rules. This will rate-limit incoming SSH attacks and mitigate the brute force attack.

www.rackaid.com

Posted by 훅크선장
, |