manywaypark's Blog
개발, 검색, 함수

Ubuntu에서 Nvidia driver 깔기

장치가 인식되어있는지 확인:

$ ubuntu-drivers devices

driver 자동 설치:

$ sudo ubuntu-drivers autoinstall


참조 링크에 더 다양한 방법이 있다.


ref: https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-18-04-bionic-beaver-linux


 happy hackin'

ssh reverse tunneling

tips & tricks/Linux/Unix 2018. 3. 12. 16:01 by manywaypark

기본적으로 ssh, autossh 등을 사용하면 됨. 

systemd 내에서 autossh를 쓸 경우는 좀 tricky한 상황이 생기는 듯 (portforwarding 환경에서는 port forwading에 실패했을 경우 재시작할 때 제대로되지 않는다.

autossh는 자동재시작 등의 기능이 있는데 이것은 systemd에서 제공하는(아주 잘 하는) 기능이다. 두개를 섞으면 좀 이상해지는 것으로 보인다.

좀 검색을 해보니 ssh + systemd가 제대로 잘 동작하는 것으로 보인다. 

좀더 시간을 두고 해결하는 것도 고려해보자.


/etc/systemd/system/secure-tunnel@.service 파일:


[Unit]

Description=Setup a secure tunnel to %I

After=network.target


[Service]

Environment="LOCAL_ADDR=localhost"

EnvironmentFile=/etc/default/secure-tunnel@%i

ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -NR ${LOCAL_PORT}:localhost:${REMOTE_PORT} ${TARGET} -p ${TARGET_PORT}


# Restart every >2 seconds to avoid StartLimitInterval failure

RestartSec=5

Restart=always


[Install]

WantedBy=multi-user.target


/etc/default/secure-tunnel@jupiter 파일:


TARGET=jupiter

TARGET_PORT=2222

LOCAL_PORT=20022

REMOTE_PORT=22


부팅시 실행되게 활성화 및 시작:

systemctl enable secure-tunnel@jupiter.service

systemctl start secure-tunnel@jupiter.service

현재 상태보기:

systemctl status secure-tunnel@jupiter.service

상태 연속으로 보기:

journalctl -f -u secure-tunnel@jupiter.service


refs:

http://system-monitoring.readthedocs.io/en/latest/ssh.html

https://gist.github.com/thomasfr/9707568 -> autossh + systemd

https://gist.github.com/drmalex07/c0f9304deea566842490 -> 최종적으로 (약간 수정해서) 내가 사용한 방법 (ssh + systemd)

https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units -> systemd 관련 상세 설명


2018-03-23 추가:
가끔 network configuration을 변경하면 재접속이 안되는 경우가 발생하는데...
아래와 같은 로그가 찍히면서 재접속 시도가 계속 실패한다.

~$ sudo journalctl -f -u secure-tunnel@tmp01.service
[sudo] password for xxxxxx: 
-- Logs begin at Fri 2018-03-23 16:45:46 KST. --
Mar 23 16:55:37 teevr-lt2 systemd[1]: secure-tunnel@tmp01.service: Failed with result 'exit-code'.
Mar 23 16:55:42 teevr-lt2 systemd[1]: secure-tunnel@tmp01.service: Service hold-off time over, scheduling restart.
Mar 23 16:55:42 teevr-lt2 systemd[1]: Stopped Setup a secure tunnel to tmp01.
Mar 23 16:55:42 teevr-lt2 systemd[1]: Started Setup a secure tunnel to tmp01.
Mar 23 16:55:42 teevr-lt2 ssh[2679]: Error: remote port forwarding failed for listen port 1907
Mar 23 16:55:42 teevr-lt2 systemd[1]: secure-tunnel@tmp01.service: Main process exited, code=exited, status=255/n/a
Mar 23 16:55:42 teevr-lt2 systemd[1]: secure-tunnel@tmp01.service: Unit entered failed state.
Mar 23 16:55:42 teevr-lt2 systemd[1]: secure-tunnel@tmp01.service: Failed with result 'exit-code'.

~$ sudo netstat -plant | grep 1907
tcp        0      0 127.0.0.1:1907          0.0.0.0:*               LISTEN      9949/sshd: xxxxxx
tcp6       0      0 ::1:1907                :::*                    LISTEN      9949/sshd: xxxxxx
tcp6      42      0 ::1:1907                ::1:40842               CLOSE_WAIT  9949/sshd: xxxxxx
tcp6       0      0 ::1:1907                ::1:40838               CLOSE_WAIT  9949/sshd: xxxxxx
tcp6      42      0 ::1:1907                ::1:40848               CLOSE_WAIT  9949/sshd: xxxxxx
tcp6      42      0 ::1:1907                ::1:40844               CLOSE_WAIT  9949/sshd: xxxxxx
tcp6      42      0 ::1:1907                ::1:40840               CLOSE_WAIT  9949/sshd: xxxxxx

접속을 이미 물고 있는 상태(LISTEN)에서 계속 재접속(port bind)을 시도하는 것이었다.
문제는 설정의 ServerAliveInterval이 60초로 설정되어 있고, 재접속시도는 5초만에 하게한 것(RestartSec) 이었다. Orz.
RestartSec을 최소한 ServerAliveInterval 보다는 길게 설정해야한다.

아래 처럼 변경후에 다른 subnet으로 옮기거나해도 잘 동작했다.
ServerAliveInterval=7
RestartSec=10

라고 쓸려고 했으나...
ClientAliveCountMax(default가 3)도 고려해야하므로, ServerAliveInterval * 3 보다 큰 값으로 RestartSec을 설정하면 잘 될거같은데...
실패하는 경우가 생긴다.

그냥 접속안되면 netstat 때려보고 port 물고 있는 pid를 죽이자!

happy hackin'

가끔은 자기 자신이 어디서 로딩되었는지를 알아야만 할 때가 있다.

static initialization 과정에서 함수의 주소로 알아내는 방법이 있다.

#define _GNU_SOURCE

#include <dlfcn.h>

#include <stdio.h>


__attribute__((constructor))

void on_load(void) {

  Dl_info dl_info;

  dladdr((void *)on_load, &dl_info);

  fprintf(stderr, "module %s loaded\n", dl_info.dli_fname);

}

좀더 자세한건 man 3 dladdr


refs: 

http://stackoverflow.com/questions/1681060/library-path-when-dynamically-loaded

https://cseweb.ucsd.edu/~gbournou/CSE131/the_inside_story_on_shared_libraries_and_dynamic_loading.pdf

the_inside_story_on_shared_libraries_and_dynamic_loading.pdf

happy hackin'

설치:

현재 우분투 14.04에서 기본 최신 gcc인 4.8을 쓰고 있는데 4.9를 쓸 일이 생겼다.

소스에서 빌드해서 써도 되지만 시간이 좀 걸리므로, PPA를 활용해서 설치한다.

⟫ sudo su -

# apt-get install build-essential

# add-apt-repository ppa:ubuntu-toolchain-r/test

# apt-get update

# apt-get install gcc-4.9 g++-4.9 cpp-4.9


설정:

기본 toolchain을 간단히 변경하기 위해 update-alternatives를 썼다.

참고 링크의 여러 방법을 참고해서 제일 간단한 방법을 하나 만들어보았다.

요지는 gcc가 변경될 때 g++, cpp도 함께 변경되게 만든 것이다.

 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 --slave /usr/bin/cpp cpp-bin /usr/bin/cpp-4.9

 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 --slave /usr/bin/cpp cpp-bin /usr/bin/cpp-4.8

cpp 대신 cpp-bin을 쓴 이유는 cpp는 우분투 시스템에서 기본적으로 생성되는 것이라 변경할 경우 스크립트가 깨질 수 있다고 두번째 참고 링크에 나옴.


확인:

제대로 변경되는지 확인해보자

⟫ sudo update-alternatives --set gcc /usr/bin/gcc-4.8          

update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in manual mode

⟫ gcc --version

gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

......

4 ⟫ g++ --version

g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

......

⟫ cpp --version

cpp (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

......

⟫ sudo update-alternatives --set gcc /usr/bin/gcc-4.9

update-alternatives: using /usr/bin/gcc-4.9 to provide /usr/bin/gcc (gcc) in manual mode

⟫ gcc --version

gcc (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3

......

⟫ g++ --version

g++ (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3

......

⟫ cpp --version

cpp (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3

......


refs:

http://askubuntu.com/questions/466651/how-do-i-use-the-latest-gcc-on-ubuntu

http://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu/9103299


happy hackin'


Load Average? IO wait?

tips & tricks/Linux/Unix 2016. 7. 27. 13:50 by manywaypark

Load Average:

CPU Load에 관한 알기쉬운 설명:

http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

http://www.howtogeek.com/194642/understanding-the-load-average-on-linux-and-other-unix-like-systems/

요약하자면, 

CPU Load 값은 코어당 1이 full인데  70%이하 정도로 유지 하는 것이 적당하다는 말인데, 

예를 들어 코어가 4개일 경우 full load는 4.0이고, 적절한 값은 2.8 이다.


IO wait:

http://bencane.com/2012/08/06/troubleshooting-high-io-wait-in-linux/

요약하자면, top, iostat, iotop, lsof (-p PID), pvdisplay 등의 유틸리티를 써서 IO 유발자(?)를 찾아내는데, 아래 명령으로 process state가 'D'인 놈을 찾아서 lsof -p PID를 통해 확인한다음 조치를 취하자는 말.

# find process w/ 'D' state (in every 5 sec, 10 times)

for x in `seq 1 1 10`; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done


happy hackin'

remmina는 다 좋은데 윈도우 키 누른 상태가 지속되는 경우가 있다.

해결법은 간단하다. 윈도우 키를 빠르게 두 번 연속으로 누르면 된다.


ref: http://askubuntu.com/questions/390869/disable-super-winkey-key-in-remmina


happy hackin'

smartmontool

tips & tricks/Linux/Unix 2016. 6. 22. 14:38 by manywaypark

커널 업그레이드 하고 리부팅 했는데 파일시스템 체크하다가 실패함. Orz

(의심 가는 것은 docker 깔아서 이거저거 테스트한 것과 18G 짜리 postgresql dump file을 서버에서 받아와서 노트북에도 밀어넣은 작업. 둘 중에 하나가 좀 문제를 있으켰을 가능성이 농후하다)

두번 정도 리부팅하니 우분투가 올라오긴 올라오는데 좀 찝찝함.

혹시나 하는 마음에 smartmontools 돌려서 H/W failure 인지 검사.

short test는 아무 이상 없구나. 퇴근하면서 extended test 돌려놓고 가야겠다.


https://help.ubuntu.com/community/Smartmontools


happy hackin'

alias가 아닌, 원래(vanilla) 명령어를 실행하게 한다. 

command라는 command도 같은 역할을 함.


refs: 

  • http://serverfault.com/questions/480271/backslash-at-the-beginning-of-a-command
  • http://www.cyberciti.biz/faq/bash-shell-temporarily-disable-an-alias/

happy hackin'


Ubuntu box를 AP로 써보자

tips & tricks/Linux/Unix 2016. 3. 28. 14:50 by manywaypark

참고 링크 보면 금방 따라할 수 있다.

Network Manager에서는 잘 되는데, 아직 Ubuntu GUI에서는 간편하게 할 수는 없다 (KDE 등에서는 간편하게 설정할 수 있다고 함).

ref: http://ubuntuhandbook.org/index.php/2014/09/3-ways-create-wifi-hotspot-ubuntu/


unity-tweak-tool

tips & tricks/Linux/Unix 2015. 5. 14. 18:12 by manywaypark

System Settings에서 보다 더 세세하게 Ubuntu desktop을 제어하고 싶은가?

그렇다면 unity-tweak-tool을 써보라.


ref: https://apps.ubuntu.com/cat/applications/unity-tweak-tool/


2015-07-13: 비슷한 이름의 ubuntu tweak이라는 도구도 있다 (직접하기 귀찮은 구버전 커널들 지우기 등을 자동으로 해준다). 

happy hackin'

1 2 3 4 ··· 6 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
Linux/Unix (57)
Win (19)
Qt (11)
Xcode (1)
Mac (8)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

03-29 16:00