Posted
Filed under Linux
scp 명령어를 이용한 파일 복사 및 전송

 

  ssh에서 제공되는 scp 명령어를 통해 로컬서버↔원격서버 로의 파일을 간단하게 전송할 수 있다.

 

 1. 사용방법
    1) 원격 서버 → 로컬 서버로 파일 전송
        # scp [옵션] [계정명]@[원격지IP주소]:[원본 경로 및 파일] [전송받을 위치]


        예제1) IP 111.222.333.444 서버의 abc라는 계정으로 /home/abc/index.html 파일을 로컬서버 /home/me/ 디렉토리에 전송 받기

                    # scp abc@111.222.333.444:/home/abc/index.html /home/me/

 

    2) 로컬 서버 → 원격 서버로 파일 전송
        # scp [옵션] [원본 경로 및 파일] [계정명]@[원격지IP주소]:[전송할 경로]


        예제2) 로컬서버 /home/me/wow.html 파일을 IP 111.222.333.444 서버의 /home/abc/ 디렉토리에 전송 하기
                   # scp /home/me/wow.html abc@111.222.333.444:/home/abc/

 

    3) ssh포트를 기본 22번으로 사용하고 있지 않는 서버로의 전송


        예제3) 2222번인 SSH포트를 사용한다면 아래와 같이 –P 옵션과 포트번호를 넣어준다.
                  # scp –P 2222 abc@111.222.333.444:/home/abc/index.html /home/me/
                  # scp –P 2222 /home/me/wow.html abc@111.222.333.444:/home/abc/

 

        [주의사항]
        옵션중에 –P와 –p가 있으니 대/소문자 확인을 하여야 한다.
        -P : 포트번호를 지정함
        -p : 원본파일 수정/사용시간 및 권한을 유지함
        -r : 하위 디렉토리 및 파일 모두 복사함

[원문]
http://faq.hostway.co.kr/?mid=Linux_ETC&page=9&document_srl=1426

2018/06/07 13:46 2018/06/07 13:46
Posted
Filed under Linux
cat /proc/$(pgrep maxscale)/limits
실행 하면 maxscale의
open file 쪽에 1024로 설정 되어 있습니다.
이부분을 늘려 주기 위해서는
vi /usr/lib/systemd/system/maxscale.service
LimitNOFILE=65536
위와 같이 설정 합니다.

2018/04/09 13:45 2018/04/09 13:45
Posted
Filed under Linux

호스트 내임 변경
hostnamectl set-hostname  blog.visualp.com

호스트 내임 확인
hostname

현재 세션(쉘)에서는 바뀌지 않지만,
재접속 하면 변경된것을 확인 할 수 있습니다.



2018/04/05 14:48 2018/04/05 14:48
Posted
Filed under Linux
Redis can’t set maximum open files to 10064 because of OS error: Operation not permitted.,
Redis can't set maximum open files to 10064 because of OS error: Operation not permitted.
Increased maximum number of open files to 10032 (it was originally set to 1024).

[cenos7]
ulimit -n 32768

change maximum number of open files  1024 to 32768

[참조]
http://myblog.opendocs.co.kr/archives/tag/redis-cant-set-maximum-open-files-to-10064-because-of-os-error-operation-not-permitted
2018/03/30 21:25 2018/03/30 21:25
Posted
Filed under Linux

기본적인 사용법

# rsync [옵션] [계정]@[sourcePC:/디렉토리] [target 디렉토리]

-a : archice mode ( 심볼릭 링크, 속성, 퍼미션, 소유권 등 보곤)

-v : verbose mode (자세한 정보 출력)

-z : compress (전송시 압축)

-r : 하위 디렉토리 포함

-u :  --update update only (don't overwrite newer files)

-e ssh : ssh를 이용한 rsync 동기화

--stats : 결과보고

--delete : 원본 서버에 없는 파일은 백업 서버에서 삭제

--progress : rsync 진행 상항 보기

--exclude : 제외할 파일 지정

--bwlimit : 대역폭(복사속도) 제어

--max-size : 특정 크기 이상 파일 제외(rsync 2.6.4 버전부터 추가된옵션)

--min-size : 특정 크기 이하 파일 제외(rsync 2.6.7 버전부터 추가된옵션)

 

응용

1) 단순동기화(원본파일 복사)

ex) rsync -avz root@soucepc:/data/backup  /data/backup

2) 동기화(삭제파일도 동일적용)

ex) rsync -avz --delete root@soucepc:/data/backup  /data/backup

3) 대역폭 조절

ex) rsync -avz --bwlimit=1024 root@soucepc:/data/backup  /data/backup

4) -e ssh

ex) rsync -avz -e "ssh -i /home/test/rsync-key" root@soucepc:/data/backup  /data/backup

5) 특정파일

ex) rsync -avz --exclude=.txt --exclude=.sh root@soucepc:/data/backup  /data/backup/

6) 특정폴더

ex) rsync -avz --exclude=aaa(폴더1) --exclude=bbb(폴더2) root@soucepc:/data/backup  /data/backup/

7) 날짜(3일이내 파일만 복사)

ex) find . -type f -mtime -3  | rsync -avz --files-from=- /soucepc /data/backup



[원문]http://algo79.tistory.com/entry/rsync-%EC%82%AC%EC%9A%A9%EB%B2%95%EB%8C%80%EC%97%AD%ED%8F%AD%EB%82%A0%EC%A7%9C%ED%8F%B4%EB%8D%94%ED%8C%8C%EC%9D%BC%ED%81%AC%EA%B8%B0%EB%93%B1
2018/01/24 11:04 2018/01/24 11:04
Posted
Filed under Linux
Apache Tomcat 설치후 관리자 모드 실행 되지 않을때 문제 해결방법
버전 : Tomcat 8

파일 : tomcat-users.xml
경로 : 톰캣설치디렉토리/conf

<!-- 아래 내용 추가--> <role rolename="manager-gui"/> <user username="tomcat" password="비밀번호 작성" roles="tomcat,manager-gui"/>



파일 : server.xml
경로 : 톰캣설치디렉토리/conf

<Service name="Catalina"> .......... <!-- 아래 내용 추가--> <Connector port="9009" protocol="AJP/1.3" redirectPort="9443" address="192.168.0.52" useIPVHosts="true" />

파일 : context.xml
경로 : 톰캣설치디렉토리/webapps/manager/META-INF

allow에 접속하려는 클라이언트PC의 IP주소를 추가

<Context antiResourceLocking="false" privileged="true" > <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.168\.0\.52|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> </Context>


위 3가지 수정후 서버 재시작

 

[원문]
http://blog.naver.com/PostView.nhn?blogId=ses1030&logNo=220823127740

2018/01/12 09:43 2018/01/12 09:43
Posted
Filed under Linux

 centos7 하드 마운트

[원문]http://zero-gravity.tistory.com/297

 추가하고 싶은 하드디스크의 용량이 2TB를 초과한다면 6번 과정으로 바로 갈 것.

 

 

 

   1. fdisk -l

   

   드라이브 목록을 확인한다.

 

# fdisk -l

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048  1469032447   734003200   83  Linux

/dev/sda3      1469032448  1510975487    20971520   83  Linux

/dev/sda4      1510975488  1953523711   221274112    5  Extended

/dev/sda5      1510977536  1531949055    10485760   83  Linux

/dev/sda6      1531951104  1552922623    10485760   83  Linux

/dev/sda7      1552924672  1560788991     3932160   82  Linux swap / Solaris

/dev/sda8      1560791040  1952958463   196083712   83  Linux

 

Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

 

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

 

 

   할당되지 않은 4TB 크기의 /dev/sdb 드라이브가 보인다. 이걸 파티션 할당해줘야 한다.

   (리눅스는 보통 첫번째 드라이브가 /dev/sda1,2,3...두번째 드라이브가 /dev/sdb1,2,3... 이렇게 설정된다.)

 

 

   2. fdisk /dev/[디스크명]

 

   새로운 하드디스크를 추가한다.

 

# fdisk /dev/sdb

 

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x6ad31b53.

 

WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).

 

 

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

 

Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

 

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p):p  

Partition number (1-4, default 1): 1

First sector (2048-4294967295, default 2048): 2048

Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294):  #Enter를 치면 default로 잡힌다.  

Using default value 4294967294

 

Partition 1 of type Linux and of size 2 TiB is set 

#하드디스크의 용량은 4TB이지만, 파티션에 할당할 수 있는 최대 크기는 2TB다.

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

Syncing disks.

 

 

   3. mkfs -t [파일시스템] /dev/[디스크명]

   파일시스템 만들기.

 

mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

134217728 inodes, 536870655 blocks

26843532 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

16384 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 

102400000, 214990848, 512000000

 

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

 

 

   4. mount -t [파일시스템] /dev/[디스크명] 

   마운트하기.

 

mount -t ext4 /dev/sdb1 /second

 

df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

 

/dev/sdb1       2.0T   81M  1.9T   1% /second   # 새로 마운트한 드라이브가 보일 것이다.

 

 

   이렇게 하면 4TB의 하드디스크 중에 2TB를 할당해서 사용할 수 있다.

 

   그러나 2TB씩 쪼개서 사용하기 싫고 4TB를 통으로 사용하고 싶다면, 다르게 설정해줘야 한다. 

 

 

   5. 되돌리기

 

   우선, 추가해줬던 파티션을 삭제하고 마운트도 다시 해제하자.

 

# fdisk /dev/sdb

 

WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).

 

 

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

 

Command (m for help): d

Selected partition 1

Partition 1 is deleted

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: 장치나 자원이 동작 중.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

 

# umount /second

 

   df- h로 확인해보면 디스크를 추가하지 전의 원래 상태로 돌아옴을 확인할 수 있다. 

 

 

 

   6. 2TB를 초과하는 디스크 할당하기.

 

   2TB를 초과하는 파티션을 할당하기 위해선 parted 명령어를 사용해야 한다.

 

parted /dev/sdb

GNU Parted 3.1

Using /dev/sdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) help                                                             

  align-check TYPE N                        check partition N for TYPE(min|opt) alignment

  help [COMMAND]                           print general help, or help on COMMAND

  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)

  mkpart PART-TYPE [FS-TYPE] START END     make a partition

  name NUMBER NAME                         name partition NUMBER as NAME

  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a

        particular partition

  quit                                     exit program

  rescue START END                         rescue a lost partition near START and END

  rm NUMBER                                delete partition NUMBER

  select DEVICE                            choose the device to edit

  disk_set FLAG STATE                      change the FLAG on selected device

  disk_toggle [FLAG]                       toggle the state of FLAG on selected device

  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER

  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER

  unit UNIT                                set the default unit to UNIT

  version                                  display the version number and copyright information of GNU Parted

(parted) mklabel gpt                                                      

Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?

Yes/No? yes                                                               

(parted) unit TB  # 단위를 설정한다. GB or TB                                                         

(parted) mkpart primary 0.00TB 4.00TB  # 용량 설정 start end

(parted) print                                                            

Model: ATA HGST HDN726040AL (scsi)

Disk /dev/sdb: 4.00TB

Sector size (logical/physical): 512B/4096B

Partition Table: gpt

Disk Flags: 

 

Number  Start   End     Size    File system  Name     Flags

 1      0.00TB  4.00TB  4.00TB  ext4         primary         # 정상적으로 추가됐다.

 

(parted) quit 

Information: You may need to update /etc/fstab.                                   

 

   파일시스템을 만든다.

# mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

244195328 inodes, 976754176 blocks

48837708 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=3124756480

29809 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 

102400000, 214990848, 512000000, 550731776, 644972544

 

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

 

   마운트한다.

# mount -t ext4 /dev/sdb1 /second

 

# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

 

/dev/sdb1       3.6T   89M  3.4T   1% /second   # 마운트 완료

 

 

   이 과정을 모두 마쳤다면, /second 폴더에 넣는 파일들은 모두 새로 추가한 디스크에 저장될 것이다.

 

   그러나 재부팅 시 마운트가 자동으로 해제되기 때문에, 부팅할 때 자동으로 마운트를 해주는 설정을 해줘야 한다.

 

 

   7. fstab 파일 등록

 

   재부팅 시 자동마운트가 되도록 설정한다.

 

# blkid   # 먼저 자동마운트 등록할 디스크의 UUID를 알아내야 한다.

/dev/sda1: UUID="22a87868-322e-4661-af01-93b2062044ce" TYPE="xfs" 

.

.

.

/dev/sdb1: UUID="e001a7f9-1154-129e-a916-dad0b54116f2" TYPE="ext4" PARTLABEL="primary" PARTUUID="52412c84-700e-2313-9e2f-c12b1ca1676a"

 

# vi /etc/fstab

 

 

#

# /etc/fstab

# Created by anaconda on Sat Sep 26 08:52:44 2015

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=1c407d96-e43b-4b52-af5f-b191560e8267 /                       ext4    defaults        1 1

.

.

.

.

 

UUID=e001a7f9-1154-129e-a916-dad0b54116f2 /second              ext4    defaults        1 2  # 여기에 추가한다.

 

 

 

   이렇게 하면 재부팅을 하더라도 자동마운트 된다.

 

   굳이 재부팅을 할 필요없이 자동으로 마운트가 되는지 확인하고 싶다면, 마운트를 해제하고 mount -a 을 해보면 된다.

2017/10/11 16:52 2017/10/11 16:52
Posted
Filed under Linux
- LISTEN 되는 모든 포트
netstat -l 또는 netstat -nap | grep LISTEN

- 모든 서비스 동시 접속자 수
netstat -nap | grep ESTABLISHED | wc -l

- 웹 동시 접속자 수
netstat -nap | grep :80 | grep ESTABLISHED | wc -l

- 웹서버 커넥션수 체크

netstat -n|grep -F :80|egrep '(ESTAB|SYN)'|awk '{print $5}'|sed 's/:[0-9]*//'|sort -u|wc -l
  

2017/08/18 10:01 2017/08/18 10:01
Posted
Filed under Linux
1. 톰켓 클러스터링 설정(config tomcat clustering)
[참고]
http://khaidoan.wikidot.com/tomcat-cluster-session-replication-without-multicasting
참고 하여 설정 함

ip 기반으로 서버 분산 처리 하는 경우
한 서버에 여러 개의 톰켓을 세팅 하는 방법은 검색하면 쉽게 해결 할 수 있음
본 글에서는 서로다른  ip주소 톰켓 을 세션 클러스터링 하기 위해서 ~


 <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true" />
바로 이부분이 아이피 기반 설정을 하기 위해서 필요함 Manager
톰켓 메니저의 자세한 설명은 tomcat.apache.org에 방문하면 확인 할 수 있음.

domain <--부분은 서로 일치 해야하며 , 
port <-- 서로다른 서버 임으로 4100포트로 통일

HOST 엘리먼트의 CONTEXT엘리먼트 PATH는 일치 해야함
session은 context기반으로 생성 됨으로 


붉은 색으로 표시 된 부분이 설정의 핵심임 UNIQUE아이디는 서로 달라야 함

LocalMember 은 자신의 서버 정보를 입력하면 되고

Member  은 원격지 서버의 정보를 입력 하면됨


마지막으로 

배포하는 어플리케이션의 web.xml에는 
<distributable />엘리먼트를 추가한다.


이렇게 하면 우선 서버 설정은 끝 
NGINX에서 로드벨런싱 세팅

server {
 
    listen       80;
    server_name  ssogate.fourfree.com;
    client_max_body_size 100M;
 
        location / {
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $remote_addr;
                proxy_pass http://tomcat;
        }
 
        location ~^/ssogate2/* {
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $remote_addr;
                proxy_pass http://tomcat2;
        }
}

ssogate.fourfree.com 서버의  nginx 설정 입니다.
ssogate.fourfree.com <-http://tomcat;
ssogate.fourfree.com/ssogate2/ <-- http://tomcat2;
으로 접근 하도록 설정 함 니다.

비록 서브 도메인이나 / 서로다른 도메인을 가지고 session을 공유 한것은 아니지만
사이트 내에서 덩치가 큰 서비스를 분리해 주기 위해서 tomcat 클러스터링을 이용했습니다.

소규모 사이트에서는 괜찮은 방법 같아 보입니다. sso 솔루션을 구매 하거나 josso를 이용해서 구축 해야 하지만 .
간단하게 session을 공유 할 수 있습니다. 
이방식으로 사이트 개발 후 서버에 배포 하려고 합니다 .~




server.xml1 설정
---------------------------------------------
 <Host name="ssogate.fourfree.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
        <!--
                <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
                <Alias>ssogate.fourfree.com</Alias>
                <Context path="/" docBase="/home/homepage/public_html" reloadable="true" workDir="/home/homepage/public_html/WEB-INF/classes" distributable="true"  className="org.apache.catalina.ha.context.ReplicatedContext"  sessionCookieDomain=".fourfree.com"  >
 
                <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true" />
 
 
                </Context>
 
                <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
           channelSendOptions="8">
 
    <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true" />
 
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
      <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                address="1.220.141.43"
                port="4100"
                autoBind="100"
                selectorTimeout="5000"
                maxThreads="6" />
 
      <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
        <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
      </Sender>
 
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
 
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
 
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor" />
 
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
 
        <LocalMember className="org.apache.catalina.tribes.membership.StaticMember"
                                                port="4100"
                                                securePort="-1"
                                                host="ssogate.fourfree.com"
                                                domain="tomcat-cluster"
                                                uniqueId="{15,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0}"/>
 
        <Member className="org.apache.catalina.tribes.membership.StaticMember"
                host="ssogate2.fourfree.com"
                port="4100"
                securePort="-1"
                domain="tomcat-cluster"
                uniqueId="{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}" />


      </Interceptor>
    </Channel>
 
    <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
           filter="" />
 
    <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
 
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
  </Cluster>
</Host>



=============================================================================================================================
server.xml2 설정
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
 
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
 
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>
 
      <!--
 <Context docBase="C:\Users\visualp\Desktop\java\sts\workspace-sts-3.6.2.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ROOT" path="" reloadable="false"/>
 -->
 <Alias>ssogate.fourfree.com</Alias>
 <Alias>ssogate2.fourfree.com</Alias>
 <Context docBase="C:\Users\visualp\Desktop\java\sts\workspace-sts-3.6.2.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\homepage" path="/" reloadable="true" source="org.eclipse.jst.jee.server:homepage" distributable="true"
className="org.apache.catalina.ha.context.ReplicatedContext"
sessionCookieDomain=".fourfree.com"
 >
 
<Manager 
className="org.apache.catalina.ha.session.DeltaManager" 
expireSessionsOnShutdown="false" 
notifyListenersOnReplication="true"
/>
 
 </Context>
 
 
<Cluster 
channelSendOptions="6" 
channelStartOptions="3" 
className="org.apache.catalina.ha.tcp.SimpleTcpCluster" defaultMode="true">
 
 
 
<Manager 
className="org.apache.catalina.ha.session.DeltaManager" 
expireSessionsOnShutdown="false" 
notifyListenersOnReplication="true"
/>
 
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</Sender>
<Receiver 
address="61.32.203.30" 
autoBind="0" 
domain="tomcat-cluster"
className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
maxThreads="6" 
port="4100" 
selectorTimeout="5000"
/>
<!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
 
<LocalMember className="org.apache.catalina.tribes.membership.StaticMember"
port="4100"
securePort="-1"
host="ssogate2.fourfree.com"
domain="tomcat-cluster"
uniqueId="{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}"/>
 
 
<Member className="org.apache.catalina.tribes.membership.StaticMember" 
port="4100" 
securePort="-1"
host="ssogate.fourfree.com" 
domain="tomcat-cluster"
uniqueId="{15,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0}" />
/>
 
</Interceptor>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" 
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
</Host>




2016/04/08 15:11 2016/04/08 15:11
Posted
Filed under Linux


형식

upstream 이름 {
    [ip_hash;]
    server host 주소:포트 [옵션];
    .....
}

옵션

옵션으로 올 수 있는 값은 아래와 같다.

  • ip_hash : 같은 방문자로부터 도착한 요청은 항상 같은 업스트림 서버가 처리 할 수 있게 한다.
  • weight=n : 업스트림 서버의 비중을 나타낸다. 이 값을 2로 설정하면 그렇지 않은 서버에 비해 두배 더 자주 선택된다.
  • max_fails=n : n으로 지정한 횟수만큼 실패가 일어나면 서버가 죽은 것으로 간주한다.
  • fail_timeout=n : max_fails가 지정된 상태에서 이 값이 설정만큼 서버가 응답하지 않으면 죽은 것으로 간주한다.
  • down : 해당 서버를 사용하지 않게 지정한다. ip_hash; 지시어가 설정된 상태에서만 유효하다.
  • backup : 모든 서버가 동작하지 않을 때 backup으로 표시된 서버가 사용되고 그 전까지는 사용되지 않는다.

예제

예를들면 아래와 같다.

upstream backend {
    ip_hash;
    server 192.168.125.142:9000 weight=3;
    server 192.168.125.143:9000;
    server 192.168.125.144:9000 max_fails=5 fail_timeout=30s;
    server unix:/var/run/php5-fpm.sock backup;
}

위의 설정을 풀어보면 아래와 같다.

같은 IP는 같은 업스트림 서버에 접속한다.
(ip_hash) 192.168.125.142 서버는 다른 서버 대비 3배 더 자주 사용된다.
192.168.125.144 서버는 30초 동안 응답하지 않는 상태가 5번 지속되면 죽은 것으로 간주하고 더 이상 요청을 보내지 않는다.
같은 호스트에 설치되서 소켓을 통해서 통신하는 FastCGI 에플리케이션은 백업용도이기 때문에 평소에는 사용하지 않다가 나머지 서버들이 불능상태가 되었을 때 자동으로 활성화된다.

2016/03/30 09:20 2016/03/30 09:20