레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시

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년 1월 29일 목요일

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                출력되는 필드의 분리문자

2015년 1월 6일 화요일

Nginx + OpenSSL 설치 SSL 인증서 만들기



키 생성

개인 키 (.key) 와 인증서 서명 요청 파일 (.csr)을 생성

# openssl req -new -newkey rsa:2048 -nodes -keyout <파일명>.key -out <파일명>l.csr

Generating a 2048 bit RSA private key
.....................+++
................................................+++
writing new private key to '<파일명>l.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:KR(국가코드)
State or Province Name (full name) [Some-State]:Korea(국가)
Locality Name (eg, city) []:Seout(지역)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<회사명>
Organizational Unit Name (eg, section) []:<부서명>
Common Name (e.g. server FQDN or YOUR name) []:<name>
Email Address []:<이메일>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:<비밀번호>
An optional company name []:<비밀번호>




#ls -al

-rw-r--r--.  1 root root     1070 Jan  7 14:55 nell.csr

-rw-r--r--.  1 root root     1708 Jan  7 14:55 nell.key


자체 서명된 SSL 인증서를 생성

# openssl x509 -req -days 365 -in <파일명>.csr -signkey <파일명>.key -out <파일명>.crt

Signature ok
subject=/C=KR/ST=Seout/L=Seout/O=xxxx/OU=Dev./CN=www.neel.pe.kr/emailAddress=nell@pe.kr

Getting Private key



웹서버 인증서 파일 (.crt) 파일이 만들어짐


# ll
-rw-r--r--.  1 root root     1265 Jan  7 15:02 nell.crt
-rw-r--r--.  1 root root     1070 Jan  7 14:55 nell.csr
-rw-r--r--.  1 root root     1708 Jan  7 14:55 nell.key




서버가 구동될때마다 개인 키에 설정된 PassPhrase를 물어보게 되므로 자동으로 모두 처리되도록 하기 위해 PassPhrase 제거


# cp nell.key nell.key.secure

# openssl rsa -in <파일명>.key.secure -out <파일명>.key
writing RSA key





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




Nginx에 SSL 적용!



# cd /usr/local/nginx
# vi conf/nginx.conf

# HTTPS 부분에 아랫부분을 변경하여 준다.



    # HTTPS server

        server {
         listen       443;
         server_name  localhost;


         ssl     on;
         ssl_certificate /usr/local/nginx/ssl/nell.crt;                  //   crt 경로)
         ssl_certificate_key     /usr/local/nginx/ssl/nell.key;       //   key 경로


         ssl_session_timeout  5m;


         ssl_protocols SSLv2 SSLv3 TLSv1;
         ssl_ciphers              ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
         ssl_prefer_server_ciphers   on;

        location / {
            root   html;       // 홈페이지 경로
            index  index.html index.htm;
        }
    }
}







nginx에 ssl 모듈 확인






#/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.7.8
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module


"--with-http_ssl_module" 이부분이 없다면 모듈을 설치해 줘여한다.




모듈 컴파일


#cd /usr/local/src/nginx-1.7.9

# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

# make && make install



# /etc/init.d/nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


"syntax is ok"가 뜬다면 정상이라는 뜻이다.




#/etc/init.d/nginx restart


웹에서 https:// xxxxxxx 확인


인증이 되지 않는 서버라는 문구가 URL 창에 뜨고 인증보기를 누르면 좀 전에 생성한

정보가 기록되어 있다.










CentOS 6.5 - Nginx 설치



Nginx 설치


버전정보 확인 http://nginx.org/  에서 업데이트 되는 Nginx를 확인하고 다운 받을 수  있다.


설치 버전
Nginx 1.7.9



설치 전 준비 파일
#yum install -y gcc pcre-* zlib*



#cd /usr/local/src

#wget http://nginx.org/download/nginx-1.7.9.tar.gz

#tar zxvf nginx-1.7.9.tar.gz

#cd nginx-1.7.9

#yum install -y gcc pcre-* zlib*


컴파일 

#./configure --prefix=/usr/local/nginx

#make

#make install



데몬 실행파일 생성

#vi /etc/init.d/nginx

생성
-------------------------------------------------------------



#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest || return $?
    stop
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
force_reload() {
    restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac




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

#chmod +x /etc/init.d/nginx



nginx 실행


#vi /etc/sysconfig/iptables      // 80 포트 추가


추가 내용 ex) 80 포트

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


#/etc/init.d/iptables restart



#/etc/init.d/nginx start


해당 URL에  localhost 또는 서버 IP 입력  완료