centos 7.2에서 2017.1.25부터 docker yum 설치가 실패하고 있다. 


다음 의존성 때문인 것 같다. 


libsemanage-2.5-8.el7.x86_64 conflicts selinux-policy-base < 3.13.1-66\\n--> Finished Dependency Resolution\\n You could try using --skip-broken to work around the problem\\n You could try running: rpm -Va --nofiles --nodigest



문제 해결이 쉽지 않아 os를 7.4로 올리니 정상적으로 docker를 설치할 수 있었다..

Posted by '김용환'
,



ubuntu에서 apt-get update가 행이 걸린다면 다음 로그를 보거나 strace로 확인한다. 


$ sudo vi /var/log/apt/term.log

$ sudo vi /var/log/dpkg.log

$ sudo vi /var/log/apt/history.log

$ strace apt-get update


잘못된 주소의 파일이 있거나, mirroring에 실패한 경우가 있을 수 있다. 



Posted by '김용환'
,



네임스페이스를 줄 수 있다. 



$ ip netns add ns1



또 실행하면 실제 network namespace의 위치를 알려주는 에러(?!)가 발생한다.


$ ip netns add ns1

Cannot create namespace file "/var/run/netns/ns1": File exists



확인한다.


$ ip netns

ns1

$ ip netns list

ns1

$ ip netns list ns1

ns1



삭제하려면 다음 커맨드를 실행한다. 


$ ip netns delete ns1

$ ip netns list




하나의 가상 ethernet을 생성하고 peer로 하나 생성한다.


$ ip link add vireth0 type veth peer name virteth1

$ ip link list

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 50000

    link/ether fa:16:3e:77:ea:d4 brd ff:ff:ff:ff:ff:ff

3: virteth1@vireht0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

    link/ether c2:d7:7a:23:90:7b brd ff:ff:ff:ff:ff:ff

4: vireht0@virteth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

    link/ether 56:48:fa:8d:53:58 brd ff:ff:ff:ff:ff:ff

    

    


만약 실수 했다면 ip link del로 삭제할 수 있다. 


$ ip link del vireth0


네트워크 namespace 에는 단지 virtual Ethernet(veth)만 할당할 수 있다.


이전에 추가한 네임스페이스에 vireth0을 연동한다. 


$ ip link set vireth0 netns ns1



ip link list를 실행하면 vireth0이 안보인다. 글로벌 공간에서 ns1로 이동했다. virteth1만 남아 있다. 


$ ip link list

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 50000

    link/ether fa:16:3e:77:ea:d4 brd ff:ff:ff:ff:ff:ff

3: virteth1@if12: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

    link/ether aa:35:8b:aa:ae:62 brd ff:ff:ff:ff:ff:ff link-netnsid 0

    



ip netns list를 실행하면 먼가가 바뀌었다. id가 0이다. 


$ ip netns list

ns1 (id: 0)



ns1에서 ip link list를 실행한다. 여기에 vireth0이 있다. 


$ ip netns exec ns1 ip link list

1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

3: vireth0@if11: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

    link/ether 52:eb:a4:5b:33:d3 brd ff:ff:ff:ff:ff:ff link-netnsid 0

    

    



새로운 ip를 부여한다. 


$ ip netns exec ns1 ifconfig vireth0 192.168.1.1/24 up



확인한다. DOWN 상태에서 LOWERLAYERDOWN 상태로 바뀌었다. 


$ ip netns exec ns1 ip link list

1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

12: vireth0@if11: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN mode DEFAULT group default qlen 1000

    link/ether 52:eb:a4:5b:33:d3 brd ff:ff:ff:ff:ff:ff link-netnsid 0

    


ip 주소를 확인하면 192.168.1.1로 되어 있음을 확인할 수 있다. 


$ ip netns exec ns1 ip addr list

1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

12: vireth0@if11: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000

    link/ether 52:eb:a4:5b:33:d3 brd ff:ff:ff:ff:ff:ff link-netnsid 0

    inet 192.168.1.1/24 brd 192.168.1.255 scope global vireth0

       valid_lft forever preferred_lft forever




ns1의 vireth0과 글로벌의 virteth1을 서로 짝이라서 virteth1의 네트워크를 설정한다. 


$ ifconfig virteth1 192.168.1.2/24 up


이제 글로벌영역에서 가상 네임 네트워크 ns1으로 ping을 실행할 수 있다. 


$ ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.043 ms

64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.039 ms



Posted by '김용환'
,


cp (rm, mv 포함) 커맨드 실행시 파일 개수가 너무 많으면, 매개 변수 개수 제한 에러가 발생한다.


$ cp /src/dir/* /dst/dir/

-bash: /bin/cp: Argument list too long



해결 방법으로는 다음 방법이 있을 것 같다. 


1. rsync


2. find 


find /src/dir/ -type f -exec cp {} /dst/dir \;



3. ls | xargs


4. for ls..




Posted by '김용환'
,

numactl 커맨드

unix and linux 2017. 10. 19. 22:06


numa 아키텍처(Non-Uniform Memory Access, NUMA)는 멀티프로세서 시스템에서 사용되고 있는 컴퓨터 메모리 설계 방법중의 하나로, 메모리에 접근하는 시간이 메모리와 프로세서간의 상대적인 위치에 따라 달라진다. NUMA구조에서 프로세서는 자기의 로컬 메모리에 접근할 때가 원격 메모리에 접근할 때보다 더 빠르다. 원격 메모리는 다른 프로세서에 연결되어 있는 메모리를 말하고 로컬 메모리는 자기 프로세서에 연결되어 있는 메모리를 말한다.


https://ko.wikipedia.org/wiki/%EB%B6%88%EA%B7%A0%EC%9D%BC_%EA%B8%B0%EC%96%B5_%EC%9E%A5%EC%B9%98_%EC%A0%91%EA%B7%BC



numa를 잘 활용해야 훨씬 빠르게 메모리를 관리할 수 있다. 




https://github.com/numactl/numactl


numa 아키텍처에서 지원하는 간단한 AP로서 numa 아키텍처에서 동작하는 java daemon을 실행할 때 자주 사용될 수 있다. elasticsearch나 cassandra에 사용한다면 성능 효과를 얻을 수 있다. 




https://www.slideshare.net/slidunder/numa-and-java-databases





numactl은 공유 메모리 또는 파일에 대한 정책을 지정할 수 있다. 





예를 들어 간단한 numactl 커맨드가 있다.


$ numactl --interleave=all /home/www/elasticsearch-5.3/bin/elasticsearch -d


interleave 모드를 사용하면 라운드 로빈으로 메모리를 노드에 할당하게 한다. numa 아키텍처를 활용해 빠르게 접근하게 한다!





https://linux.die.net/man/8/numactl



--interleave=nodes, -i nodes
Set a memory interleave policy. Memory will be allocated using round robin on nodes. When memory cannot be allocated on the current interleave target fall back to other nodes. Multiple nodes may be specified on --interleave, --membind and --cpunodebind. You may specify "all", which means all nodes in the current cpuset. nodes may be specified as N,N,N or N-N or N,N-N or N-N,N-N and so forth. Relative nodes may be specifed as +N,N,N or +N-N or +N,N-N and so forth. The + indicates that the node numbers are relative to the process' set of allowed nodes in its current cpuset. A !N-N notation indicates the inverse of N-N, in other words all nodes except N-N. If used with + notation, specify !+N-N.



자바와 NUMA 아키텍처와 관련된 설명은 다음을 참조한다.

https://www.slideshare.net/slidunder/numa-and-java-databases


이 슬라이드는 numctl과 cassandra 간의 조심스러움을 표현하고 있다. 


NUMA and Java Databases from Raghavendra Prabhu






Posted by '김용환'
,


Intel VT-X option이 BIOS에서 활성화되는지 리눅스에서 확인하는 방법이다. 



$ sudo apt-get install -y cpu-checker



$ kvm-ok

INFO: /dev/kvm exists

KVM acceleration can be used


사용할 수 있다!!




해당 패키지로 bios에서 NX 비트를 지원하는지 확인할 수 있다. (https://ko.wikipedia.org/wiki/NX_%EB%B9%84%ED%8A%B8)


$ check-bios-nx

modprobe: ERROR: could not insert 'msr': Operation not permitted



'unix and linux' 카테고리의 다른 글

Argument list too long 해결하기  (0) 2017.10.20
numactl 커맨드  (0) 2017.10.19
tcpCurrEstab  (0) 2017.09.19
유닉스/리눅스에서 위험한 명령어 : rm, crontab  (0) 2017.09.15
[ssh] tunneling 예제  (0) 2017.09.08
Posted by '김용환'
,

tcpCurrEstab

unix and linux 2017. 9. 19. 17:35




장비의 tcp 현재 전체 커넥션 개수를 snmp의 tcpCurrEstab를 통해 쉽게 얻을 수 있다. 


ESTABLISHED와 CLOSE_WAIT TCP 커넥션 개수를 얻는다. 


http://www.oid-info.com/get/1.3.6.1.2.1.6.9


"The number of TCP connections for which the current state is either ESTABLISHED or CLOSE-WAIT." 




Posted by '김용환'
,

ubuntu 16에서 

root권한으로 실수할만한 예제를 테스트해봤다.


다행히 rm -rf /은 fail safe되어 안전하다. 



# rm -rf /

rm: it is dangerous to operate recursively on '/'

rm: use --no-preserve-root to override this failsafe





그러나 crontab은 여전히 그대로이다.. -r 사용하면 다 날아감..


$ crontab -l


* * * * * echo "hello"

$ crontab -r

$ crontab -l

no crontab for deploy



Posted by '김용환'
,



ssh tunning을 통해 내부 망에서 외부 망으로 연결할 수 있다. 관련 예제를 소개한다.



A 서버에서 B 서버를 통해 외부 망으로 접근할 수 있도록 터널링하는 예제이다. -v는 내부 구조를 알기 위해..



$ ssh -v -L 61514:rsync.apache.org:873 deploy@tunnel.interal.google.io  -i /root/.ssh/repo

 

 OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014

debug1: Reading configuration data /root/.ssh/config

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 19: Applying options for *

debug1: Connecting to tunnel.interal.google.io [1.1.1.1] port 22.

debug1: Connection established.

debug1: permanently_set_uid: 0/0

debug1: identity file /root/.ssh/repo type -1

debug1: identity file /root/.ssh/repo-cert type -1

debug1: Enabling compatibility mode for protocol 2.0

debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8

debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2

debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000

debug1: SSH2_MSG_KEXINIT sent

debug1: SSH2_MSG_KEXINIT received

debug1: kex: server->client aes128-ctr hmac-sha1-etm@openssh.com none

debug1: kex: client->server aes128-ctr hmac-sha1-etm@openssh.com none

debug1: sending SSH2_MSG_KEX_ECDH_INIT

debug1: expecting SSH2_MSG_KEX_ECDH_REPLY

debug1: Server host key: ECDSA

debug1: Host 'tunnel.interal.google.io' is known and matches the ECDSA host key.

debug1: Found key in /root/.ssh/known_hosts:19

debug1: ssh_ecdsa_verify: signature correct

debug1: SSH2_MSG_NEWKEYS sent

debug1: expecting SSH2_MSG_NEWKEYS

debug1: SSH2_MSG_NEWKEYS received

debug1: SSH2_MSG_SERVICE_REQUEST sent

debug1: SSH2_MSG_SERVICE_ACCEPT received

debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

debug1: Next authentication method: gssapi-keyex

debug1: No valid Key exchange context

debug1: Next authentication method: gssapi-with-mic

debug1: Next authentication method: publickey

debug1: Trying private key: /root/.ssh/tunnel

debug1: key_parse_private2: missing begin marker

debug1: read PEM private key done: type RSA

debug1: Authentication succeeded (publickey).

Authenticated to tunnel.interal.google.io ([1.1.1.1]:22).

debug1: Local connections to LOCALHOST:61514 forwarded to remote address rsync.apache.org:873

debug1: Local forwarding listening on 127.0.0.1 port 61514.

debug1: channel 0: new [port listener]

debug1: Local forwarding listening on ::1 port 61514.

bind: Cannot assign requested address

debug1: channel 1: new [client-session]

debug1: Requesting no-more-sessions@openssh.com

debug1: Entering interactive session.

debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0

debug1: Sending environment.

debug1: Sending env LANG = en_US.UTF-8

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)


 * Documentation:  https://help.ubuntu.com

 * Management:     https://landscape.canonical.com

 * Support:        https://ubuntu.com/advantage

Last login: Thu Sep  7 23:49:54 2017



ps -ef로 보면 연결이 잘 되었다는 것을 확인할 수 있다. 


실제 소켓 단에서도 잘 연결되었는지 확인하려면 A 서버, B 서버에서 소켓을 확인한다.



A 서버에서 확인하기


$ netstat -anp

tcp        0      0 1.1.1.1:22      3.3.3.3:61518    ESTABLISHED -





B 서버에서 확인하기   


$ netstat -tpln

(No info could be read for "-p": geteuid()=1000 but you should be root.)

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 127.0.0.1:61514         0.0.0.0:*               LISTEN      -




Posted by '김용환'
,



백업용으로 git에 큰 파일(압축 파일)을 올릴 때 git 관리자의 정책으로 인해 업로드 실패가 발생할 수 있다. 


용량을 50m 단위로 줄여서 압축하려면 -s 옵션을 추가한다. 기본 값은 m이고, 나머지는 g, k 이렇게 사용하면 된다.


$ zip -r -s 50 launch.zip launch/  --out launch-sp



Posted by '김용환'
,