[linux] 헷갈리기 쉬운 fstab 의 옵션 설정

# cat /etc/fstab

[파일시스템 장치명] [마운트 포인트] [파일시스템 종류] [옵션] [dump관련설정] [파일점검 옵션]

LABEL=/                         /                         ext3     defaults                  1 1

LABEL=/boot1                 /boot                    ext3     defaults                 1 2

tmpfs                             /dev/shm              tmpfs   defaults                 0 0

devpts                           /dev/pts                devpts  gid=5,mode=620      0 0

sysfs                             /sys                     sysfs   defaults                 0 0

proc                              /proc                     proc    defaults                 0 0

LABEL=SWAP-sda3         swap                    swap    defaults                0 0

-파일시스템 장치명 : 장치명을 지정

-마운트 포인트 : 장치가 연결된 마운트 지점

-파일시스템 종류 : 파티션이 사용하는 파일시스템 지정

-옵션 : 파일시스템의 속성을 설정하는 옵션

defaults (rw, nouser,auto,exec suid 속성을 모두 가지는 옵션)

auto : 부팅시 자동 마운트

noauto : 부팅시 자동마운트 안함

exec : 실행파일이 실행되는 것을 허용

no exec : 실행파일이 실행되는 것을 허용 안함

suid : setuid, setgid의 사용을 허용하는 옵션

nosuid : setuid, setgid의 사용을 거부

ro (read only) : 읽기 전용

rw (ead write) : 읽고 쓰기 가능

user : 일반 계정 사용자들도 마운트 할 수 있는 옵션

nouser : root만 mount 가능

usrquota : 일반 사용자 quota적용

grpquota : 그룹 quota 적용

-dump 관련 설정

0 : 덤프되지 않은 파일시스템

1 : 데이터 백업을 위해 dump가능

-파일점검 옵션

0 : 부팅시 fsck를 사용하지 않음

1 : 루트 파일시스템을 의미

2 : 루트 파일시스템 이외의 파일시스템을 의미

[linux] vsftp 를 이용한 FTP서버 구성

 

Yum install vsftpd

 

하고 나서

 

/etc/vsftp/vsfptd.conf

 

# anonymous 사용자의 접속 허용 여부, 즉 anonymous ftp (default = YES)

# 공개된 형태의 FTP 서버로 운영할 것이 아니라면 NO로 한다.

anonymous_enable=NO

# 로컬 계정 사용자의 접속 허용 여부 (default = NO)

local_enable=YES

 

# write 명령어 허용 여부 (defualt = NO)

write_enable=YES

# 로컬 계정 사용자용 umask (default = 077)

local_umask=022

 

# anonymous 사용자가 파일을 업로드 할 수 있는지 여부 (default = NO)

# anon_upload_enable=YES

# anonymous 사용자의 디렉토리 생성 허용 여부 (default = NO)

# anon_mkdir_write_enable=YES

 

# 파일 전송 로그를 남길 것인지 여부 (default = YES)

xferlog_enable=YES

# xferlog 표준 포맷으로 로그를 남길지 여부 (기본 설정파일은 YES)

# 아래에서 NO로 설정했을 때를 설명함

xferlog_std_format=YES

# 파일 전송 로그 파일명

xferlog_file=/var/log/vsftpd.log

 

# FTP 서버 접속할 때 로긴 메시지 (default = vsFTPd 버전번호)

# 한글 사용 가능

# ftpd_banner=Welcome to blah FTP service.

ftpd_banner=Welcome to Yeonjins FTP

 

# 사용자의 홈디렉토리를 벗어나지 못하도록 제한하기 위한 설정 (default=NO)

# 제한이 필요할 경우 YES로 바꾼 후 제한할 사용자 ID를 chroot_list_file= 에 설정한 파일에

# 지정한다.

# chroot_local_user= 설정과 관련이 있으니 ‘3. 문제 해결’을 꼭 읽어보라.

#

# chroot_list_enable=YES

# chroot_list_file=/etc/vsftpd.chroot_list

 

# ——————————————————————-

# 기본 설정 파일에는 없는 설정값으로 필요한 설정만 추가한다.

# ※ 중요한 설정은 굵은 글씨로 표시

# ——————————————————————-

 

# PAM 파일명을 지정 (설치할 때 /etc/pam.d/vsftpd명으로 복사함)

pam_service_name=vsftpd

 

# wtmp에 로그 남기기 (YES로 해야만 last 명령어로 접속 여부 확인 가능)

session_support=YES

 

# 사용자가 자신의 home directory를 벗어나지 못하도록 설정

chroot_local_user=YES

 

# 새로운 디렉토리에 들어갔을 때 뿌려줄 환경 메시지를 저장한 파일명

# message_file=.message

 

# xferlog 형식으로 log를 남기려면 (위에서 이미 YES로 했음)

# xferlog_std_format=NO

#

#   – xferlog 표준 포맷은 로긴, 디렉토리 생성등의 로그를 남기지 않음

#     그러나 vsftpd 스타일 로그는 이를 포함한 보다 상세한 로그를 남김

#   – vsftpd 스타일 로그 예

#

#   Sun Jul 12 01:38:32 2003 [pid 31200] CONNECT: Client “127.0.0.1”

#   Sun Jul 12 01:38:34 2003 [pid 31199] [truefeel] FAIL LOGIN: Client “127.0.0.1”

#   Sun Jul 12 01:38:38 2003 [pid 31199] [truefeel] OK LOGIN: Client “127.0.0.1”

#   Sun Jul 12 01:38:41 2003 [pid 31201] [truefeel] OK MKDIR: Client “127.0.0.1”, “/mp3”

#   Sun Jul 12 01:39:06 2003 [pid 31201] [truefeel] OK UPLOAD: Client “127.0.0.1”, “/델리

#   스파이스 5집 – [04]키치죠지의 검은 고양이.mp3”, 6855473 bytes, 3857.39Kbyte/sec

 

# 전송속도 제한 (0은 제한없음, 단위는 초당 bytes)

anon_max_rate=0

local_max_rate=0

trans_chunk_size=0

 

# 최대 접속 설정 (단 xinetd를 통하지 않고 standalone으로 동작할 때만 사용 가능)

# standalone을 위해서는 listen=YES 추가하고 별도로 vsftpd를 띄워야 함

#

# max_clients=최대 접속자 수, max_per_ip=IP당 접속 수

# max_clients=100

# max_per_ip=3

 

# Standalone 으로 운영할 때 listen=YES. 포트 변경을 원할 경우 listen_port 설정

# 디폴트 포트는 21번 포트이다.

listen=YES

# listen_port=21

 

#passive mod

pasv_enable=YES

pasv_min_port=50020

pasv_max_port=50020

 

 

이후에 방화벽 설정

 

/etc/sysconfig/iptables

# FTP

-A INPUT -m state –state NEW -m tcp -p tcp –dport 20 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT

# FTP data transfer

-A INPUT -m state –state NEW -m tcp -p tcp –dport 50020 -j ACCEPT
해당 사항을 추가해준다. Passive 모드로 동작하게 설정을 올리고, 포트를 50020 로 잡아주었다.

[linux] lsof 사용

lsof  lisopen files 약자로 시스템에서 열린 파일 목록을 알려주고 사용하는 프로세스, 디바이스 정보, 파일의 종류등 상세한 정보를 출력해 준다.

리눅스와 유닉스는 추상화된 파일 시스템(VFS – Virtual File System) 사용하므로 일반 파일, 디렉터리, 네트워크 소켓, 라이브러리, 심볼릭 링크 등도 모두 파일로 처리되며 lsof 에서 상세한 정보를 확인할 있다.

 

유닉스마다 고유의 lsof 비슷한 용도의 명령어가 있지만 명령어와 옵션이 제각각이고 출력 정보가 상이하여 OS 바뀌면 사용하기가 힘들다.

lsof 리눅스, AIX, Solaris, FreeBSD, Mac OS X 종류에 상관없이 일관된 옵션과 출력 형식을 갖는 장점이 있다.

 

 

모든 열린 파일 출력 

옵션 없이 lsof 실행하면 모든 열린 파일 정보를 출력한다.

lsof

COMMAND    PID      USER   FD      TYPE             DEVICE SIZE/OFF       NODE NAME

init         1      root  cwd       DIR              253,0     4096          2 /

init         1      root  rtd       DIR              253,0     4096          2 /

init         1      root  txt       REG              253,0   150352       3932 /sbin/init

init         1      root  mem       REG              253,0    65928     784927 /lib64/libnss_files-2.12.so

init         1      root  DEL       REG              253,0              784911 /lib64/libc-2.12.so

init         1      root  DEL       REG              253,0              785325 /lib64/libgcc_s-4.4.7-20120601.so.1.#prelink#.YDRQV5

init         1      root  DEL       REG              253,0              784939 /lib64/librt-2.12.so

init         1      root  DEL       REG              253,0              784935 /lib64/libpthread-2.12.so.#prelink#.0jHMuJ

init         1      root  DEL       REG              253,0              785344 /lib64/libdbus-1.so.3.4.0.#prelink#.HCYJdq

init         1      root  mem       REG              253,0    39896     785047 /lib64/libnih-dbus.so.1.0.0

init         1      root  mem       REG              253,0   101920     785049 /lib64/libnih.so.1.0.0

init         1      root  DEL       REG              253,0              784904 /lib64/ld-2.12.so

init         1      root    0u      CHR                1,3      0t0       4160 /dev/null

init         1      root    1u      CHR                1,3      0t0       4160 /dev/null

init         1      root    2u      CHR                1,3      0t0       4160 /dev/null

init         1      root    3r     FIFO                0,8      0t0       8845 pipe

init         1      root    4w     FIFO                0,8      0t0       8845 pipe

init         1      root    5r      DIR               0,10        0          1 inotify

init         1      root    6r      DIR               0,10        0          1 inotify

init         1      root    7u     unix 0xffff880037504680      0t0       8846 socket

컬럼별 의미는 다음과 같다.

  1. COMMAND : 실행한 명령어
  2. PID : process id
  3. USER : 실행한 사용자
  4. FD: File Descriptor, 파일의 종류
  1. cwd: current working directory
  2. rtd: root directory
  3. mem : memory-mapped file
  4. txt: program text (code and data);
  5. TYPE: 파일 종류
  1. DIR: 디렉터리
  2. CHR:  character special file
  3. REG: regular file
  4. unix: 유닉스 도메인 소켓 (MySQL 등이 사용하는 소켓으로 로컬 프로세스에서만 사용 가능하며 TCP/UDP 보다 속도가 매우 빠름)
  5. DEVICE : 장치 번호
  6. SIZE/OFF: 파일의 크기나 오프셋
  7. NODE: 노드 번호
  8. NAME:  파일명

 

특정 사용자의 열린 파일 출력 

-u 옵션으로 사용자를 지정할 있다.

lsof -u lesstif

COMMAND  PID    USER   FD   TYPE             DEVICE SIZE/OFF    NODE NAME

sshd    7320 lesstif  cwd    DIR              253,0     4096       2 /

sshd    7320 lesstif  rtd    DIR              253,0     4096       2 /

sshd    7320 lesstif  txt    REG              253,0   546680  931362 /usr/sbin/sshd

sshd    7320 lesstif  DEL    REG                0,4            22174 /dev/zero

sshd    7320 lesstif  mem    REG              253,0    18592  785075 /lib64/security/pam_limits.so

sshd    7320 lesstif  mem    REG              253,0    10224  785073 /lib64/security/pam_keyinit.so

sshd    7320 lesstif  mem    REG              253,0    10240  785078 /lib64/security/pam_loginuid.so

sshd    7320 lesstif  mem    REG              253,0    18664  785090 /lib64/security/pam_selinux.so

sshd    7320 lesstif  mem    REG              253,0    41088  925568 /usr/lib64/libcrack.so.2.8.1

sshd    7320 lesstif  mem    REG              253,0    14432  785059 /lib64/security/pam_cracklib.so

 

특정 포트를 사용하는 프로세스 정보 보기

개인적으로 가장 많이 쓰는 명령어이다. -i 옵션뒤에 프로토콜과 포트를 명시해 주면 된다. 다음은 TCP 22 포트(ssh) 쓰는 프로세스의 정보를 출력한다.

lsof -i TCP:22

COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

sshd    1550    root    3u  IPv4  13931      0t0  TCP *:ssh (LISTEN)

sshd    1550    root    4u  IPv6  13933      0t0  TCP *:ssh (LISTEN)

sshd    1895    root    3r  IPv4  15005      0t0  TCP 192.168.152.131:ssh->192.168.152.1:55859 (ESTABLISHED)

sshd    7316    root    3r  IPv4  22126      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57127 (ESTABLISHED)

sshd    7320 lesstif    3u  IPv4  22126      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57127 (ESTABLISHED)

sshd    7474    root    3r  IPv4  22763      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57197 (ESTABLISHED)

특정 명령어가 사용하는 포트

apache httpd 같은 경우 fork 하여 여러 개의 프로세스가 뜨게 된다. -c 옵션과 httpd 주면 httpd 오픈한 파일 정보를 출력한다.

lsof -c httpd

특정 파일을 사용하는 프로세스 보기

특정 파일을 사용하고 있는 프로세스의 자세한 정보를 있다. 옵션 없이 파일의 경로를 지정하면 된다.

lsof /var/log/httpd/access_log

 

특정 디렉터리내 열린 파일 보기

특정 디렉터리 하위의 열린 파일을 표시하고 싶은 경우가 있다. +D 옵션 뒤에 디렉터리 경로를 명시하면 된다. 아래는 /tmp 디렉터리 밑에 열린 파일을 표시한다.

lsof +D /tmp

 

포트 범위 지정

TCP 포트 22 에서 80 까지 출력

lsof -i TCP:22-80

COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

master  1349    root   12u  IPv4  12888      0t0  TCP localhost:smtp (LISTEN)

master  1349    root   13u  IPv6  12890      0t0  TCP localhost:smtp (LISTEN)

sshd    1550    root    3u  IPv4  13931      0t0  TCP *:ssh (LISTEN)

sshd    1550    root    4u  IPv6  13933      0t0  TCP *:ssh (LISTEN)

sshd    1895    root    3r  IPv4  15005      0t0  TCP 192.168.152.131:ssh->192.168.152.1:55859 (ESTABLISHED)

sshd    7316    root    3r  IPv4  22126      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57127 (ESTABLISHED)

sshd    7320 lesstif    3u  IPv4  22126      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57127 (ESTABLISHED)

httpd   7400    root    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7402  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7403  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7404  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7405  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7406  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7407  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7408  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

httpd   7409  apache    4u  IPv6  22492      0t0  TCP *:http (LISTEN)

sshd    7474    root    3r  IPv4  22763      0t0  TCP 192.168.152.131:ssh->192.168.152.1:57197 (ESTABLISHED)

 

IPv4 또는 IPv6 포트만 표시

-i 옵션 뒤에 4(IPv4), 또는 6(IPV6) 지정하여 특정 IP 버전만 확인할 있다./

lsof -i 4

COMMAND    PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

rpcbind   1068     rpc    6u  IPv4  11858      0t0  UDP *:sunrpc 

rpcbind   1068     rpc    7u  IPv4  11860      0t0  UDP *:819 

rpcbind   1068     rpc    8u  IPv4  11861      0t0  TCP *:sunrpc (LISTEN)

rpc.statd 1086 rpcuser    5r  IPv4  11949      0t0  UDP *:838 

rpc.statd 1086 rpcuser    8u  IPv4  11955      0t0  UDP *:47492 

rpc.statd 1086 rpcuser    9u  IPv4  11959      0t0  TCP *:38374 (LISTEN)

cupsd     1159    root    7u  IPv4  12195      0t0  TCP localhost:ipp (LISTEN)

 

특정 사용자 제외

사용자 지정 옵션인 -u ^ 추가하면 특정 사용자는 제외할 있다. 다음은 lesstif root 사용자가 열은 파일은 제외하고 정보를 출력한다.

lsof -u^lesstif -u ^root

 

열린 모든 네트워크 포트 표시

모든 네트워크 포트를 표시한다. -i 뒤에 프로토콜을 명시하면 해당 프로토콜 관련 포트만 표시한다.

## 모든 포트

lsof -i

## TCP

lsof -i TCP 

## UDP

lsof -i UDP

특정 프로세스가 오픈한 파일 표시

특정 프로세스가 오픈한 파일만 표시한다. -p(소문자) 옵션뒤에 PID  주면 된다.

lsof -p 123

 

특정 사용자가 오픈한 모든 프로세스 중지

-t 옵션은 자세한 정보를 출력하지 않고 pid 정보만 출력한다. 다음 명령은 lesstif 사용자로 구동한 프로세스의 id 리턴한다.

lsof -t -u lesstif

13324

이를 응용하여 kill 명령어에 pid 전달할 있으므로 아래와 같이 사용하면 lesstif 사용자의 모든 프로세스를 중지하게 된다.

kill -KILL `lsof -t -u lesstif`

 

Ref

[linux] 다수 서버 호스트명 수정하기 – bash

자체적으로, ReserveDNS 를 운영하면서 질의 하면 더욱 좋겠지만 그렇지 못한 경우를 위해서 다음과 같이

호스트 파일을 일괄 수정한다.

 

 

Java 등에서 inetaddress.getbyname  또는

InetAddress[] ipAddress = DNSNameService.lookupAllHostAddr(“hostName”);

등을 사용하는 경우 호스트명을 통해서 아이피를 가져오게 됨

 

이럴때 일일히 서버에서 등록하지 말고 매니지먼트 서버에서 아래와 같이 쉘을 하나 만들어서 원격지 배쉬로 실행시켜서 적용하면 좋다.

 

쉘스크립트 작성..

#!/bin/bash

a=(`hostname`)

b=`ifconfig eth0 | grep 10.11 | cut -d ‘:’ -f2 | cut -d ‘ ‘ -f1`

echo -e “$b $a” >> /etc/hosts

 

이렇게 작성한 쉘을 아래와 같이 원격지에 뿌려줌. (remotehost.txt 에 대상이 되는 서버를 미리 등록해놓자~)

for i in $(cat remotehost.txt ); do ssh $i ‘/bin/bash -s’ < myname.sh  ;done

 

 

 

[linux] vim diff

Vim editor 에서 아래와 같이 vimdiff 로 alias가 걸려있음

Vimdiff A B 로 하면 둘을 비교해서 다른부분은 볼드체로 표시됨. 꿀~

컨트롤 WW 로 이동 가능염

그냥 VIM 에서는 :sp (split) 로 쪼갤수잇음.
Vim a.txt
:sp b.txt 입력

https://kldp.org/node/984

vimdiff 사용법
리눅스에서 두 파일을 비교하는 명령어인 vimdiff의 간단한 사용법을 말씀 드리겠습니다.
기본적으로 vimdiff는 vim에서 화면을 분할하고, 두 파일을 열었을 상태와 같다고 보시면 됩니다.
추가적으로 좋은 점은 서로 다른 부분을 표시해주는 부분이죠.
두 파일을 비교하고, 병합하는데 사용할 수 있습니다.
우선 분할된 창에서 다른 창으로 이동하는 명령은 Ctrl + w + w입니다.
차이점이 있는 부분으로 이동하는 명령은 ] + c 와 [ + c 입니다.
] + c는 현재 위치에서 아래쪽으로 탐색하며,
[ + c는 현재 위치에서 위쪽으로 탐색을 진행합니다.
수정을 원하는 부분을 찾았으면 복사를 해야겠지요.
d + o는 현재 위치에 반대쪽 창의 내용을 복사해 옵니다.
d + p는 현재 위치의 내용을 반대쪽 창에 복사합니다.
vimdiff는 동일한 부분은 생략하여 보여줍니다.
이를 펼치기 위해서는 z + o 또는 z + space를 누르면 됩니다.
반대로 접기 위해서는 z + c를 누르면 됩니다.
마지막으로, 한쪽 창의 내용을 편집하다보면 차이점을 나타내는 표시가 없어질 경우가 있습니다.
이때 :diffupdate를 누르시면 다시 비교하여, 차이점을 표시해 줍니다.

[linux] trickle 대역폭 제한

주로 ftp, rsync를 이용하여 데이터가 이동하는데 이런 프로그램의 대역폭을 trickle 프로그램으로

조절이 가능하다.

설치

root@smileserv-desktop:~# apt-get install trickle

패키지 목록을 읽는 중입니다완료

의존성 트리를 만드는 중입니다       

상태 정보를 읽는 중입니다완료

다음 패키지가 자동으로 설치되었지만 더 이상 필요하지 않습니다:

  linux-image-3.13.0-66-generic linux-image-3.13.0-68-generic

  linux-image-3.13.0-70-generic linux-image-3.13.0-71-generic

  linux-image-3.13.0-73-generic linux-image-3.13.0-74-generic

  linux-image-3.13.0-76-generic linux-image-extra-3.13.0-66-generic

  linux-image-extra-3.13.0-68-generic linux-image-extra-3.13.0-70-generic

  linux-image-extra-3.13.0-71-generic linux-image-extra-3.13.0-73-generic

  linux-image-extra-3.13.0-74-generic linux-image-extra-3.13.0-76-generic

Use ‘apt-get autoremove’ to remove them.

다음 새 패키지를 설치할 것입니다:

  trickle

0개 업그레이드, 1개 새로 설치, 0개 제거 및 116개 업그레이드 안 함.

0 바이트/34.6 k바이트 아카이브를 받아야 합니다.

이 작업 후 158 k바이트의 디스크 공간을 더 사용하게 됩니다.

Selecting previously unselected package trickle.

(데이터베이스 읽는중현재 648717개의 파일과 디렉터리가 설치되어 있습니다.)

Preparing to unpack …/trickle_1.07-10ubuntu2_amd64.deb …

Unpacking trickle (1.07-10ubuntu2) …

Processing triggers for man-db (2.6.7.1-1ubuntu1) …

trickle (1.07-10ubuntu2) 설정하는 중입니다

# debian 계열 ubuntu 14.04 에서 apt-get install 명령어로 쉽게 설치가 가능하다

[root@controller ~]#  yum install epel-release

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: data.nicehosting.co.kr

 * extras: ftp.daumkakao.com

 * updates: data.nicehosting.co.kr

Resolving Dependencies

–> Running transaction check

—> Package epel-release.noarch 0:7-5 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

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

 Package                                                Arch                                             Version                                          Repository                                        Size

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

Installing:

 epel-release                                           noarch                                           7-5                                              extras                                            14 k

Transaction Summary

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

Install  1 Package

Total download size: 14 k

Installed size: 24 k

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

Downloading packages:

epel-release-7-5.noarch.rpm                                                                                                                                                               |  14 kB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : epel-release-7-5.noarch                                                                                                                                                                       1/1

  Verifying  : epel-release-7-5.noarch                                                                                                                                                                       1/1

Installed:

  epel-release.noarch 0:7-5

Complete!

[root@controller ~]# yum install trickle

Loaded plugins: fastestmirror

epel/x86_64/metalink                                                                                                                                                                      | 5.3 kB  00:00:00

epel                                                                                                                                                                                      | 4.3 kB  00:00:00

(1/3): epel/x86_64/group_gz                                                                                                                                                               | 169 kB  00:00:00

(2/3): epel/x86_64/primary_db                                                                                                                                                             | 3.9 MB  00:00:00

(3/3): epel/x86_64/updateinfo                                                                                                                                                             | 493 kB  00:00:05

Loading mirror speeds from cached hostfile

 * base: data.nicehosting.co.kr

 * epel: ftp.riken.jp

 * extras: ftp.daumkakao.com

 * updates: data.nicehosting.co.kr

Resolving Dependencies

–> Running transaction check

—> Package trickle.x86_64 0:1.07-19.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

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

 Package                                           Arch                                             Version                                                 Repository                                      Size

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

Installing:

 trickle                                           x86_64                                           1.07-19.el7                                             epel                                            48 k

Transaction Summary

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

Install  1 Package

Total download size: 48 k

Installed size: 103 k

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

Downloading packages:

warning: /var/cache/yum/x86_64/7/epel/packages/trickle-1.07-19.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY

Public key for trickle-1.07-19.el7.x86_64.rpm is not installed

trickle-1.07-19.el7.x86_64.rpm                                                                                                                                                            |  48 kB  00:00:00

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

Importing GPG key 0x352C64E5:

 Userid     : “Fedora EPEL (7) <epel@fedoraproject.org>”

 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5

 Package    : epel-release-7-5.noarch (@extras)

 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

Is this ok [y/N]: y

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : trickle-1.07-19.el7.x86_64                                                                                                                                                                    1/1

  Verifying  : trickle-1.07-19.el7.x86_64                                                                                                                                                                    1/1

Installed:

  trickle.x86_64 0:1.07-19.el7

Complete!

# redhat 계열 CentOS 7에서는 epel repository를 설치하고 yum 설치가 가능하다.

– ftp 트래픽 조절

# trickle 사용전

root@smileserv-desktop:~# lftp -u SND xxx.xxx.xxx.xxx

비밀번호

lftp SDN@xxx.xxx.xxx.xxx:~> cd smileserv/Linux_iso/    

lftp SDN@xxx.xxx.xxx.xxx:~/smileserv/Linux_iso> get CentOS\ 7\ x86_64-0.iso

`CentOS 7 x86_64-0.iso’ at 132024912 (3%) 9.19M/초 남은시간:7m [자료 받는 중]

# trickle 사용후

root@smileserv-desktop:~# trickle -s -u 1000 -d 1000 lftp -u SND 211.55.113.55

lftp SDN@xxx.xxx.xxx.xxx:~> cd smileserv/Linux_iso/

lftp SDN@xxx.xxx.xxx.xxx:~/smileserv/Linux_iso> get -c CentOS\ 7\ x86_64-0.iso

`CentOS 7 x86_64-0.iso’ at 192482168 (4%) 1.07M/초 남은시간:61m [자료 받는 중]

# 사용법은 명령어 전에 trickle을 붙여주는 것이며 -u, -d옵션으로 Kbyte 단위의 업, 다운로드

 대역폭 할당이 가능하다.

[Nginx] Rewrite Rule

nginx rewrite

도메인이 www 로 시작하지 않는 것을 www로 가게

Query Parameter 삭제

      • nginx rewrite는 rewrite 후에 쿼리 파라미터를 자동으로 붙여버린다.
      • 쿼리 파라미터가 붙는 것을 막으려면 타겟 URL의 끝에 물음표(?)가 있어야 한다.
        rewrite ^ http://www.example.com/? last; # 쿼리 파라미터를 무시하고 무조건 http://www.example.com 으로 보내버림

http로 온 것을 모두 https

[linux] sudo 커맨드 환경 변수 (env) 등록

아래와 같이 sudo env 명령을 사용하면 된다.

 

아래 예시는 sudo 명령어 자체에 alias를 설정하는 과정이며,

Centos6 에서 python27을 사용하기 위해 rh 의 LIBRARY 를 PATH에 등록하는 과정이다.

 

alias sudo=’sudo env PATH=/opt/rh/python27/root/usr/bin${PATH:+:${PATH}} LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} XDG_DATA_DIRS=/opt/rh/python27/root/usr/    share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}  PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}’

[기타] 신뢰할수 있는 루트 인증서 등록 하는 법

Mac OS X

Add

Use command:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/new-root-certificate.crt

Remove

Use command:

sudo security delete-certificate -c “<name of existing certificate>”

Windows

Add

Use command:

certutil -addstore -f “ROOT” new-root-certificate.crt

Remove

Use command:

certutil -delstore “ROOT” serial-number-hex

Linux (Ubuntu, Debian)

Add

  1. Copy your CA to dir /usr/local/share/ca-certificates/
  2. Use command:

sudo cp foo.crt /usr/local/share/ca-certificates/foo.crt

  1. Update the CA store:

sudo update-ca-certificates

Remove

  1. Remove your CA.
  2. Update the CA store:

sudo update-ca-certificates –fresh

Restart Kerio Connect to reload the certificates in the 32-bit versions or Debian 7.

Linux (CentOs 6)

Add

  1. Install the ca-certificates package:

yum install ca-certificates

  1. Enable the dynamic CA configuration feature:

update-ca-trust force-enable

  1. Add it as a new file to /etc/pki/ca-trust/source/anchors/:

cp foo.crt /etc/pki/ca-trust/source/anchors/

  1. Use command:

update-ca-trust extract

Restart Kerio Connect to reload the certificates in the 32-bit version.

Linux (CentOs 5)

Add

Append your trusted certificate to file /etc/pki/tls/certs/ca-bundle.crt

cat foo.crt >> /etc/pki/tls/certs/ca-bundle.crt

Restart Kerio Connect to reload the certificates in the 32-bit version.

[linux] redis clustering (redis-trib 이용)

redis 3.0 이상 필요.

설치하고 난 뒤에 다음과 같이 redis.conf를 변경해줍니다.

daemonize yes

pidfile /var/run/redis.pid

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile “/services/log/redis/redis.log”

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /services/data/redis/

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

appendonly yes

appendfilename “appendonly.aof”

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000

cluster-enabled yes

cluster-node-timeout 2000

cluster-slave-validity-factor 1

cluster-config-file nodes.conf

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events “”

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

그 다음 루비루비젬을 설치해주고, redis 를 설치해줘야 한다그래야 클러스터 관련 스크립트가 실행됨 (include redis)

yum install ruby rubygem

gem install –http-proxy http://10.10.10.100:8080 redis

이후 레디스 소스파일이 위치한 경로에 src 폴더안에 redis-trib.rb 를 이용하면된다.

명령어

for i in $(cat centos_redis30.txt);do ssh $i “hostname;yum install ruby rubygem -y”;done

for i in $(cat centos_redis30.txt);do ssh $i “hostname;gem install –http-proxy http://10.10.10.100:8080 redis “;done

설정파일은 master / slave 구분없이 동일하므로 scp로 넣어준다.

설정 파일 복사 후 적용을 위해서 service redis restart

그다음 1번 서버에서 다음과 같은 명령어를 날려준다.

echo yes | /services/src/redis-3.0.1/src/redis-trib.rb create –replicas 1 10.10.10.21:6379 10.10.10.22:6379 10.10.10.23:6379 10.10.10.24:6379 10.10.10.25:6379 10.10.10.26:6379

(클러스터링 및 리플리카를  M M M S S S 순으로 넣어줍니다. )

레디스 클러스터링에서는

사용 포트가 서비스포트 + 10000번이 자동 할당된다.

해당 포트를 통해서 redis clustering command 가 실행되며해당 포트를열지 않으면클러스터링이 안됨.

.

Redis-trib 사용법

Redis-trib 사용법

http://download.redis.io/redis-stable/src/redis-trib.rb

명령 설명

o    create   클러스터를 생성한다. replicas 지정해서 슬레이브 개수를 지정할  있다.

o    reshard   슬롯을 노드에 할당 또는 재할당한다. Source 노드와 destination 노드를 지정한다.

o    add-node   클러스터에 노드를 추가한다마스터 또는 슬레이브로 추가할  있다.

o    del-node   클러스터에서 노드를 제거한다.

redis-trib CREATE

o    클러스터를 생성한다.

o    명령   redis-trib.rb create [–replicas n] ip1:port1 … ipn:portn

o    –replicas n   마스터  슬레이브 노드를   만들지를 정한다.   생략하거나 0으로 설정하면 슬레이브 노드를 만들지 않고 마스터로만 클러스터를 구성한다.  

o    ip1:port1 … ipn:portn   클러스터에 참여할 레디스 노드들의 ip:port 입력한다.   명령을 실행하는 머신과 같은 ip 사용해도 ip 반드시 입력해야 한다.

o    Standalone mode 시작한 레디스는 클러스터에 참여할  없다.   지정한 ip:port  standalone mode Redis-trib 종료한다.

o    DB 데이터가 있으면 클러스터를 생성하지 못하고 종료한다.   그러므로 클러스터를 생성할 노드는 AOF  RDB 부터 데이터를 읽어들이면 안된다.   Cluster mode 시작한 레디스는 클러스터가 구성되지 않은 상태에서는 set 명령같은 데이터를 입력/수정/삭제/조회하는 명령을 수행할  없다.   하지만 Flushdb 또는 flushall 명령은 실행가능하다 명령을 실행해서 데이터를 모두 삭제했어도 클러스터는 구성되지 않는다처음부터 데이터를 읽어 들이지 않는 방법이 가장 좋다.

o    레디스 노드는 최소 3 이상을 지정해야 한다.   Replicas 0으로 지정하면 참여한 노드가 모두 마스터가 된다.   Replicas 1 지정하면 최소 마스터슬레이브 3쌍으로 구성되어 6노드 이상이 있어야 한다.   Cluster 명령을 직접 사용하면 이러한 제한은 없어서, 1 노드로도 클러스터를 만들  있다.

o    IP 같은 경우 클러스터 구성   IP 같으면 명령에 지정된 순서대로 마스터와 슬레이브가 정해진다.

o    다음과 같이 replicas 1 지정하고 5001부터 5006까지 포트를 지정하면 아래와 같이 구성된다.

$ src/redis-trib.rb create –replicas 1 127.0.0.1:5001 127.0.0.1:5002 127.0.0.1:5003 127.0.0.1:5004 127.0.0.1:5005 127.0.0.1:5006

설명: Redis Cluster Create redis_trib

o    replicas 2 지정하고 9 노드를 지정하면 다음과 같이 구성된다.

설명: Redis Cluster Create redis-trib replicas 2

o    3 IP 레디스 노드 2개씩 지정하고 replicas 1 하면 다음과 같이 구성된다.   세번째 박스(IP 105)  박스안에 마스터슬레이브가 구성되었으므로  박스가 다운되면 클러스터가 다운되는 상황이 된다.

설명: Redis Cluster Create redis_trib 3boxes 6nodes

o    redis-trib 클러스터 구성을   하려고 하지만완벽하지 않아서 위와 같은 상황이 발생할  있으므로세밀한 구성을 위해서는 클러스터 명령으로 직접 구성하는 것이 좋은 방법이다.

o    redis-trib create했을때 구성 형태에 대한 자세한 내용은 여기를 보세요.   레디스 클러스터 자동 구성 형태

o    다음은 6 노드로 마스터 3, 슬레이브 3으로 구성했을때 나오는 메시지이다.   redis 3.0.2 포한된 redis-trib.rb 실행한 것이다.    길지만 생략하지 않고 그대로 보여준다.

$ src/redis-trib.rb create –replicas 1 127.0.0.1:5001 127.0.0.1:5002 127.0.0.1:5003 127.0.0.1:5004 127.0.0.1:5005 127.0.0.1:5006

>>> Creating cluster

Connecting to node 127.0.0.1:5001: OK

Connecting to node 127.0.0.1:5002: OK

Connecting to node 127.0.0.1:5003: OK

Connecting to node 127.0.0.1:5004: OK

Connecting to node 127.0.0.1:5005: OK

Connecting to node 127.0.0.1:5006: OK

>>> Performing hash slots allocation on 6 nodes…

Using 3 masters:

127.0.0.1:5001

127.0.0.1:5002

127.0.0.1:5003

Adding replica 127.0.0.1:5004 to 127.0.0.1:5001

Adding replica 127.0.0.1:5005 to 127.0.0.1:5002

Adding replica 127.0.0.1:5006 to 127.0.0.1:5003

M: a2c1abd1e2db46fe31beed7e4d40f81cc8abe28d 127.0.0.1:5001

     slots:0-5460 (5461 slots) master

M: ed6274c72384c208154e9f06e3c40a7f893197f6 127.0.0.1:5002

     slots:5461-10922 (5462 slots) master

M: 4c385777933bf54eb0636ebe7bda4903e0da0ade 127.0.0.1:5003

     slots:10923-16383 (5461 slots) master

S: 813e57347d2de9f3a9f36f7846642a5732c1519e 127.0.0.1:5004

     replicates a2c1abd1e2db46fe31beed7e4d40f81cc8abe28d

S: cfd9827e915e79c4550afddad2b546c3d1298872 127.0.0.1:5005

     replicates ed6274c72384c208154e9f06e3c40a7f893197f6

S: d324144ecfb33f75ef5e90b47388423f0656ab95 127.0.0.1:5006

     replicates 4c385777933bf54eb0636ebe7bda4903e0da0ade

Can I set the above configuration? (type ‘yes’ to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending CLUSTER MEET messages to join the cluster

Waiting for the cluster to join…

>>> Performing Cluster Check (using node 127.0.0.1:5001)

M: a2c1abd1e2db46fe31beed7e4d40f81cc8abe28d 127.0.0.1:5001

     slots:0-5460 (5461 slots) master

M: ed6274c72384c208154e9f06e3c40a7f893197f6 127.0.0.1:5002

     slots:5461-10922 (5462 slots) master

M: 4c385777933bf54eb0636ebe7bda4903e0da0ade 127.0.0.1:5003

     slots:10923-16383 (5461 slots) master

M: 813e57347d2de9f3a9f36f7846642a5732c1519e 127.0.0.1:5004

     slots: (0 slots) master

     replicates a2c1abd1e2db46fe31beed7e4d40f81cc8abe28d

M: cfd9827e915e79c4550afddad2b546c3d1298872 127.0.0.1:5005

     slots: (0 slots) master

     replicates ed6274c72384c208154e9f06e3c40a7f893197f6

M: d324144ecfb33f75ef5e90b47388423f0656ab95 127.0.0.1:5006

     slots: (0 slots) master

     replicates 4c385777933bf54eb0636ebe7bda4903e0da0ade

[OK] All nodes agree about slots configuration.

>>> Check for open slots…

>>> Check slots coverage…

[OK] All 16384 slots covered.

redis-trib RESHARD

o    슬롯을 재할당한다슬롯과 데이터를 같이 옮겨준다.

o    명령   redis-trib.rb reshard ip:port

o    ip:port 접속해서 작업할 노드이다. Reshard  source 노드나 destination 노드로 접속할 필요는 없다.

o    Reshard  노드를 추가했을때  노드에 슬롯을 할당하기 위해 사용하거나기존 노드의 슬롯을 다른 노드로 옮길때 사용한다.   Reshard 명령은 destination 노드로 데이터를 migrate 명령으로 옮긴다.

o    Source 노드는 1 이상 또는 모두를 지정할  있고, destination 노드는 하나만 지정한다.   옮길 슬롯의 개수를 지정한다특정 슬롯을 지정하거나 특정 범위를 지정할  없다.

o    다음은 reshard할때 나오는 메시지이다옮길 슬롯의 갯수만큼 메시지가 나오므로여기서는 5 슬롯만 지정했다.   Source node #1 에서 all 입력하면 모든 노드로 부터 슬롯을 받는다.   특정 노드 id 여러개 입력할  있다모두 입력했으면 done 입력한다.   Source node  Destination(Receiving) node 모두 마스터 노드만 지정해야 된다슬레이브 노드는 지정할  없다.   입력해야  부분은 굵게 표시했다.

redis-trib.rb reshard 127.0.0.1:5001

>>> Performing Cluster Check (using node 127.0.0.1:5001)

[OK] All nodes agree about slots configuration.

>>> Check for open slots…

>>> Check slots coverage…

[OK] All 16384 slots covered.

How many slots do you want to move (from 1 to 16384)? 5

What is the receiving node ID? 4c385777933bf54eb0636ebe7bda4903e0da0ade

Please enter all the source node IDs.

  Type ‘all’ to use all the nodes as source nodes for the hash slots.

  Type ‘done’ once you entered all the source nodes IDs.

Source node #1:a2c1abd1e2db46fe31beed7e4d40f81cc8abe28d

Source node #2:done

Ready to move 5 slots.

Do you want to proceed with the proposed reshard plan (yes/no)? yes

Moving slot 0 from 127.0.0.1:5001 to 127.0.0.1:5003:

Moving slot 1 from 127.0.0.1:5001 to 127.0.0.1:5003:

Moving slot 2 from 127.0.0.1:5001 to 127.0.0.1:5003:

Moving slot 3 from 127.0.0.1:5001 to 127.0.0.1:5003:

Moving slot 4 from 127.0.0.1:5001 to 127.0.0.1:5003:

redis-trib ADD-NODE

o    클러스터에 노드를 추가한다마스터 또는 슬레이브로 추가할  있다.

o    명령   redis-trib.rb add-node [–slave] [–master-id id] new_ip:port existing_ip:port

o    –slave    노드를 슬레이브로 추가할  사용한다지정하지 않으면 마스터로 추가된다.

o    –master-id id   slave 옵션을 사용했을때 마스터 노드 ID 지정한다생략할  있다생략하면 existing_ip:port 노드의 슬레이브가 된다.

o    new_ip:port   추가할 ip:port 지정한다. Cluster mode 시작되어 있어야 하고데이터가 없어야 한다.

o    existing_ip:port   접속해서 작업할 기존 노드를 지정한다.

o    다음은 5007 노드를 마스터로 클러스터에 등록하는 명령과 메시지이다.   중간에 입력해야 하는 것은 없다.   이후에 reshard 명령으로 슬롯을 할당해야 마스터로서 역할을 수행할  있다.

redis-trib.rb add-node 127.0.0.1:5007 127.0.0.1:5001

>>> Adding node 127.0.0.1:5007 to cluster 127.0.0.1:5001

>>> Performing Cluster Check (using node 127.0.0.1:5001)

[OK] All nodes agree about slots configuration.

>>> Check for open slots…

>>> Check slots coverage…

[OK] All 16384 slots covered.

Connecting to node 127.0.0.1:5007: OK

>>> Send CLUSTER MEET to node 127.0.0.1:5007 to make it join the cluster.

[OK] New node added correctly.

o    다음은 5007 노드를 5002 슬레이브로 등록하는 명령이다마지막에 다른 부분만 표시한다.  

redis-trib.rb add-node –slave 127.0.0.1:5007 127.0.0.1:5002

>>> Adding node 127.0.0.1:5007 to cluster 127.0.0.1:5002

….. 중간 생략 …..

[OK] All 16384 slots covered.

Automatically selected master 127.0.0.1:5002

Connecting to node 127.0.0.1:5007: OK

>>> Send CLUSTER MEET to node 127.0.0.1:5007 to make it join the cluster.

Waiting for the cluster to join.

>>> Configure node as replica of 127.0.0.1:5002.

[OK] New node added correctly.

o    다음은 master-id 옵션을 지정한 명령 예이다.

$ redis-trib.rb add-node –slave –master-id 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 127.0.0.1:5007 127.0.0.1:5001

redis-trib DEL-NODE

o    클러스터에서 노드를 제거한다.   슬롯이 할당되어 있으면 제거할  없다.   Reshard 명령으로 슬롯과 데이터를 다른 노드에 할당한  del-node 명령을 실행한다.   제거할 노드가 슬레이브면 reshard  필요없다.

o    명령   redis-trib.rb del-node ip:port node-id

o    ip:port   접속해서 작업할 노드를 지정한다.

o    node-id   제거할 노드 ID 지정한다.

o     명령은 마지막에 레디스 인스턴스를 shutdown 한다.

o    다운된 노드에 대해서는  명령을 실행할  없다.   왜냐하면  명령은 해당 노드에 접속해서 확인  진행하는데접속할  없기 때문이다.   이때는 redis-cli 접속해서 cluster forget node-id 명령으로 제거한다.

o    다음은 5001번에 접속해서 5007 노드를 제거하는 명령과 메시지다.

redis-trib.rb del-node 127.0.0.1:5001 b8b8b72fb2b5305ad63290bb1aa24cf81fce1bc2

>>> Removing node b8b8b72fb2b5305ad63290bb1aa24cf81fce1bc2 from cluster 127.0.0.1:5001

>>> Sending CLUSTER FORGET messages to the cluster…

>>> SHUTDOWN the node.

원본 위치 <http://www.redisgate.com/redis/cluster/redis-trib.php>

확인 작업

아래 생성된 슬롯수 및 ok가 일치하면 (클러스터링 개당 슬롯이 분리되어있음)

Nodes 수가 설정값과 일치하는지 known nodes 확인

Size 에서 클러스터링 값을 확인

[root@ip-10-24-20-62 redis]# redis-cli -h localhost

localhost:6379> cluster info

cluster_state:ok

cluster_slots_assigned:16384

cluster_slots_ok:16384

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:6

cluster_size:3

cluster_current_epoch:6

cluster_my_epoch:4

cluster_stats_messages_sent:4481

cluster_stats_messages_received:4440

localhost:6379>

클러스터 노드수는 아래와 같이 확인

localhost:6379> cluster nodes