반응형

Ubuntu 22.04에서는 VPN 설정하는 것이 아주 쉽다.

아래의 Network Setting 화면에서 [ VPN ] 항목 옆에 있는 + 버튼을 누르고 VPN  Server 정보를 입력하기만 하면 끝이다.

 

 

 

 

위와 같이 설정하고, VPN 연결을 활성화하는 버튼을 누른다.

 

 

 

그런데 VPN 연결을 몇시간 사용하다보면, 간혹 모르는 사이에 끊어지는 경우가 있다.

그런 경우 아래와 같은 nmcli CLI 명령을 crontab에 추가하고 1시간 간격으로 자동 실행하도록 하면 편하다.

 

$  nmcli con up id "VPN1"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/24)
$

 

 

알아두면 좋은 명령어 예시

 

##
## VPN 연결 정보 조회
##

$  nmcli con
NAME                UUID                                  TYPE       DEVICE      
VPN1                b0838d77-ae82-4573-a15b-fba0f8884594  vpn        enp4s0      
Wired connection 1  bef5ca16-baca-35e4-8259-e5dbbacbe1c0  ethernet   enp4s0      
$


$  nmcli con down id VPN1
반응형

 

##
## Cluter Network 설정 정보 보기
##

$ kubectl get network.config/cluster -o jsonpath='{.status}{"\n"}'
{"clusterNetwork":[{"cidr":"10.128.0.0/14","hostPrefix":23}],"clusterNetworkMTU":1450,"networkType":"OpenShiftSDN","serviceNetwork":["172.30.0.0/16"]}


##
## CNI Network Type 설정 정보 보기
##

$ oc get network.config/cluster -o jsonpath='{.status.networkType}{"\n"}'
OpenShiftSDN

$
반응형

 


 

내가 자주 사용하는 형태는 아래와 예제와 같고, find 명령에 대한 자세한 내용은 아래 Web Docs를 참고할 것 !!!

 

$ find /proc -maxdepth 2 -name "comm" -print

$ find /proc -maxdepth 2 -name "comm" -exec cat {} \;

$ find . -maxdepth 2 -name "comm" -type f -mmin +1 -print | xargs grep kubelet
./4305/comm:kubelet
$

 

 

find 명령과 xargs 명령을 조합해서 사용하려면 많은 내용을 길게 입력해야 하는데, 아래와 같이 미리 .bashrc 파일에 function으로 등록하면 쉽게 이용할 수 있다.

 

$ cat .bashrc

... 중간 생략 ...

##
## .c 또는 .h 파일에서 특정 문자열을 찾는 함수
##
function find_xargs() {
    find . -name "*\.[ch]" -type f  -print | xargs grep $1
}

... 중간 생략 ...


##
## 위에서 .bashrc 파일에 추가한 내용을 현재 shell 환경에 적용하기
##

$ . .bashrc


## --------------------------------------------------------------

##
## 위에서 작성한 find_xargs 명령을 이용하여 Source code file에서 ip_hdr 함수를 찾는 예제
##

$ find_xargs  ip_hdr

./net/dccp/ipv6.c:		newnp->mcast_hops  = ip_hdr(skb)->ttl;
./net/dccp/ipv4.c:	return secure_dccp_sequence_number(ip_hdr(skb)->daddr,
./net/dccp/ipv4.c:					   ip_hdr(skb)->saddr,
./net/dccp/ipv4.c:	newinet->mc_ttl	   = ip_hdr(skb)->ttl;
./net/dccp/ipv4.c:	const struct iphdr *iph = ip_hdr(skb);
./net/dccp/ipv4.c:	rxiph = ip_hdr(rxskb);
./net/dccp/ipv4.c:	sk_rcv_saddr_set(req_to_sk(req), ip_hdr(skb)->daddr);
./net/dccp/ipv4.c:	sk_daddr_set(req_to_sk(req), ip_hdr(skb)->saddr);
./net/dccp/ipv4.c:	iph = ip_hdr(skb);
./net/sched/act_ipt.c:	iph = ip_hdr(skb);
./net/sched/act_ctinfo.c:		dscp = ipv4_get_dsfield(ip_hdr(skb)) & ~INET_ECN_MASK;
./net/sched/act_ctinfo.c:				ipv4_change_dsfield(ip_hdr(skb),
./net/sched/act_nat.c:	iph = ip_hdr(skb);
./net/sched/act_nat.c:		iph = ip_hdr(skb);
./net/sched/act_ct.c:	iph = ip_hdr(skb);

... 중간 생략 ...

$

 


 

아래 Web docs에 아주 자세한 설명과 예제가 있다.

 

How to Use the Linux xargs Command

 

반응형

https://engineer-mole.tistory.com/235#:~:text=w%20%ED%8C%8C%EC%9D%BC%EB%AA%85%20%23%20%ED%98%84%EC%9E%AC%EC%9D%98%20%ED%8C%A8%ED%84%B4,%EB%B3%80%ED%99%98%20%EB%AC%B8%EC%9E%90%EB%A1%9C%20%EB%B3%80%ED%99%98%ED%95%9C%EB%8B%A4.

 

[Linux] sed 커맨드 상황별 사용법

쉘에서 데이터를 가공할 때 sed를 자주 사용하게 되는데, 상황에 따른 사용예를 정리한 포스팅이다. sed 커맨드는 Linux/Unix/BSD/OSX의 경우 기본적으로 설치되어 있으므로, sed 커맨드를 사용하기 위

engineer-mole.tistory.com

 

반응형

빠르게 개념을 이해하고, Git 명령을 사용하고 싶다면 이 Web Docs를 읽어 보기 !!!

https://rogerdudler.github.io/git-guide/index.ko.html

 

git - 간편 안내서 - 어렵지 않아요!

 

rogerdudler.github.io

 

 

NULab에서 만든 Git 가이드 북.

https://backlog.com/git-tutorial/kr/

 

누구나 쉽게 이해할 수 있는 Git 입문~버전 관리를 완벽하게 이용해보자~ | Backlog

누구나 쉽게 알 수 있는 Git에 입문하신 것을 환영합니다. Git을 사용해 버전 관리를 할 수 있도록 함께 공부해봅시다!

backlog.com

 

 

Git 개발 커뮤니티에서 직접 만든 Git Book

https://git-scm.com/book/ko/v2/

 

Git - Book

 

git-scm.com

 

반응형

 

아래와 같이 `oc edit` 명령으로 insecureRegistries 항목에 Container Image Registry 주소를 추가한다.

 

$  oc edit image.config.openshift.io/cluster

... 중간 생략 ...

spec:
  registrySources:
    insecureRegistries:
    - aaa.cloud.net:8080
    - bbb.cloud.net:5000

... 중간 생략 ...

$

 

그리고 kubernetes node에서 사람이 podman 명령어를 직접 사용하는 경우도 있기 때문에 아래와 같이 /etc/containers/registres.conf 파일에도 registry 주소를 추가한다.

 

##
## File Path:  /etc/containers/registries.conf
##

$  cat  /etc/containers/registries.conf

... 중간 생략 ...

[registries.insecure]
registries = ['aaa.registry.net:8080', 'bbb.registry.net:8080']

... 중간 생략 ...

$
반응형

 

 

작성일: 2024년 4월 11일

 

 

Go 언어를 사용해서 CLI를 개발할 일이 생겼는데, 기존 C언어로 개발하던 개발 습성 때문인지 CLI를 개발할 생각하니까 귀찮고 짜증부터 났다.

Java처럼 CLI를 쉽게 개발할 수 있는 Go Package가 있지 않을까 싶어서 구글링을 해보니, 역시나 GoLang은 개발 도구나 Library package가 훌륭하다는 것을 또 한번 느끼게 되었다.

 

일단 딱 눈에 들어온 것은 Cobra library였다.

https://pkg.go.dev/github.com/spf13/cobra#section-readme

 

cobra package - github.com/spf13/cobra - pkg.go.dev

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used. Deprecated: Use SetOut and/or SetErr instead

pkg.go.dev

 

Cobra is a library providing a simple interface to create powerful modern CLI interfaces similar to git & go tools.
Cobra is also an application that will generate your application scaffolding to rapidly develop a Cobra-based application.

 

위 Cobra Web Docs 문서에서 소개하는 것처럼 Cobra는 library이면서, application scaffoling을 만들어주는 개발 도구이다.

그래서 단순하게 library reference만 읽고 사용법을 익히는 것이 아니라 Cobra 도구를 이용해서 scaffolding을 만들고, 그 scaffolding 안에서 나의 logic을 추가해야 한다.

Cobra의 개발 절차만 잘 따라하면, 시간을 팍팍 줄여가면서 CLI를 붕어빵 찍어내듯이 만들 수 있을 것 같은 느낌적인 느낌이 들었다.

그럼 그 개발 절차를 자세히 들여다 보면 이렇다.

 

 

https://www.youtube.com/watch?v=so3VZwdWcBg&t=4s 

 

 

 

 

 

 

Reference

https://yjwang.tistory.com/137

 

[Go-lang] Cobra를 사용해서 cli 프로그램 개발

cobra 사용해서 cli tool을 개발해보고자 한다. 아무래도 Infra 작업을 하다보면 cli tool이 있으면 편하겠다는 생각을 하곤하는데 생각한 김에 만들어보고자합니다. cobra 프로젝트는 kubectl에서도 사용

yjwang.tistory.com

 

 

https://www.sktenterprise.com/bizInsight/blogDetail/dev/2755

 

[Golang] Cobra를 이용한 CLI 유틸리티 만들기 | 개발자 Story | SKT Enterprise

현대사회에서 대부분의 유저들은 휴대폰이나 컴퓨터 화면을 통해 쉽고 편한 GUI(Graphic User Interface)를 선호합니다. 그러나 GUI로는 채우기 힘든 여전히 CLI(Command Line Interface)를 선호하는 분야도 많

www.sktenterprise.com

 

https://nangman14.tistory.com/97

 

Go로 커맨드를 실행할 수 있는 CLI를 구현해보자 (With Cobra)

CLI(Command Line Interface)란 터미널을 통해 사용자와 컴퓨터가 상호작용하는 인터페이스를 말합니다. CLI는 그래픽을 통해 직관적으로 사용할 수 있는 GUI(Graphic User Interface)와 달리 명령줄로만 입력을

nangman14.tistory.com

 

 

 

 

기타: 다른 방식의 CLI 개발 예제

 

https://dev.to/tidalmigrations/interactive-cli-prompts-in-go-3bj9

 

Interactive CLI prompts in Go

Tidal Migrations 💓 CLI applications Do you like CLI applications? We love them! At Tidal...

dev.to

 

 

https://github.com/manifoldco/promptui

 

GitHub - manifoldco/promptui: Interactive prompt for command-line applications

Interactive prompt for command-line applications. Contribute to manifoldco/promptui development by creating an account on GitHub.

github.com

 

+ Recent posts