/etc/fstab 작성 잘못으로 부팅이 안될때



fstab 파일을 잘 못 작성하면 디스크 마운트 실패로 부팅이 안되는 경우가 발생하지요~


/etc/fstab 작성 잘못으로 부팅이 안될때/etc/fstab 작성 잘못으로 부팅이 안될때


Give root password for maintenance

(or type Control-D to continue):


이런 메시지가 나타났을때 root 비밀번호를 입력하고 엔터를 합니다.


이제 /etc/fstab 을 수정하고 저장한 뒤에 재부팅을 하면 됩니다.


루트 파티션이 read only 로 마운트가 되어 수정이 불가능하면


# mount -o rw,remount /


명령어로 리마운트 한 다음에 /etc/fstab 파일을 수정하면 됩니다.


블로그 이미지

영은파더♥

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

,

리눅스 디스크 추가 후 마운트 하기



서버는 코노하 VPS 에서 용량은 200기가를 추가해서 테스트 하였습니다.


마운트 방법은 파티션 라벨로 하는 방법과 UUID 로 마운트 하는 방법에 대해서 알아봅니다.


[root@conoha-jp ~]# fdisk -l

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.


Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: gpt



#         Start          End    Size  Type            Name

 1         2048         6143      2M  BIOS boot parti biosboot

 2         6144     41940991     20G  EFI System      rootfs


Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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


[root@conoha-jp ~]# fdisk -l /dev/vdb


Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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


fdisk 명령어로 추가된 디스크를 확인합니다.



이번에는 fdisk 로 파티션을 잡으면 됩니다.


[root@conoha-jp ~]# fdisk /dev/vdb

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 0xbe02cf7a.


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-419430399, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):

Using default value 419430399

Partition 1 of type Linux and of size 200 GiB is set


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks.


굵은 글씨를 따라하면 됩니다. 용량은 엔터, 엔터 치시면 됩니다.


파티션을 잡았으니 이번엔 ext4 로 포맷을 합니다.


[root@conoha-jp ~]# mkfs.ext4 /dev/vdb1

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

13107200 inodes, 52428544 blocks

2621427 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2199912448

1600 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


Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done


포맷이 완료되었으면 마운트를 해야합니다.


그냥 마운트를 한다면 재부팅시에 다시 마운트를 수동으로 해야 하므로 자동으로 마운트가 되도록 /etc/fstab 을 수정하도록 합니다.


/etc/fstab 에 아래 내용을 추가하여 줍니다.


방법1 ( 파티션 라벨로 마운트 )

/dev/vdb1 /home ext4 defaults 1 1


방법2 ( 파티션 UUID로 마운트 )

[root@conoha-jp ~]# blkid /dev/vdb1

/dev/vdb1: UUID="939dd5c4-7e89-4f4a-aab6-098e3acaac30" TYPE="ext4"


UUID=939dd5c4-7e89-4f4a-aab6-098e3acaac30 /home ext4 defaults 1 1



수동으로 마운트를 하고 마운트가 잘 되었는지 확인하는 방법은 아래와 같습니다.

[root@conoha-jp ~]# mount -t ext4 /dev/vdb1 /home

[root@conoha-jp ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/vda2        20G  3.4G   16G  19% /

devtmpfs        236M     0  236M   0% /dev

tmpfs           245M     0  245M   0% /dev/shm

tmpfs           245M  8.4M  237M   4% /run

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

tmpfs            49M     0   49M   0% /run/user/0

/dev/vdb1       197G   61M  187G   1% /home

마운트가 잘 되었군요.


재부팅 후에도 자동으로 마운트가 되는지 확인을 하면 됩니다.


블로그 이미지

영은파더♥

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

,

CentOS 7.x quota 유틸로 계정별 디스크용량 할당하기



우선 quota 를 설치합니다.


# yum install quota



▶ 파티션 설정 ( vi /etc/fstab 에서 할당하고자 하는 파티션을 설정합니다. )


UUID=939dd5c4-7e89-4f4a-aab6-098e3acaac30 /home ext4 defaults,usrquota 1 1


usrquota 옵션을 추가해주면 됩니다.

유저디렉토리 /home 파티션에 설정하면 됩니다.

6.x 버전에서는 / 루트 파티션에서도 쿼타설정이 가능하였는데 7.x 버전에서는 안되는 것 같습니다.



저장한 다음에 재부팅을 하거나 수동으로 mount 를 합니다.


▶ 파티션 마운트 ( /etc/fstab 에 정의가 되었다면 mount -a 로 마운트 가능 )


[root@conoha-jp ~]# mount -t ext4 /dev/vdb1 /home

[root@conoha-jp ~]# mount | grep quota

/dev/vdb1 on /home type ext4 (rw,relatime,quota,usrquota,data=ordered)


정상적으로 마운트가 되었는지 확인합니다.


이제 /home 디렉토리를 quota 설정을 합니다.


▶ aquota.user 생성


[root@conoha-jp ~]# quotacheck -cvug /home

quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.

quotacheck: Scanning /dev/vdb1 [/home] done

quotacheck: Old group file name could not been determined. Usage will not be subtracted.

quotacheck: Checked 2 directories and 1 files

[root@conoha-jp ~]# ls -l /home

total 24

-rw------- 1 root root  6144 Dec 29 11:47 aquota.user

drwx------ 2 root root 16384 Dec 29 11:30 lost+found


aquota.user 가 생성된 것을 확인합니다.



▶ 용량 제한 시작 ( 재부팅 되더라도 적용됨 )


[root@conoha-jp ~]# quotaon /home



▶ 계정별 용량 설정 방법 ( edquota -u user1 )


Disk quotas for user user1 (uid 1000):

  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/vdb1                        16     102400     102400          4        0        0


설정단위는 KBytes 입니다.

위의 예제는 100MB 를 설정하였습니다.



▶ 계정 용량 확인 방법


[root@conoha-jp ~]# repquota -a

repquota: Cannot stat() given mountpoint user1: No such file or directory

Skipping...

repquota: No correct mountpoint specified.

repquota: Cannot initialize mountpoint scan.

[root@conoha-jp ~]# repquota -a

*** Report for user quotas on device /dev/vdb1

Block grace time: 7days; Inode grace time: 7days

                        Block limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace

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

root      --      20       0       0              2     0     0

user1     --      16  102400  102400              4     0     0



▶ 용량 설정 복사 방법


[root@conoha-jp ~]# useradd user2

[root@conoha-jp ~]# edquota -p user1 user2

[root@conoha-jp ~]# repquota -a

*** Report for user quotas on device /dev/vdb1

Block grace time: 7days; Inode grace time: 7days

                        Block limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace

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

root      --      20       0       0              2     0     0

user1     --      16  102400  102400              4     0     0

user2     --      16  102400  102400              4     0     0



용량 제한이 되는지 확인을 해보겠습니다.


[root@conoha-jp ~]# su user1

[user1@conoha-jp root]$ cd

[user1@conoha-jp ~]$ rm -rf *

[user1@conoha-jp ~]$ dd if=/dev/zero of=/home/user1/tmp1.bin bs=100M count=1

vdb1: write failed, user block limit reached.

dd: error writing ‘/home/user1/tmp1.bin’: Disk quota exceeded

1+0 records in

0+0 records out

104820736 bytes (105 MB) copied, 0.232518 s, 451 MB/s

[user1@conoha-jp ~]$ dd if=/dev/zero of=/home/user1/tmp2.bin bs=100M count=1

dd: error writing ‘/home/user1/tmp2.bin’: Disk quota exceeded

1+0 records in

0+0 records out

0 bytes (0 B) copied, 0.0481577 s, 0.0 kB/s


100MB 파일을 생성해보니 두번째 부터는 에러가 발생합니다.


용량제한이 되고 있다는 의미입니다.



▶ 용량 제한 종료 ( 재부팅되면 자동으로 quotaon 이 적용됨 )


[root@conoha-jp ~]# quotaoff /home



블로그 이미지

영은파더♥

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

,

LSYNCD 서버 파일 동기화 시키기



웹서버의 이미지나 데이터 파일을 다른 원격지 서버에 실시간 동기화를 원할 때 lsyncd 데몬을 사용하면 간단히 파일 동기화가 가능합니다.


그리고 같은 서버내 다른 디렉토리에도 백업이 가능하고 특정 폴더나 특정 파일을 제외하는 것도 가능합니다.


lsyncd.conf 설정 옵션에 대해서 알아보겠습니다.



▶ LSYNCD 설치


# yum install lsyncd lua rsync


lsyncd 와 lua 를 설치하여야 한다.

rsync 는 기본적으로 설치가 되어있겠지만 안되어 있다면 설치를 해주면 된다.



▶ 데몬 동작 설정


# systemctl enable lsyncd

# systemctl start lsyncd


6.x 버전은

# chkconfig --level 2345 lsyncd on

# service lsyncd start

아직 설정전이라 에러가 발생할겁니다.



이제 설정파일을 설정해보겠습니다.



▶ 같은 서버에 파일 동기화 설정 ( vi /etc/lsyncd.conf )


settings {

logfile="/tmp/lsyncd.log",

statusFile="/tmp/lsyncd-status.log"

}


sync {

default.rsync,

source="/var/www/html",

target="/var/www/html_backup"

}



▶ 동작 테스트


# touch /var/www/html/test.{1..5}

# ls -l /var/www/html_backup/

-rw-r--r-- 1 root root      0 12월 23 13:51 test.1

-rw-r--r-- 1 root root      0 12월 23 13:51 test.2

-rw-r--r-- 1 root root      0 12월 23 13:51 test.3

-rw-r--r-- 1 root root      0 12월 23 13:51 test.4

-rw-r--r-- 1 root root      0 12월 23 13:51 test.5


파일이 동기화가 안되어 있다면 몇 초 후에 재확인 해보세요.

그래도 파일이 동기화가 안된다면 /var/log/message 로그 파일을 확인해 보고 에러를 잡아주면 됩니다.

/etc/lsyncd.conf 파일에 설정이 잘 못 되었을 가능성이 큽니다.



이번엔 원격지 서버에 파일을 동기화 시키는 방법에 대해서 알아보겠습니다.


먼저 ssh 암호 입력 없이 접속이 가능하도록 만들어 주어야 합니다.


▶ 암호키 생성 및 복사


# ssh-keygen

# ssh-copy-id -p포트번호 root@192.168.1.3


에러가 나면 scp ./.ssh/id_rsa.pub root@192.168.1.3:~/.ssh/authorized_keys 이렇게 복사를 하면 됩니다.


원격지에 다른서버의 key값이 있다면 덥어쓰면 안되니깐 아래의 방법을 사용하여야 합니다.


cat ./.ssh/id_rsa.pub | ssh -p포트번호 root@192.168.1.3 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"


ssh-copy-id 명령어를 사용하면 덥어쓰지 않고 추가가 됩니다.



▶ 원격지 서버에 파일 동기화 설정 ( vi /etc/lsyncd.conf )


settings {

logfile="/tmp/lsyncd.log",

statusFile="/tmp/lsyncd-status.log"

}


sync {

default.rsyncssh,

source="/var/www/html",

host="192.168.1.3",

targetdir="/var/www/html"

}



▶ 로컬 및 원격지 서버에 파일 동기화 설정 ( vi /etc/lsyncd.conf )


settings {

logfile="/tmp/lsyncd.log",

statusFile="/tmp/lsyncd-status.log"

}


sync {

default.rsync,

source="/var/www/html",

target="/var/www/html_backup"

}


sync {

default.rsyncssh,

source="/var/www/html",

host="192.168.1.3",

targetdir="/var/www/html"

}


이렇게 하면 이중으로 백업이 가능합니다.



▶ 기타 설정


settings {

logfile="/tmp/lsyncd.log",

statusFile="/tmp/lsyncd-status.log"

}


sync {

default.rsyncssh,

source="/var/www/html",

host="192.168.1.3",

targetdir="/var/www/html",

delay = 1,

delete = true,

exclude = {

'/test1' ,

'/test3' ,

'*.tmp' ,

'*.swp'

},

ssh = {

port = 10022

},

rsync = {

archive = true,

compress = false,

verbose = false

}

}


delay : 동기화 작동 시점을 초단위로 조절할 수 있습니다. 디폴트는 15초 입니다.

delete :

원본에서 파일 삭제시 타겟까지 삭제하는 옵션입니다.

false 면 삭제를 하지 않습니다.

exclude :

/var/www/html/test1 폴더를 제외하려면 위에 처럼 exclude 옵션을 사용하면 됩니다.

source 폴더가 루트로 보고 적어주면 됩니다.

파일을 제외 하려면 *.swp 처럼 적어주면 됩니다.

ssh :

ssh 포트를 설정할 수 있습니다.

rsync :

archive 소유권까지 동일하게 복사가 됩니다.

compress 압축여부을 지정할 수 있습니다.

verbose 로그를 상세하게 보여주는 옵션입니다.



▶ lsyncd.log 에러


Wed Mar 15 14:05:54 2017 Normal: --- TERM signal, fading ---

Wed Mar 15 14:05:56 2017 Error: Terminating since out of inotify watches.

Consider increasing /proc/sys/fs/inotify/max_user_watches


동기화 시키려는 파일이 많은 때는 위와 같은 에러가 발생합니다.


이럴때는 max_user_watches 수를 증가시켜 주면 됩니다.


# echo 65536 > /proc/sys/fs/inotify/max_user_watches


이제 lsyncd 를 재시작 하면 됩니다.



MySQL DB 동기화는 https://ivps.tistory.com/217 여기를 참고하세요.



블로그 이미지

영은파더♥

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

,

SSH KEY 원격지서버에 복사하기



원격지 서버에 암호입력 없이 접속하기 위해서는 SSH KEY 를 생성해서 원격지 서버에 복사해 두어야 한다.


ssh-keygen 과 ssh-copy-id 명령어를 이용해보자.


[root@conoha-jp ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

3d:ec:1e:82:64:8a:6a:98:66:ce:5d:60:73:26:05:6e root@conoha-jp

The key's randomart image is:

+--[ RSA 2048]----+

|   .             |

|  . .            |

|   E .           |

|  . .    o       |

|   = oo S +      |

|  ..*+ . . .     |

|... ... . o      |

|+=. .    o .     |

|*o .      .      |

+-----------------+


옵션 생략하고 ssh-keygen 으로 하여도 된다.


생성된 키를 원격지 서버에 복사해보자.


[root@conoha-jp ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.3

The authenticity of host '192.168.1.3 (192.168.1.3)' can't be established.

ECDSA key fingerprint is 68:03:15:9f:4a:96:27:6a:d0:26:9d:91:2e:f9:e2:ea.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@192.168.1.3's password:


Number of key(s) added: 1


Now try logging into the machine, with:   "ssh 'root@192.168.1.3'"

and check to make sure that only the key(s) you wanted were added.


옵션 없이 ssh-copy-id root@192.168.1.3 으로 하여도 된다.


ssh 포트가 22번이 아니라면 -p 옵션을 사용하면 된다.


예) ssh-copy-id -p포트번호 root@192.168.1.3



192.168.1.3 서버에 복사가 되었다.


이제 부터는 암호 입력없이 접속이 가능할 것이다.


블로그 이미지

영은파더♥

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

,

쉘스크립트로 FTP 사용방법



쉘스크립트로 ftp 를 사용하는 방법입니다.


#!/bin/bash


FTP_SERVER="FTP주소"

FTP_USER="계정아이디"

FTP_PASS="계정비번"


{

echo user ${FTP_USER} ${FTP_PASS}

echo bi

echo put test.bin

echo bye

} | ftp -i -n -v ${FTP_SERVER}


ftp 주소와 아이디, 비밀번호를 작성한 다음에

그리고, echo 로 ftp 명령어를 나열해서 작성하시면 됩니다.



블로그 이미지

영은파더♥

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

,

리눅스 telnet 강제종료 방법



ftp 포트로 텔넷 접속 후에 telnet 을 종료를 하고자 할 때는 Ctrl + ] 키를 누르면 된다.


그리고는 close 입력 후 엔터~


[root@conoha-jp ~]# telnet localhost 21

Trying ::1...

telnet: connect to address ::1: Connection refused

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

220 (vsFTPd 3.0.2)


^]

telnet> close

Connection closed.



블로그 이미지

영은파더♥

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

,

하나의 계정에 여러개의 서브도메인 가상호스트 설정



하나의 계정에 서브도메인을 여러개 멀티로 아파치 가상호스트에서 경로를 유동적으로 설정하는 방법입니다.


서브도메인을 변수로 받아서 경로를 지정 할 수 가 있습니다.


aaa.example.com /home/example/www/aaa/

bbb.example.com /home/example/www/bbb/

ccc.example.com /home/example/www/ccc/



<VirtualHost *:80>

    ServerName example.com

    ServerAlias *.example.com

    DocumentRoot /home/example/www

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$

    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]

    RewriteRule ^(.+)\.example\.com(.*) /home/example/www/$1/$2 [L]

    <IfModule mod_ruid2.c>

        RMode config

        RUidGid example example

    </IfModule>

</VirtualHost>


이렇게 해놓으면 매번 서브도메인을 추가 할 때 마다 가상호스트를 작성하지 않아도 됩니다.


블로그 이미지

영은파더♥

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

,

Putty 한글 깨지는 문제 해결 방법


리눅스에서 한글 설정이 UTF-8 이라면 그냥 Putty 로 접속하면 한글이 깨져서 보일 것입니다.

locale 명령어로 리눅스의 LANG 설정값 부터 먼저 확인을 하고 진행합니다.

# locale

LANG=ko_KR.UTF-8

LC_CTYPE="ko_KR.UTF-8"

LC_NUMERIC="ko_KR.UTF-8"

LC_TIME="ko_KR.UTF-8"

LC_COLLATE="ko_KR.UTF-8"

LC_MONETARY="ko_KR.UTF-8"

LC_MESSAGES="ko_KR.UTF-8"

LC_PAPER="ko_KR.UTF-8"

LC_NAME="ko_KR.UTF-8"

LC_ADDRESS="ko_KR.UTF-8"

LC_TELEPHONE="ko_KR.UTF-8"

LC_MEASUREMENT="ko_KR.UTF-8"

LC_IDENTIFICATION="ko_KR.UTF-8"

LC_ALL=


Putty 한글 깨지는 문제 해결 방법Putty 한글 깨지는 문제 해결 방법

디폴트가 CP949 로 되어 있어서 그렇습니다.


Putty 한글 깨지는 문제 해결 방법Putty 한글 깨지는 문제 해결 방법

UTF-8 로 변경해서 세션을 저장해주면 됩니다.



블로그 이미지

영은파더♥

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

,

CentOS 7.x 시스템 백업 및 복구


현재 리눅스 시스템을 VPS 환경이 다른 시스템에 서버 이전을 하고자 할때 사용할 수 있는 방법입니다.

패키지를 다시 설치하고 환경설정하고 데이터 및 DB 백업같은 번거로움을 줄여줍니다.

CentOS 6.x 버전 및 하위 버전도 될겁니다.

VPS 를 예로 들었지만 실제 시스템도 되겠죠?


1. 기존 VPS와 신규 VPS 커널 일치

리눅스 버전이 같아야 합니다.

기존 VPS 및 신설 VPS 에서 둘 다 yum update 를 합니다.

/boot 영역을 백업하지 않기 때문에 두 VPS 에서 yum update 는 반드시 해야합니다.


2. 기존 VPS 리눅스 시스템 백업

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

--exclude={제외할 폴더들 쉼표로 구분}

ip설정이 dhcp가 아닌 static 이라면 /etc/sysconfig/network-scripts 디렉토리도 추가하여야 합니다.


3. 신설 VPS 에 백업파일 다운로드

# scp -pr root@example.com:/mnt/backup.tar.gz /mnt/

scp 로 복사를 합니다.

ssh 포트가 22번이 아니라면 -P포트번호 를 추가하면 됩니다.

root@example.com 은 기존 VPS 의 주소입니다.

자신의 환경에 맞게 수정하시면 됩니다.


4. 백업파일 풀기

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


5. 재부팅

# reboot


이제 서버 시스템이 이전되었습니다.

로그인해서 확인해보세요.

IP 는 당연히 다를테니 네임서버 변경을 하셔야 합니다.


블로그 이미지

영은파더♥

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

,