2015년 3월 19일 목요일

Rsync 설정

================================================================
rsync server 192.168.1.200
rsync client   192.168.1.201
================================================================


패키지 설치 여부 확인
================================================================
# rpm -qa | grep rsync     
    rpm install rsync      설치가 안 되어 있을 시
# rpm -qa | grep xinetd
    rpm install xinetd     설치가 안 되어 있을 시
================================================================


rsync 서버 설정_rsync 사용 설정
# vi /etc/xinetd.d/rsync
'disable = yes' 라고 되어있는 부분을 'disable = no' 로 변경한다.
================================================================
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
        disable = no
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
====================================================================



rsync 서버 설정 _ rsync 설정
# vi /etc/rsyncd.conf
/etc/rsyncd.conf의 경우 처음에는 없는 파일일 가능성이 높다. 편집기를 이용해 새로 작성해준다.
====================================================
[test]                                 -> 사용할 rsync 서비스 이름
path=/data/test/                  -> 데이터 원본 경로
comment = test                   -> 코멘트
uid = root                                       -> 권한 사용자
gid = root                                       -> 권한 그룹
use chroot = yes
read only = yes
hosts allow = 192.168.0.201     -> rsync 클라이언트 IP , local일경우 입렵 필요 없음
max connections = 3
timeout=600
====================================================


rsync 서버 설정 5) xinetd 서비스 재시작 및 방화벽 확인 (873 포트 허용)
====================================================
# /etc/init.d/xinetd restart
====================================================


rsync client 설정
====================================================
# telnet [rsync 서버 IP] 873
ex) telnet 192.168.1.200 873        rsync 접속 여부 확인

# rsync -avz [IP]::[서비스명] [저장디렉토리]
ex) # rsync -avz 192.168.1.200::test /data/test

혹시 내역을 로그로 남기고 싶을 경우 아래와 같이 입력한다.
rsync -avz 192.168.1.200::test /data/test > /data/test/rsync.log
====================================================


데이터 동기화 시 crontab 사용 (client server에서 설정)
====================================================
#crontab -e
편집창에 아래와 같이 입력(매분 마다 동기화)
* * * * * rsync -avz 192.168.1.200::test  /data/test
====================================================

2015년 2월 25일 수요일

CentOS 6.6 삼바설치 (SMB)






1. SAMBA 설치


# yum install samba




2. samba 사용자 추가 및 비밀번호 설정

# smbpasswd -a nell <- (samba계정)

- 계정 삭제 : # smbpasswd -d nell <- (samba계정)









3. smb.conf 파일 수정


# vi /etc/samba/smb.conf












4. 방화벽 설정 (iptables 등록)


# vi /etc/sysconfig/iptables





추가


-A INPUT -m state --state NEW -m tcp -p tcp --dport 149 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT





5. SMB & iptables 재시작

# /etc/init.d/smb restart

# /etc/init.d/iptables restart






6. 시작 + r  누른 후 samba ip 입력
























2015년 2월 23일 월요일

[ openstack ] SSH - PuTTY 접속 방법





PuTTY를 이용한 키패어 접속


openstack에 aws (amazon web service )와 마찬가지로 인스턴스 이미지를 생성하게 되면, Redhat 계열 OS를 사용할 경우 키 패어 없이 로그인을 할 수 없다.
이것을 해결하기 위해 인스턴스에서 키 패어를 생성하고, Putty를 이용하여 접속 할 수 있게하는 방법이다.




1. openstack 키 패어 생성








2. .pem 파일 다운로드










3. puttygen download

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html











4. Putty Key Generator 실행 -> Import Key -> Save private key

    파일명.ppk 로 저장










5. putty 실행 -> SSH -> Auth -> 조금 전 만든 .ppk 파일 선택 후 open

참고로 이 작업들을 하기전에 인스턴트 볼륨들을 생성해 놔야 그쪽으로 접속하겠지요..??


































2015년 1월 29일 목요일

MRTG 설치하기




기본적으로 APM 설치가 되어있어야 한다.


APM yum 설치하기




1. 준비사항

CentOS, APM




2. snmp 설치

1) snmp 설치
[root@nell /]# yum install net-snmp*





 2) /etc/snmp/snmpd.conf 설정


# First, map the community name "public" into a "security name"
#       sec.name  source          community
#com2sec notConfigUser  default       public
com2sec fserver          127.0.0.1     community

# Second, map the security name into a group name:
#       groupName      securityModel securityName
#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
group    fgroup         v1      fserver
group    fgroup         v2c    fserver
# Third, create a view for us to let the group have rights to:
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view     all           included   .1
# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access   fgroup         ""      any       noauth    exact  all        none none


3) snmp 데몬 실행

/etc/init.d/snmpd start







3. MRTG 설치

[root@nell /]#  cd /usr/src
[root@nell /]#  wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.17.4.tar.gz
[root@nell /]#  tar xvfz mrtg-2.17.4.tar.gz
[root@nell /]#  cd mrtg-2.17.4
[root@nell /]#  ./configure –with-gd=/usr/local/gd –with-z=/usr/local/zlib –with-png=/usr/local/libpng
[root@nell /]#  make
[root@nell /]#  make install




4. MRTG 웹 설정

  1) 웹설정 (<Directory> 설정)
[root@nell /]#  adduser mrtg
[root@nell /]#  mkdir /home/mrtg/public_html
[root@nell /]#  mkdir /home/mrtg/public_html/localhost
[root@nell /]#  mkdir /home/mrtg/conf
[root@nell /]#  chmod 755 /home/mrtg
[root@nell /]#  chown mrtg.mrtg /home/mrtg
[root@nell /]#  vi /etc/httpd/conf/httpd.conf

~ 중략 ~
<IfModule mod_userdir.c>
    # UserDir disabled
    UserDir public_html

</IfModule>
<Directory /home/*/public_html>
</Directory>
~ 중략 ~








2) cfgmaker
   (모니터링할 대상항목의 Config 파일을 생성하는 작업 )


[root@nell /]#  cd /usr/local/mrtg-2/bin
[root@nell /]#  ./cfgmaker –global 'WorkDir: /home/mrtg/public_html/localhost' –global 'Options[_]: bits,growright' –output /home/mrtg/conf/localhost.cfg community@127.0.0.1







3) 모니터링 Config 수정
  (/home/mrtg/conf/localhost.cfg 하단부에 추가 합니다.)




### CPU Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:community@127.0.0.1
MaxBytes[cpu]: 2000
#Unscaled[cpu]: dwmy
Options[cpu]: integer, gauge,withzeroes, growright, noinfo, nopercent
YLegend[cpu]: CPU Load Average
ShortLegend[cpu]: (%)
LegendI[cpu]: Aver 1/minite
LegendO[cpu]: Aver 5/min
Legend1[cpu]: Aver 1/minite
Legend2[cpu]: Aver 5/min
Title[cpu]: CPU Load
PageTop[cpu]: </p><h1>CPU Load Average</h1>
### Rate of CPU use ###
Target[cpu_use]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.52.0:community@127.0.0.1
MaxBytes[cpu_use]: 100
Options[cpu_use]: growright, noinfo, nopercent
YLegend[cpu_use]: CPU usage(%)
ShortLegend[cpu_use]: (%)
LegendI[cpu_use]: User
LegendO[cpu_use]: System
Legend1[cpu_use]: CPU usage(User)(%)
Legend2[cpu_use]: CPU usage(System)(%)
Title[cpu_use]: Rate of CPU use
PageTop[cpu_use]: <h1>Rate of CPU use</h1>
### Memory Free ###
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:community@127.0.0.1
MaxBytes1[mem]: 7513968
MaxBytes2[mem]: 7513968
Unscaled[mem]: dwmy
Options[mem]: gauge, growright, noinfo
YLegend[mem]: Mem Free(Bytes)
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: RAM [MBytes]
Legend2[mem]: Swap Memory [MBytes]
Title[mem]: Memory Free
PageTop[mem]: <h1>Memory Free</h1>






4) indexmaker 및 mrtg 쿼리
[root@nell /]#  cd /usr/local/mrtg-2/bin
[root@nell /]#  ./indexmaker –title "Localhost" /home/mrtg/conf/localhost.cfg > /home/mrtg/public_html/localhost/index.html
[root@nell /]#  env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/localhost.cfg


------------------------------------------------


5. 웹사이트 및 crontab 적용
 
 1) 리다이렉션 페이지 생성

[root@nell /]#  cat > /home/mrtg/public_hml/index.html
<meta http-equiv="refresh" content="1;url=./localhost/index.html">




  2) 모니터링 스크립트 작성 및 crontab 등록


[root@nell /]#   cat > /script/mrtg.sh

#!/bin/bash
env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/localhost.cfg



[root@nell /]#  crontab -e 
*/1 * * * * /scripts/mrtg.sh






























APM(Apache + PHP + Mysql) yum 설치




1. APM 설치

[root@nell /]# yum -y install httpd php mysql mysql-server php-mysql






2. 라이브러리 설치

[root@nell /]# yum -y install zlib zlib-devel freetype freetype-devel freetype-utils gd gd-devel libjpeg libjpeg-devel libpng libpng-devel php-gd php-xml php-mbstring






3. 서비스 시작

[root@nell /]# service httpd restart; service mysqld restart






4. RHEL Repository 추가

[root@nell /]# cd /usr/src
[root@nell /]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@nell /]# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[root@nell /]# rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
[root@nell /]# ls -1 /etc/yum.repos.d/epel* /etc/yum.repos.d/remi.repo
/etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel-testing.repo
/etc/yum.repos.d/remi.repo







5. php-mcrypt 설치

[root@nell /]# yum -y install libmcrypt libmcrypt-devel php-mcrypt





6. Directory 설정 및 phpMyadmin 설치

1) Apache Directory 설정 (httpd.conf 편집)

[root@nell /]# vi /etc/httpd/conf/httpd.conf

 # UserDir disabled
       UserDir public_html



2) phpMyadmin 설치

[root@nell /]# adduser phpma
[root@nell /]# cd /home/phpma
[root@nell /]# wget http://jaist.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.1.12/phpMyAdmin-4.1.12-all-languages.tar.gz
[root@nell /]# tar xvfz phpMyAdmin-4.1.12-all-languages.tar.gz
[root@nell /]# mv phpMyAdmin-4.1.12-all-languages public_html
[root@nell /]# chown phpma.phpma ./public_html/ -R
[root@nell /]# chmod 755 /home/phpma























awk 사용방법

“awk 는 유닉스에서 처음 개발된 스크립트 언어로 텍스트 형태로 되어있는 데이타를 필드로 구분하여 처리하는 기능을 기본으로 합니다. 주로 패턴검색과 조작을 통해  레포트를 만드는 등의 작업에 사용됩니다. 여기서는 awk 를 활용할 수 있는 몇가지 예제와 문법을 설명합니다. 
1. awk 활용예제
 1) date 명령의 결과값을 awk 로 년도와 월만 출력하는 보고서 형태
[root@localhost ~]# date | awk '{print "Year : "$1 "\nMonth : "$2}'
Year : 2015.
Month : 01.
2) /etc/passwd 파일을 ‘:’ 구분자로 나누어 세번째 필드 uid 가 500 이상인 경우 첫번째 필드 출력
[root@localhost ~]# cat /etc/passwd | awk -F: '$3 > 500 {print $1}'
apple
mark
kimC
3) 디스크 사용량이 10MB 이상인 경우만 출력
[root@localhost home]# du ./ | awk '$1 > 10000 {print}'
10604   ./abc/public_html/locale
33296   ./abc/public_html
41864   ./abc
4) ClamAV 스캔결과 감염된 파일에 대한 내용을 수합한 파일 test.txt 에서 전체 합계를 구하기
[root@localhost home]# cat test.txt
Infected files: 0
Infected files: 0
Infected files: 3
Infected files: 0
Infected files: 0
Infected files: 5
Infected files: 1
Infected files: 0
Infected files: 1
[root@localhost home]# awk '{sum += $3 } END {printf "SUM : " sum"\n"}' ./test.txt
SUM : 10
– 여려개의 txt 파일에서 한번에 합계 구하기
[root@localhost ~]# find ./ -name '0*.txt' | xargs cat | awk '$1 == "Infected" {sum += $3 } END {printf "SUM : " sum"\n"}'
SUM : 10
5) /var/log 디렉토리에 500MB 이상 파일을 압축
[root@localhost log]# ls -al mes* | awk '$5 > 500000 {system("gzip -f "$8)}'
6) 로그인 정보 중 root 가 로그인한 로그 중 부팅시 발행한 로그를 제외하고 출력
[root@localhost ~]# last | awk '$1 =="root" && $3 != "boot" {print}'
root     pts/0        192.168.11.6     Tue Jan 20 09:03   still logged in
root     tty1                          Tue Jan 20 09:02   still logged in
root     pts/0        192.168.11.6     Tue Jan 20 01:02 - down   (00:24)
~
2. awk 문법
1)  awk 프로그램의 구조
awk ‘패턴 {액션}’ 파일명
2) awk 의 패턴
BEGIN    입력화일을 읽어들이기 전 옆에 제시되는 문자열을 실행
END       awk 가 모든 입력을 처리한 후 옆에 제시되는 문자열을 실행
3) awk 의 연산자
=    +=    -=    *=    /=    %=    배정연산자
+    –    *    /    %    ++    —      산술연산자
||    &&    !                            논리연산자(OR, AND, NOT)
>    >=    <    <=    ==    !=      비교연산자
v ~p                                       변수 v가 패턴 P에 부합되면 참
v !~p                                      변수 v가 패턴 P에 부합되지 않으면 참
4) awk 에 미리 정의된 변수
변수              내용
FILENAME    현재 처리되고 있는 입력 파일의 이름
FS                  입력 필드 분리문자
NR                 현재 레코드(행)의 번호
NF                  현재 레코드(행)의 필드의 갯수
OFS                출력되는 필드의 분리문자

windows xcopy와 robocopy (rsync와 같음) 옵션 및 사용방법



1. Robocopy 사용법

 1) 사용 예
c:\robocopy d:\data e:\back /MIR /R:1 /LOG:e:\back\backup_log_%date%.txt

2) 사용법
robocopy 원본 대상 [옵션]
3) 옵션
/E                            ::    비어 있는 디렉터리를 포함하여 하위 디텍터리를 복사
/L                            ::    실제 복사하지 않고 목록만 출력
/XF file [file]…       ::    지정된 이름/경로/와일드카드와 일치하는 파일을 제외
/XD dirs [dirs]…    ::    지정된 이름/경로와 일치하는 디렉터리를 제외
/PURGE                 ::    원본에 없는 대상 파일/디렉터리를 삭제
/MIR                      ::    미러링. /E 와 /PURGE 를 함께 쓰는 것
/R:n                       ::    실패한 복사본에 대한 다시 시도 횟수
/W:n                      ::    다시 시도 간 대기시간
/LOG:file               ::    상태를 로그파일에 출력
robocopy/? 통해 많은 옵션을 확인가능



-------------------------------------

2. xcopy 사용법

1) xcopy 사용 예
@echo off
xcopy /C/R/E/D/H/S/Y D:\data E:\back

2) 사용법
xcopy [옵션] 원본 대상
3) 옵션
/C        오류가 생겨도 계속복사
/R        읽기 전용 파일을 겹쳐쓰기
/E        비어 있는 경우를 포함 디렉터리와 하위 디렉터리를 복사
/D        대상 파일보다 새로운 원본 파일만 복사
/H        숨겨진 파일과 시스템 파일도 복사
/S        비어 있지 않는 디렉터리와 하위 디렉터리를 복사
/Y        기존 대상 파일을 덮어쓸지 여부를 묻지 않음