로그인 이후에 환경 메시지를 설명하려면 /etc/motd 파일을 사용한다.


$ sudo vi /etc/motd

# welcome knight76


로그아웃하고 다시 연결하면 배너가 출력된다.


$ ssh ..

# welcome knight76



ssh 로그인할 때만 추가하려면 /etc/ssh/sshd_config 를 수정해서 주석처리된 Banner 옵션을 수정해서  가르키는 파일을 만든다. 



$ sudo vi /etc/ssh/sshd_config

...

# no default banner path

#Banner none

Banner /etc/mybanner

...




ssh 로그인에 사용할 새로운 배너 파일을 생성한다.


$ sudo vi /etc/mybanner

######### ssh test ########





sshd 서비스를 재시작한다. 


$ sudo systemctl restart sshd.service



로그아웃하고 로그인하면 다음과 같은 화면이 뜬다.


$ ssh ..
######### ssh test ########

vagrant@localhost's password:





배너를 동적 스크립트로 쓰려면 /etc/profile.d/motd.sh를 수정해서 사용한다.


$ sudo vi  /etc/profile.d/motd.sh
#!/bin/bash
echo -e "`hostname`에 오신 것을 환영합니다. 계정: `whoami`, kernerl 정보 : `uname -r`"


로그아웃하고 다시 접근하면 다음 내용을 볼 수 있다.

$ 로그인
######### ssh test ########
vagrant@localhost's password:
Last login: Fri Aug  5 03:43:48 2016 from 10.0.2.2
# welcome knight76
knight76에 오신 것을 환영합니다. 계정: vagrant,  kernerl 정보 : 3.10.0-327.22.2.el7.x86_64




Posted by '김용환'
,


시간을 동기화하기 위해 과거에는 ntpd 데몬을 사용했지만, 이제는 좀 더 좋은 chrony를 사용할 수 있다.


먼저 chrony 패키지를 설치한다.


$ sudo yum install -y chrony


패키지는 chrony이지만, 실행 데몬 이름은 chronyd이다. 먼저 상태를 보면, 아직 실행 중은 아니다.


$ sudo systemctl status chronyd

● chronyd.service - NTP client/server

   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)

   Active: inactive (dead)

   

   


chronyd를 실행한다.


$ sudo systemctl start chronyd



chronyd 상태를 확인한다.


$ sudo systemctl status chronyd

● chronyd.service - NTP client/server

   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)

   Active: active (running) since 금 2016-08-05 01:55:27 UTC; 1s ago

...


 systemd[1]: Started NTP client/server.

 

   


부팅 이후에도 실행되도록 설정한다.


$ sudo systemctl enable chronyd




timedatectl 커맨드로 시간 정보를 확인하고, NTP 동기되어 있는지 확인한다. 


$  timedatectl status

      Local time: 시간

  Universal time: 시간

        RTC time: 시간

       Time zone: UTC (UTC, +0000)

     NTP enabled: no

NTP synchronized: yes

 RTC in local TZ: no

      DST active: n/a

      



$ timedatectl  | grep "NTP synchronized"

NTP synchronized: yes




만약 NTP synchronized: no라면 다음 명령어를 사용한다.


$ sudo timedatectl set-ntp yes




chrony가 시간 동기화를 제대로 진행하고 있는지 확인한다.


$ chronyc tracking

Reference ID    : IP정보

Stratum         : 3

Ref time (UTC)  :시간정보

System time     : 0.004222759 seconds slow of NTP time

Last offset     : -0.005224241 seconds

RMS offset      : 0.005224241 seconds

Frequency       : 41.940 ppm fast

Residual freq   : -6.715 ppm

Skew            : 0.610 ppm

Root delay      : 0.050698 seconds

Root dispersion : 0.028846 seconds

Update interval : 65.3 seconds

Leap status     : Normal





chrony가 동기화에 사용되는 네트워크를 확인한다.


$ chronyc sources

210 Number of sources = 4

MS Name/IP address         Stratum Poll Reach LastRx Last sample

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

^- 3.3.3.3        2   6    37    60    -11ms[  -11ms] +/-  103ms

^* 11.1.2.1               2   6    37    60   -218us[-5442us] +/-   54ms

^- 1.3.2.1               3   6    37    60    -27ms[  -27ms] +/-  339ms

^- 4.5.6.7       2   6    37    60  -4180us[-4180us] +/-  115ms

Posted by '김용환'
,


센트OS7을 설치하면 기본 로케일 설정과 키맵 설정은 미국으로 되어 있다.


localectl을 사용해서 로케일 상태 정보를 확인할 수 있다.


$ localectl status

   System Locale: LANG=en_US.UTF-8

       VC Keymap: us

      X11 Layout: us



한국 설정으로 바꿔본다.


$ sudo localectl set-locale LANG=ko_KR.utf8

$ sudo localectl set-keymap ko-mac


localectl을 사용해서 변경된 로케일 상태 정보를 확인할 수 있다.


$ localectl status

   System Locale: LANG=ko_KR.utf8

       VC Keymap: ko-mac

      X11 Layout: us



이제, 에러 메시지가 한글로 출력된다.


$ ls /adsfa/

ls: cannot access /adsfa/: 그런 파일이나 디렉터리가 없습니다




Posted by '김용환'
,



메모리에 블루투스 모듈을 로딩했는지 lsmod로 확인한다.


$ lsmod | grep btusb


블루투스 모듈이 있는지 확인한다. kernerl/drivers/bluetooth 디렉토레 있는지 확인할 수 있다.


$ modinfo btusb

filename:       /lib/modules/3.10.0-327.22.2.el7.x86_64/kernel/drivers/bluetooth/btusb.ko

license:        GPL

version:        0.6

description:    Generic Bluetooth USB driver ver 0.6

author:         Marcel Holtmann <marcel@holtmann.org>

rhelversion:    7.2

..



modprobe를 이용해서 블루투스 모듈을 메모리에 올린다.


$ sudo modprobe btusb




정상적으로 블루투스 모듈이 올라갔는지 lsmod로 확인한다.


$ lsmod | grep btusb

btusb                  28219  0

bluetooth             372944  1 btusb



이제 블루투스 모듈을 내리고, 메모리에 해당 모듈이 있는지 확인한다.


$ sudo rmmod btusb


$  lsmod | grep btusb


Posted by '김용환'
,


centos 7에 기본 툴과 개발 툴인 "Base", "Development Tools"를 설치할 수 있다. 



$ yum groupinfo "Base"

Group: 기본

 Group-Id: base

 Description: Enterprise Linux의 기본 설치

 Mandatory Packages:

    acl

    at

   +attr

...


$ yum groupinfo "Development Tools"

Group: 개발 도구

 Group-Id: development

 Description: 기본적인 개발 환경

 Mandatory Packages:

   +autoconf

   +automake

    binutils

   +bison

   +flex

    gcc

   +gcc-c++

    gettext

....



설치는 groupinstall을 사용한다.


$ sudo yum -y groupinstall "Base", "Development Tools"





yum 그룹 패키지를 설치했는지, 안했는지를 알기 위해 grouplist를 실행한다.


# yum grouplist

Loaded plugins: fastestmirror

Setting up Group Process

Loading mirror speeds from cached hostfile

Installed Groups:

   Additional Development

   Development tools

   Legacy UNIX compatibility

   Milkymist

   Perl Support

   Security Tools

   Web Server

Available Groups:

   Backup Client

   Backup Server

   Base

   CIFS file server

   Client management tools

   Compatibility libraries

   Console internet tools




참고로. centos7부터는 과거 Centos6 이하에서 사용할 수 있었던 "Development Libraries"를 더 이상 못 쓰는 것 같다.


$ yum groupinfo "Development Libraries"

Warning: group/environment Development Libraries does not exist.


$ yum grouplist | grep Development

   Additional Development

   Development tools

   Desktop Platform Development

   Server Platform Development




대신, yum groupinstall "Additional Development"를 사용한다.

Posted by '김용환'
,


리스트(List)에서 중복 요소 제거할 때, 다음 예시를 사용한다.


#!/bin/bash


contents=("a1123zba" "bbbbbbb" "ccccc" "ccccc")

result=`echo "${contents[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '`

echo $result




결과는 다음과 같다.


$ ./test.sh

a1123zba bbbbbbb ccccc


Posted by '김용환'
,




맥에서 centos 7.2를 설치하려면 vagrant가 필요하다.


https://www.vagrantup.com/downloads.html

mac 버전 다운로드를 클릭해서 vagrant_1.8.5.mg 를 다운받고 실행한다.


$ vagrant init



다음에, mac 용 virtualbox를  설치한다.
https://www.virtualbox.org/


vagrant 이미지에 centos가 있는지 확인한다.
https://atlas.hashicorp.com/boxes/search?utm_source=vagrantcloud.com&vagrantcloud=1

centos 7 다운로드하기 전에 확인한다.
https://atlas.hashicorp.com/centos/boxes/7



이제 vagrant를 이용해서 centos 7을 설치한다. libvirt로 사용한다.

$ vagrant box add  centos/7
==> box: Loading metadata for box 'centos/7'
    box: URL: https://atlas.hashicorp.com/centos/7
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) libvirt
2) virtualbox

Enter your choice: 1
==> box: Adding box 'centos/7' (v1606.01) for provider: libvirt
    box: Downloading: https://atlas.hashicorp.com/centos/boxes/7/versions/1606.01/providers/libvirt.box
==> box: Successfully added box 'centos/7' (v1606.01) for 'libvirt'!


(참고로 삭제는 ~$ vagrant box remove  centos/7 --provider=libvirt  명령을 내린다)



vi Vagrantfiles를 실행하여 다음을 수정한다.

#config.vm.box = "base" 에서 주석 처리를 삭제하고, config.vm.box = "centos/7"으로 수정한다




vagrant 이미지를 실행한다. 

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' is up to date...


실행은 되는데, ssh 연결이 되지 않는다. 아마도 많은 ssh 키 때문에 그런 것 같기도하고.

 vagrant ssh-config 를 실행해서 IdentifyFile 옵션이 가르키는 파일을 삭제하고, 다시 vagrant ssh를 실행해 본다. (파일은 다시 생성된다)


$ vagrant ssh-config

Host default

  HostName 127.0.0.1

  User vagrant

  Port 2200

  UserKnownHostsFile /dev/null

  StrictHostKeyChecking no

  PasswordAuthentication no

  IdentityFile /Users/계정명/.vagrant/machines/default/virtualbox/private_key

  IdentitiesOnly yes

  LogLevel FATAL





그래도 연결이 되지 않는다. 정확한 문제가 발생하는지 보려면, 다음 커맨드를 실행한다. hang되는 부분을 찾아본다.

~$ ssh vagrant@127.0.0.1 -p 2222 -v
OpenSSH_6.9p1, LibreSSL 2.1.7
..
debug1: Next authentication method: gssapi-with-mic



 virtualbox에서 running 중인 centos 7 터미널화면으로 접속한다.

vagrant centos/7의 기본 계정이름과 패스워드는 vagrant/vagrant 이다. vagrant 계정으로 로그인한 후, 다음을 실행한다.

1. sudo vi /etc/ssh/sshd_config 
  GSSAPIAuthentification yes를 GSSAPIAuthentification no로 수정한다

2. sudo /sbin/service sshd restart 




이제 mac으로 돌아가서 vagrant ssh,  또는 ssh vagrant@localhost -p 2222 를 실행하면, 접속이 잘 되는지 확인할 수 있다.





Posted by '김용환'
,



linux 간 디렉토리를 복사할 때, 빠른 복사 툴이 여러 존재한다.


1. rsync

rsync는 다 좋은데, 

데몬 설치와 설정 작업이 필요하고.

sender와 receiver 간의 버전 때문에, 버전을 맞춰야 하는 작업이 있을 수 있다.

또한, 파일 분석 시간이 오래 걸릴 수 있다는 단점이 있다. 



2. scp


간단한 file copy로는 좋지만, 대용량 파일(디렉토리)에서는 속도가 나오지 않는다. 


예) scp 계정@원본ip:/home/www/ . 




3. tar + ssh

rsync 랑 비슷한 속도 수준이며, 초기 복사 준비 시간도 없다. (강추)


예) tar -c /var/lib/jenkins | ssh 장비이름 'tar -xvf - -C /var/lib/jenkins'








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

[bash] 리스트(List)에서 중복 요소 제거하기  (0) 2016.08.03
[vagrant] 맥에서 centos 7 설치  (0) 2016.07.24
FQDN-도메인  (0) 2016.06.25
[리눅스] redir로 proxy 서버 만들기  (0) 2016.06.20
ipcalc - ip 계산기  (0) 2016.06.14
Posted by '김용환'
,

FQDN-도메인

unix and linux 2016. 6. 25. 14:14


도메인은 FQDN(https://wiki.kldp.org/KoreanDoc/html/PoweredByDNS-KLDP/fqdn.html)이라는 규칙을 따르고 있다. 마침표(.)를 항상 이름 뒤에 붙인다.

www.

google.

com. 

이런 단위로 구성된다. 기술적으로 마지막에 점이 빠지면 에러이지만, 계속 사용했던 관습을 따라 마지막 점은 생략해도 된다.


www.google.com. 

www.google.com. 


nslookup을 확인하면 확인할 수 있다. 




$ nslookup www.google.com.

Server: 1.214.68.2

Address: 1.214.68.2#53


Non-authoritative answer:

Name: www.google.com

Address: 203.252.15.151

Name: www.google.com

...



$ nslookup www.google.com

Server: 1.214.68.2

Address: 1.214.68.2#53


Non-authoritative answer:

Name: www.google.com

Address: 210.94.153.34

...




실제로 웹 브라우져에서 테스트해보면 잘 알 수 있다.

웹 브라우져는 간단한 문법 이슈까지 문제를 해결한다. 


Posted by '김용환'
,



proxy 서버(redirection)를 쉽게 구축할 수 있다.


$ sudo yum install redir



현 서버에서 10000포트로 접근하면 8.8.8.8의 22 번 포트로 TCP 연결을 redirection해준다.


$ redir --lport=10000 --caddr=8.8.8.8 --cport=22



현 서버의  ip가 10.10.10.10인 네트워크 이더넷에서 9001 포트로 접근하면 80포트로 TCP 연결을 redirection해준다.


$ redir –laddr=10.10.10.10 –lport=9001 –caddr=10.10.10.10 –cport=80

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

linux에서 빠른 디렉토리 copy 툴  (0) 2016.06.28
FQDN-도메인  (0) 2016.06.25
ipcalc - ip 계산기  (0) 2016.06.14
sudo echo > 에러 대신 tee 커맨드  (0) 2016.06.07
[pv] rpm으로 파이프 뷰 프로그램 설치 및 실행  (0) 2016.05.27
Posted by '김용환'
,