아파치 웹서버 성능검사 도구



리눅스에서 웹서버 벤치마크(스트레스) 테스트 명령어 ab 라는 툴이 있습니다. 


웹서버의 성능 및 예상하는 동시접속자 수를 버틸 수 있는지 테스트 하는데 사용되며 튜닝에 이용되기도 합니다.


ab 명령어가 없다고 나오면 아래와 같이 설치하면 됩니다.


[root@virtualbox ~]# yum install httpd-tools

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirror.navercorp.com

 * epel: mirror.premi.st

 * extras: mirror.navercorp.com

 * updates: mirror.navercorp.com

Resolving Dependencies

--> Running transaction check

---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos will be installed

--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-tools-2.4.6-40.el7.centos.x86_64

--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-tools-2.4.6-40.el7.centos.x86_64

--> Running transaction check

---> Package apr.x86_64 0:1.4.8-3.el7 will be installed

---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


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

 Package            Arch          Version                     Repository   Size

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

Installing:

 httpd-tools        x86_64        2.4.6-40.el7.centos         base         82 k

Installing for dependencies:

 apr                x86_64        1.4.8-3.el7                 base        103 k

 apr-util           x86_64        1.5.2-6.el7                 base         92 k


Transaction Summary

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

Install  1 Package (+2 Dependent packages)


Total download size: 277 k

Installed size: 584 k

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

Downloading packages:

(1/3): apr-1.4.8-3.el7.x86_64.rpm                          | 103 kB   00:00

(2/3): httpd-tools-2.4.6-40.el7.centos.x86_64.rpm          |  82 kB   00:00

(3/3): apr-util-1.5.2-6.el7.x86_64.rpm                     |  92 kB   00:20

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

Total                                               13 kB/s | 277 kB  00:20

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : apr-1.4.8-3.el7.x86_64                                       1/3

  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/3

  Installing : httpd-tools-2.4.6-40.el7.centos.x86_64                       3/3

  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  1/3

  Verifying  : httpd-tools-2.4.6-40.el7.centos.x86_64                       2/3

  Verifying  : apr-1.4.8-3.el7.x86_64                                       3/3


Installed:

  httpd-tools.x86_64 0:2.4.6-40.el7.centos


Dependency Installed:

  apr.x86_64 0:1.4.8-3.el7             apr-util.x86_64 0:1.5.2-6.el7


Complete!



테스트 방법은 아래와 같습니다.


[root@virtualbox ~]# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking conoha.ivps.kr (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Finished 500 requests



Server Software:        Apache/2.4.6

Server Hostname:        conoha.ivps.kr

Server Port:            80


Document Path:          /phpinfo.php

Document Length:        91191 bytes


Concurrency Level:      20

Time taken for tests:   10.072 seconds

Complete requests:      500

Failed requests:        55

   (Connect: 0, Receive: 0, Length: 55, Exceptions: 0)

Write errors:           0

Total transferred:      45704945 bytes

HTML transferred:       45595445 bytes

Requests per second:    49.64 [#/sec] (mean)

Time per request:       402.864 [ms] (mean)

Time per request:       20.143 [ms] (mean, across all concurrent requests)

Transfer rate:          4431.65 [Kbytes/sec] received


Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:       65   87  13.5     93     125

Processing:   207  300  88.0    296     805

Waiting:       66  107  48.5     96     304

Total:        276  387  94.9    392     905


Percentage of the requests served within a certain time (ms)

  50%    392

  66%    401

  75%    411

  80%    422

  90%    489

  95%    551

  98%    691

  99%    735

 100%    905 (longest request)



500번 요청해서 55번 실패했다는 로그입니다.



▶ 옵션설명


-c 옵션 : 동시 요청수 (아래의 -n 횟수 보다 이하의 수여야 한다.)


-n 옵션 : 요청 횟수


# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php


동시에 20명이 요청하는데 합산해서 요청 수가 500 이라는 의미 ( 20 x 25 = 500 )


-c 5 -n 100 : 5 x 20 = 100


-c 100 -n 100 : 100 x 1 = 100


-c 3 -n 100 : 3 x 33 + 1 = 100




이제 아파치 튜닝중 하나인 mod_cache 모듈을 활용해서 cache 기능을 활성화 시켜서 테스트 해보도록 하겠습니다.


▶아파치 mod_cache 기능


아파치 2.2.x 버전은 두번째 줄에 아마도 mod_disk_cache.c 로 해주어야 합니다.


아래는 2.4.x 버전용인데 차이는 mod_disk_cache 이냐 mod_cache_disk 이냐 입니다.


아래의 내용을 /etc/httpd/conf/httpd.conf 파일에 추가해주던지 아니면


/etc/httpd/conf.d/cache.conf 파일을 신규로 생성해서 저장해 주면 됩니다.


<IfModule mod_cache.c>

    <IfModule mod_cache_disk.c>

        CacheEnable disk /

        CacheRoot /var/cache/mod_cache/tmp

        CacheDirLevels 2

        CacheDirLength 1

        CacheMaxFileSize 300000

        CacheMinFileSize 1

        #CacheIgnoreCacheControl On

        CacheIgnoreNoLastMod On

        CacheIgnoreQueryString Off

        CacheIgnoreHeaders None

        CacheLastModifiedFactor 0.1

        CacheDefaultExpire 300

        CacheMaxExpire 86400

        #CacheStoreNoStore On

        #CacheStorePrivate On

    </IfModule>

</IfModule>


이제는 위에 지정한 /var/cache/mod_cache/tmp 폴더를 만들어 줍니다. 물론 apache 접근 권한이 가능한 경로라면 자동으로 만들어집니다.


[root@conoha conf.d]# cd /var/cache

[root@conoha cache]# ll

total 4

drwx------  2 root root   22 Apr  7 11:01 ldconfig

drwxr-xr-x 34 root root 4096 Apr  7 03:33 man

drwxr-xr-x  3 root root   19 Apr  7 10:36 yum

[root@conoha cache]# mkdir -m700 mod_cache

[root@conoha cache]# mkdir -m700 mod_cache/tmp

[root@conoha cache]# chown -R apache.apache mod_cache


디렉토리를 생성해 주었다면 이제는 아파치를 재시작 해주고 테스트 하면 됩니다.


아파치 재시작은 CentOS 6.x 버전은 service httpd restart

7.x 버전은 systemctl restart httpd.service


[root@virtualbox ~]# ab -c 20 -n 500 http://conoha.ivps.kr/phpinfo.php

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking conoha.ivps.kr (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Finished 500 requests



Server Software:        Apache/2.4.6

Server Hostname:        conoha.ivps.kr

Server Port:            80


Document Path:          /phpinfo.php

Document Length:        91191 bytes


Concurrency Level:      20

Time taken for tests:   17.398 seconds

Complete requests:      500

Failed requests:        2

   (Connect: 0, Receive: 0, Length: 2, Exceptions: 0)

Write errors:           0

Total transferred:      45720566 bytes

HTML transferred:       45595498 bytes

Requests per second:    28.74 [#/sec] (mean)

Time per request:       695.910 [ms] (mean)

Time per request:       34.795 [ms] (mean, across all concurrent requests)

Transfer rate:          2566.37 [Kbytes/sec] received


Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:       64   86  66.6     77    1135

Processing:   405  589 253.8    564    2083

Waiting:       63  156 232.0     92    1496

Total:        472  675 266.6    658    2182


Percentage of the requests served within a certain time (ms)

  50%    658

  66%    669

  75%    677

  80%    690

  90%    921

  95%   1334

  98%   1658

  99%   1770

 100%   2182 (longest request)


Failed requests 가 눈에 띄게 줄어들었습니다.


테스트 서버가 ConoHa VPS 서버인데다 램(1GB) 등 하드웨어 사양이 좀 딸려서 좀 더 심한 테스트를 하지 못한 점은 양해바랍니다.





블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x firewalld 대신에 iptables 로 대체



아무리 봐도 firewalld 는 생소해서 도무지 적응이 안된다.


firewalld 를 내리고 iptables 를 설치해보자.



[root@conoha ~]# systemctl stop firewalld

[root@conoha ~]# systemctl disable firewalld

Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@conoha ~]# yum install iptables-services

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: ftp.iij.ad.jp

 * epel: ftp.riken.jp

 * extras: ftp.iij.ad.jp

 * updates: ftp.iij.ad.jp

Resolving Dependencies

--> Running transaction check

---> Package iptables-services.x86_64 0:1.4.21-16.el7 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


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

 Package                  Arch          Version               Repository   Size

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

Installing:

 iptables-services        x86_64        1.4.21-16.el7         base         50 k


Transaction Summary

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

Install  1 Package


Total download size: 50 k

Installed size: 24 k

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

Downloading packages:

iptables-services-1.4.21-16.el7.x86_64.rpm                 |  50 kB   00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : iptables-services-1.4.21-16.el7.x86_64                       1/1

  Verifying  : iptables-services-1.4.21-16.el7.x86_64                       1/1


Installed:

  iptables-services.x86_64 0:1.4.21-16.el7


Complete!

[root@conoha ~]# systemctl enable iptables

Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.

[root@conoha ~]# systemctl start iptables

[root@conoha ~]# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination

ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED

ACCEPT     icmp --  anywhere             anywhere

ACCEPT     all  --  anywhere             anywhere

ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh

REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited


Chain FORWARD (policy ACCEPT)

target     prot opt source               destination

REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited


Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination

[root@conoha ~]#


폰트 굵은 부분만 보면 된다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x 네트워크장치명 enp0s3 를 eth0 로 변경하는 방법



ifconfig 명령어를 실행해보면 아래화면 처럼 익숙하지 않은 장치명이 보인다.


[root@virtualbox ~]# ifconfig

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.250  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::a00:27ff:fe27:d6ca  prefixlen 64  scopeid 0x20<link>

        ether 08:00:27:27:d6:ca  txqueuelen 1000  (Ethernet)

        RX packets 251  bytes 22168 (21.6 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 147  bytes 23767 (23.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


CentOS 6.x 버전에서는 eth0 로 나왔었는데 말이다.


enp0s3 를 eth0로 바꿔주자.


# mv /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0


우선 장치 파일명 부터 바꾼 다음에


# vi /etc/sysconfig/network-scripts/ifcfg-eth0


TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=no

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

NAME=eth0

UUID=57e2e929-c87c-4607-90cb-8f87037a9d16

DEVICE=eth0

ONBOOT=yes

DNS1=168.126.63.1

IPADDR=192.168.1.250

PREFIX=24

GATEWAY=192.168.1.1


안에 내용을 변경해주자. NAME= 부분과 DEVICE= 부분을 enp0s3 에서 eth0 로 변경하고 저장하면 된다.


다음에는


# vi /etc/default/grub


GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT="console"

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos_virtualbox/root rd.lvm.lv=centos_virtualbox/swap rhgb quiet net.ifnames=0 biosdevname=0"

GRUB_DISABLE_RECOVERY="true"


/etc/default/grub 파일을 열어서 굵은 글씨로 되어 있는 "net.ifnames=0 biosdevname=0" 를 추가하고 저장하자.


그리고 grub2-mkconfig 명령어로 grub.cfg 를 생성해주어야 한다.


# grub2-mkconfig -o /boot/grub2/grub.cfg

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-3.10.0-327.13.1.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-327.13.1.el7.x86_64.img

Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img

Found linux image: /boot/vmlinuz-0-rescue-cc29964e94c24c63899315ba5cff468c

Found initrd image: /boot/initramfs-0-rescue-cc29964e94c24c63899315ba5cff468c.img

done


이제 재부팅하면 된다.


# reboot


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x ifconfig command not found 해결 방법



CentOS 7.2 minimal 최소 설치를 했더니 이렇게 나온다.


[root@virtualbox ~]# ifconfig

-bash: ifconfig: command not found

[root@virtualbox ~]# netstat

-bash: netstat: command not found

[root@virtualbox ~]#


이런거 까지 바뀌다니 너무한거 같다.


아래와 같이 yum 으로 net-tools 를 설치해주자.

[root@virtualbox ~]# yum install net-tools

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirror.navercorp.com

 * extras: mirror.navercorp.com

 * updates: mirror.navercorp.com

Resolving Dependencies

--> Running transaction check

---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


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

 Package         Arch         Version                          Repository  Size

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

Installing:

 net-tools       x86_64       2.0-0.17.20131004git.el7         base       304 k


Transaction Summary

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

Install  1 Package


Total download size: 304 k

Installed size: 917 k

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

Downloading packages:

net-tools-2.0-0.17.20131004git.el7.x86_64.rpm              | 304 kB   00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : net-tools-2.0-0.17.20131004git.el7.x86_64                    1/1

  Verifying  : net-tools-2.0-0.17.20131004git.el7.x86_64                    1/1


Installed:

  net-tools.x86_64 0:2.0-0.17.20131004git.el7


Complete!

[root@virtualbox ~]#


# yum install -y net-tools 로 설치해도 된다.


한번 물어보고 설치할거냐 바로 설치하느냐의 차이다.


[root@virtualbox ~]# ifconfig

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::a00:27ff:fe27:d6ca  prefixlen 64  scopeid 0x20<link>

        ether 08:00:27:27:d6:ca  txqueuelen 1000  (Ethernet)

        RX packets 75998  bytes 113700300 (108.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 17889  bytes 1229230 (1.1 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 8  bytes 560 (560.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 8  bytes 560 (560.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


이제 잘 된다.




블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 mysql root 비밀번호 변경 및 분실시 초기화

 

 

mysqladmin 을 이용한 mysql 비밀번호 변경 방법이다.

 

# mysqladmin -u root -p password

Enter password:

New password:

Confirm new password:

순서대로 기존암호, 변경암호, 확인암호

 

 

 


 

 

이번엔 분실시 초기화에 대해서 알아보자.

CentOS 7.x 버전에는 mariadb 이다. 그래서 6.x 버전과는 좀 다르다.

 

# systemctl stop mariadb.service

먼저 위의 명령어로 mariadb 서비스를 종료하자.

 

다음엔 아래의 굵은 글씨를 참고해서 변경해주면 된다.

[root@conoha ~]# mysqld_safe --skip-grant-tables --skip-networking &

[1] 14248

[root@conoha ~]# 160406 13:43:10 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

160406 13:43:10 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

 

[root@conoha ~]# mysql -u root

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 1

Server version: 5.5.44-MariaDB MariaDB Server

 

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

MariaDB [mysql]> update user set password=PASSWORD('1234') where User='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

 

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [mysql]> quit

Bye

[root@conoha ~]#

 

 

여기까지 완료했다면 mysql 재시작

# systemctl start mariadb.service

 

이제 사용하면 된다.

 

블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x phpmyadmin 설치하기



phpMyAdmin 이 설치되어 있으면 사용하기가 정말 편하다.


sql 클라이언트 프로그램 없이도 브라우저에서 바로 쿼리문을 사용할 수 있기 때문이다.


그리고 "최근 1440초 동안 아무 동작이 없어 로그아웃 되었습니다. 다시 로그인해주세요." 메시지 안나오게 설정하는 방법에 대해서 알아보자.


▶ phpmyadmin 설치


# yum install -y phpmyadmin



▶ 아파치 재시작


# systemctl restart httpd.service

6.x 버전은 service httpd restart



이제 접속을 시도해 보자.

phpmyadmin 접속 url 은 http://도메인주소/phpmyadmin 이다.


Forbidden

You don't have permission to access /phpMyAdmin on this server.

접속 거부 메시지가 나타난다.



▶ 접근허용 IP 추가 ( /etc/httpd/conf.d/phpMyAdmin.conf 파일에서 자신의 IP 추가)


Require ip 127.0.01 접근허용IP

Require ip 127.0.0.1 을 찾아서 뒤에다 공백을 붙이고 허용IP를 적어주고 저장

그리고 아파치 재시작



다시 로그인 시도

CentOS 7.2 phpMyAdmin 로그인화면CentOS 7.2 phpMyAdmin 로그인화면

이제 접속이 잘 된다.


로그인 주소가 너무나 잘 알려져 있어서 그리고 보안을 위해 Alias 를 수정해주자.


vi /etc/httpd/conf.d/phpMyAdmin.conf

Alias /__MyAdmin /usr/share/phpMyAdmin

#Alias /phpmyadmin /usr/share/phpMyAdmin


자신이 원하는 Alias를 적고 저장한 다음에 아파치 재시작


이제 접속 URL 이 바뀌었다.



phpMyAdmin 1440초 자동 로그아웃최근 1440초 동안 아무 동작이 없어 로그아웃 되었습니다. 다시 로그인해주세요.


그리고 접속한지 아무입력 없이 1440초 (24분) 가 지나면 위와 같이 자동 로그아웃이 된다.


/etc/phpMyAdmin/config.inc.php 파일에서 아래부분을 찾아서 cookie 를 http 로 바꿔주자.


$cfg['Servers'][$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?

$cfg['Servers'][$i]['user']          = '';          // MySQL user

$cfg['Servers'][$i]['password']      = '';          // MySQL password (only needed


인증 방식을 cookie 에서 http 로 바꾸면 처음 접속시 바로 로그인을 요구한다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 시스템 백업 및 복구하기



이번에는 리눅스 시스템을 tar 압축으로 백업 및 증분백업하는 방법에 대해서 알아보자.


백업 파일은 로컬에 저장할 수도 있지만 nfs 또는 webdav로 마운트하여 다른 서버에 저장할 수도 있다.


시스템의 용량이 크다면 로컬에 백업했다가 다른 서버로 업로드하는 방식을 권장한다.




▶ 압축 백업하기 (원격 NAS 가 /mnt/nas 에 마운트가 되었다는 전제 조건)


# tar cvpzf /mnt/nas/backup.tar.gz --exclude=/mnt --exclude=/media --exclude=/proc --exclude=/sys --exclude=/var/cache --exclude=/lost+found /


제외 폴더를 아래 처럼 나열하여도 된다.


# tar cvpzf /mnt/nas/backup.tar.gz --exclude={/mnt,/media,/proc,/sys,/var/cache,/lost+found} /


gzip 압축 : tar cvpzf backup.tar.gz

bzip2 압축 : tar cvpjf backup.tar.bz2

xz 압축 : tar cvpJf backup.tar.xz


실제로 /mnt 에 압축 백업을 해보았다. bzip2, gzip, xz 순이다.

# ls -l /mnt

-rw-r--r-- 1 root root 614800905 Apr  6 11:12 backup.tar.bz2

-rw-r--r-- 1 root root 670125342 Apr  6 11:08 backup.tar.gz

-rw-r--r-- 1 root root 475330744 Apr  6 11:27 backup.tar.xz


bzip2 와 xz 는 압축율은 높지만 속도가 그만큼 느리다.


백업시에 네트워크로 바로 백업할 수도 있지만 네트워크 속도를 감안하여 /mnt 로컬에 저장한 후에 업로드하는 방법을 사용하여도 된다.


/mnt 외에 로컬에 저장하려고 한다면 백업파일명도 --exclude= 에 포함시켜야 한다.





▶ 복구하기


# tar xvpzf /mnt/nas/backup.tar.gz -C /


# tar xvpjf /mnt/nas/backup.tar.bz2 -C /


# tar xvpJf /mnt/nas/backup.tar.xz -C /


압축방식에 따라 압축해제 옵션도 다르다. z, j, J





이번에는 증분백업하는 방법이다.


▶ 증분 백업하기


# tar -g backup.list -cvpzf /mnt/backup_20160401.tar.gz --exclude=/mnt --exclude=/media --exclude=/proc --exclude=/sys --exclude=/var/cache --exclude=/lost+found /


# tar -g backup.list -cvpzf /mnt/backup_20160402.tar.gz --exclude=/mnt --exclude=/media --exclude=/proc --exclude=/sys --exclude=/var/cache --exclude=/lost+found /


# tar -g backup.list -cvpzf /mnt/backup_20160403.tar.gz --exclude=/mnt --exclude=/media --exclude=/proc --exclude=/sys --exclude=/var/cache --exclude=/lost+found /


복구는 맨처음 압축한 백업파일 부터 순서대로 하나씩 풀어주면 된다.


만약에 1주일이나 한달 단위로 증분백업을 하고자 한다면 시작하려는 일자에 backup.list 파일을 지워주면 된다.





리눅스 디스크 전체 백업에 대해서 알아보기 ☞ https://ivps.tistory.com/3



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 백업 방법에는 tar로 압축백업하는 방법도 있고 디스크를 통째로 복사하는 방법, 데이터베이스 및 웹페이지 데이터만 백업 등 여러가지가 있다.


그 중에 디스크 전체를 백업하는 방식인 dd 명령어로 백업 및 복원하는 방법에 대해서 알아보자.


대부분의 가상서버호스팅은 여유의 하드가 따로 없는데 없다면 Backup storage 를 활용하거나

NAS 시스템의 webdav 를 마운트하여 백업을 할 수 있다.


리눅스 디스크 백업은 파티션 테이블과 파티션 파일을 따로 백업할 수도 있고 통째로 할 수도 있다.


우선 서버에서 어떤 파티션을 백업해야 하는지 알아야된다.




▶ 백업 파티션 확인하기

# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   48G  1.6G   46G   4% /

devtmpfs                 487M     0  487M   0% /dev

tmpfs                    497M     0  497M   0% /dev/shm

tmpfs                    497M   13M  484M   3% /run

tmpfs                    497M     0  497M   0% /sys/fs/cgroup

/dev/vda1                497M  218M  279M  44% /boot

tmpfs                    100M     0  100M   0% /run/user/0


# fdisk -l

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048     1026047      512000   83  Linux

/dev/vda2         1026048   104857599    51915776   8e  Linux LVM


백업해야될 파티션이 /dev/vda1 과 /dev/vda2 임을 알 수가 있다.





▶ 디스크 통째로 백업하기

# dd if=/dev/vda of=/dev/vdb bs=512K

/dev/vdb 가 있는 경우다.

nas 활용시 : dd if=/dev/vda of=/mnt/nas/vda.bin bs=512K




▶ 디스크 통째로 복구하기

# dd if=/dev/vdb of=/dev/vda bs=512K

백업할 때의 if 와 of 인자 위치만 바뀌었다.

nas 활용시 : dd if=/mnt/nas/vda.bin of=/dev/vda bs=512K





▶ 파티션 테이블(MBR) 백업

# dd if=/dev/vda of=/mnt/nas/vda.mbr bs=512 count=1

dd 명령어로 MBR을 백업하는 방법이다.

sfdisk 명령으로는 : sfdisk -d /dev/vda > /mnt/nas/vda.mbr


▶ 파티션 파일 백업

# dd if=/dev/vda1 of=/mnt/nas/vda1.bin bs=1K

# dd if=/dev/vda2 of=/mnt/nas/vda2.bin bs=1K


# dd if=/dev/vda1 bs=512K | gzip -c > /mnt/nas/vda1.bin.gz

# dd if=/dev/vda2 bs=512K | gzip -c > /mnt/nas/vda2.bin.gz

위쪽은 압축 안하고 그대로 복사하는 방법이고 아랫쪽은 압축하여 백업하는 방법이다.




▶ 파티션 테이블(MBR) 복구

# dd if=/mnt/nas/vda.mbr of=/dev/vda bs=512 count=1

sfdisk 명령으로는 : sfdisk /dev/vda < /mnt/nas/vda.mbr


▶ 파티션 파일 복구

# dd if=/mnt/nas/vda1.bin of=/dev/vda1 bs=512K

# dd if=/mnt/nas/vda2.bin of=/dev/vda2 bs=512K


# gzip -cd /mnt/nas/vda1.bin.gz | dd of=/dev/vda1 bs=512K

# gzip -cd /mnt/nas/vda2.bin.gz | dd of=/dev/vda2 bs=512K

위쪽은 그대로 복사하여 복구하는 방법이고 아랫쪽은 압축된 백업본을 압축해제 하고 복구하는 방법이다.




위의 방법 중 편한 방법을 활용하면 된다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,