2011년 12월 26일 월요일

Linux 파일시스템 복구

하드디스크 복구

일단, 싱글모드로 부팅하신후에..
e2fsck /dev/hda1
사용법은 위와 같습니다. 복구하고자 하는 파티션을 적어주면 되죠..
주의할점은, 싱글모드로 부팅해서 언마운트가 된 상황에서 복구해줘야 합니다..

싱글모드로의 부팅은 처음 부팅시
boot : linux 1
리눅스 파일시스템 점검및 복구를 할 수 있는 명령어입니다.
리눅스 시스템이 부팅되는 과정에서 /etc/rc.d/rc.sysinit 스크립트가 자동
으로 실행이 됩니다.
/etc/rc.d/rc.sysinit 스크립트를 확인해 보시면 파일시스템을 점검하는 명
령어가 실행되는 단계가 있습니다. 따라서 시스템부팅시마다 파일시스템
점검명령어가 실행됩니다.
e2fsck 의 종료코드
0 - 에러없이 정상적인 종료를 의미함.
1 - 파일시스템을 복구하였음을 의미함.
2 - 파일시스템이 복구되어 시스템이 재부팅되어야함을 의미함.
4 - 작업대상 파일시스템에 문제가 있으나 복구하지않고 그대로 두었
음을 의미함.
8 - 실행에러를 의미함.
16 - 사용법(Usage)또는 문법(Syntax)에러를 의미함.
32 - e2fsck 작업이 사용자에 의해서 취소(Cancel)되었음을 의미함.
128 - 공유 라이브러리(Shared library) 에러를 의미함.
[주의사항]e2fsck 명령어로 파일시스템을 점검하고 복구할 때에는 대상 파일시스템이 마운트되어있지않은 상태에서 실행하시기 바랍니다. 만약 마운트되어있는 상태에서 이 명령어를 사용하신다면 원하지않은 오류를 발생할 수도 있습니다.
마운트된 파일시스템을 e2fsck 로 점검 할때는 "WARNING!!!" 메세지가 나온다~
사용하기전에 파일시스템 정보부터 확인한다.
-----------------------------------------------------------------------------------
[root@dg69 /]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 4957220 2726600 1978804 58% /
/dev/sdb1 17654736 2672588 14085324 16% /backup
/dev/sda1 101086 17979 77888 19% /boot
none 517292 0 517292 0% /dev/shm
/dev/sda5 11084636 178904 10342656 2% /home
------------------------------------------------------------------------------------
[root@dg69 /]# mount/dev/sda2 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sdb1 on /backup type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda5 on /home type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/proc on /var/named/chroot/proc type none (rw,bind)
------------------------------------------------------------------------------------
[root@dg69 /]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2233.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 18.3 GB, 18373206016 bytes
255 heads, 63 sectors/track, 2233 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 2233 17936541 83 Linux
Command (m for help): q
------------------------------------------------------------------------------------
[root@dg69 /]# fdisk /dev/sda
The number of cylinders for this disk is set to 2233.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 18.3 GB, 18373206016 bytes
255 heads, 63 sectors/track, 2233 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 640 5036377+ 83 Linux
/dev/sda3 641 831 1534207+ 82 Linux swap
/dev/sda4 832 2233 11261565 5 Extended
/dev/sda5 832 2233 11261533+ 83 Linux
Command (m for help): q
[root@dg69 /]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
LABEL=/backup1 /backup ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
LABEL=/home1 /home ext3 defaults 1 2
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/hda /media/cdrom auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
[root@dg69 /]#
------------------------------------------------------------------------------------
e2fsck 사용법
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck /dev/sdb1 <-----일반적인 특정시스템 점검복구e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/backup1: clean, 62/2244608 files, 738598/4484135 blocks
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -f /dev/sdb1 <-----강제적인 특정시스템 점검복구
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/backup1: 62/2244608 files (16.1% non-contiguous), 738598/4484135 blocks
------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -j ext3 /dev/sdb1 <-----ext3(저널링)파일시스템 점검복구
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/backup1: clean, 62/2244608 files, 738598/4484135 blocks
--------------------------------------------------------------------------------------
[root@dg69 /]# e2fsck -fv /dev/sdb1 <-----강제적인 특정시스템 점검복구및 상세정보출력
e2fsck 1.35 (28-Feb-2004)
/dev/sdb1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
62 inodes used (0%)
10 non-contiguous inodes (16.1%)
# of inodes with ind/dind/tind blocks: 27/17/0
738598 blocks used (16%)
0 bad blocks
1 large file
43 regular files
10 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
53 files
-----------------------------------------------------------------------------------------
*점검 복구 자동 : e2fsck -p /dev/sdb1
*점검,복구시 묻는질문에 무조건 yes : e2fsck -y /dev/sdb1
*점검,복구시 묻는질문에 무조건 no : e2fsck -n /dev/sdb1
*버퍼캐쉬의 내용을 디스크에 저장하기 : e2fsck -F /dev/sdb1
파일시스템의 수퍼블록을 이용한 파일시스템 복구방법
리눅스의 파일시스템은 블록그룹(Block Group)이라는 것으로 기본구조를 이
루고 있으며 모든 블록그룹의 맨 앞에는 수퍼블록이라는 것이 존재합니
다. 블록그룹에 존재하는 모든 수퍼블록들은 동일한 정보를 가지고 있으
며 파일시스템이 파괴되었을 경우에 이 정보를 이용하여 복구를 할 수 있도
록 준비하고 있습니다.
- 첫번째 수퍼블록 : 1 번블록에 위치함.
- 두번째 수퍼블록 : 1 번블록 + 8192 번블록*1 = 8193 번째 블록에 위치함.
- 세번째 수퍼블록 : 1 번블록 + 8192 번블록*2 = 16385 번째 블록에 위치함.
- n 번째 수퍼블록 : 1 번블록 + 8192 번블록*n 번째블록에 위치함.
ex) 첫번째 수퍼블록이 깨졌기 때문에 일반적인 방법으로 복구가 불가능하게 된 경우로서 두번째 수퍼블록으로 복구를 하는 예
----------------------------------------------------------------------------------------
[root@file root]# e2fsck -b 8193 /dev/sda1
e2fsck 1.32 (09-Nov-2002)
/dev/sda1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.
Do you really want to continue (y/n)? yes
/boot was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/boot: ***** FILE SYSTEM WAS MODIFIED *****
-------------------------------------------------------------------------------------------
세번째 수퍼블록을 이용한 복구작업 : # e2fsck -b 16385 /dev/sda1
네번째 수퍼블록을 이용한 복구작업 : # e2fsck -b 24577 /dev/sda1 으로 하시던지, 부팅후에 init 1 으로 레벨을 변경하실수가 있습니다..

2011년 12월 25일 일요일

FTP 226 Transfer done (but failed to open directory). 오류해결방법 ...‎

Fedora Core9에 vsftp를 설치하여 사용하다 보면 외부에서 FTP 접속할 경우
아래  표와 같이 디렉토리 목록만 나오고 파일목록이 안나오는 경우가 있다.

230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).


이럴 경우 "root" 권한으로

SELinux 정책을 일시적으로 끄고 싶을때 (재부팅하면 SELinux의 정책은 원래대로 돌아온다.)
# setenforce 0
다시 켜고 싶을땐
# setenforce 1

영구적으로 SELinux정책을 끄고 싶을때는 아래와 같이 해주면 된다.(이것도 역시 root 권한으로...)
#vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

위와 같이 "SELINUX="의 값을 "enforcing"에서 "disabled"로 수정 후 저장하면 재부팅 후에도... 쭈욱~ 

출처 : http://mrtroll.tistory.com/entry/%ED%8E%98%EB%8F%84%EB%9D%BC%EC%BD%94%EC%96%B4%EC%97%90%EC%84%9C-SELINUX-%EA%B4%80%EB%A0%A8-%EC%84%A4%EC%A0%95FTP%EA%B4%80%EB%A0%A8

페도라코어에서 SELINUX 관련 설정(FTP관련)

*** SELINUX
# setsebool -P ftp_home_dir 1
페도라 코어 4 까실때 SELinux 로 설정했다면 디폴트로 사용자의 home 디렉토리에 쓰기를 막아놓는다.
SELinux 설정에서 FTP 부분을 변경하자.
# service vsftpd restart
home 디렉토리의 읽고쓰기를 1(True)로 변경하시고 vsftpd 를 재시작.

# setsebool -P ftpd_disable_trans 1
FTP 에 관하여 SELinux 정책을 아예 적용하지 않는 옵션을 설정


- 근데 왜 내꺼에선 setsebool -P ftp_home_dir 1 명령어 입력후 먹통일까... -ㅅ-

selinux disable

1. 수동으로 끄기 (일시적으로만 먹힘)
system-config-securitylevel
setenforce 0

2. 커널 명령행에 다음 옵션 추가. (grub.conf 등에)
selinux=0

3. /etc/selinux/config 파일 수정 ***추천***
SELINUX=어쩌구~ 써있는 것을 SELINUX=disabled로 수정

 

2011년 12월 21일 수요일

제로보드XE upload 2MB 제한

문제: XE에서 upload 2MB 제한되어 있으며, 관리자메뉴에서 설정을 바꿔도 변경되지 않는다.
          이는 apache의 php.ini 파일의 설정때문이다.

해결:/usr/local/apache/conf/php.ini 파일의 upload_max_filesize와 post_max_size를 수정후
        apache를 재실행 하면 된다.
        XE 관리페이지에서는 별다른 설정이 필요없다.

2011년 12월 19일 월요일

mysql시작하기

- MySQL 활성화
echo 'mysql_enable="YES"' >> /etc/rc.conf
- MySQL 설정
cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf

UTF-8로 설정
# vi /etc/my.cnf
--------------------------------------------------------------------------------
[client]
default-character-set=utf8

[mysqld]
character-set-client-handshake=FALSE
init_connect="SET collation_connection=utf8_general_ci"
init_connect="SET NAMES utf8"
#default-character-set=utf8 => MySQL 5.0이면 이 부분 추가
character-set-server=utf8
collation-server=utf8_general_ci

[mysqldump]
default-character-set=utf8

[mysql]
default-character-set=utf8
-----------------------------------------------------


- MySQL 시작
/usr/local/etc/rc.d/mysql-server start

- MySQL 루트 패스워드 지정
mysql> set password for 'root'@'localhost' = password('비밀번호');
mysql> grant all on *.* to root@localhost identified by '비밀번호';
mysql> UPDATE mysql.user SET Password = PASSWORD('비밀번호') WHERE User = 'root';
mysql> flush privileges;

- MySQL 루트 패스워드 지정 방법 2
/usr/local/bin/mysqladmin -u root password 비밀번호

- 외부 접속 가능
mysql> grant all privileges on *.* to root@"%" identified by '비밀번호' with grant option;

- 외부 접속 가능 방법 2
mysql -h localhost -u root -p
mysql> grant all privileges on *.* to 'root'@'%' identified by '비밀번호';
mysql> grant reload,process on *.* to root@localhost;
FLUSH PRIVILEGES;

XE설치시 퍼미션불가능 이라는 에러발생.

문제: XE설치시 약관동의후 다음페이지에서 퍼미션 불가능 이라고 뜰때.
해결:htdocs 디렉토리 혹은 XE설치디렉토리의 퍼미션확인
        755 --> 707

XE설치 화면이 표시되지 않을때.

문제: APM설치후 httpd 실행후 웹서버에 접속하면
        http://xxx.xxxx.xxx.xxx/ ---> 파일내용만 보임.
        http://xxx.xxxx.xxx.xxx/index.php --> XE첫화면만 보이며 약관동의후 다음페이지로 넘어가면
        페이지가 표시되지 않음.

 해결:/usr/local/apache/conf/httpd.conf파일 수정
        DirectoryIndex --> index.php추가해줌.

2011년 12월 14일 수요일

아파치 403에러 Permission Denied access to / denied 초치법

아파치 설정후 기본 index.html화면은 뜨는데 사용자 원하는 화면이 안뜰때.
1.httpd log확인(/var/log/httpd/error.log)
2.Permission Denied access to / denied  메시지가 있다면 아래와 같이 조치한다.
3.# chcon -R -h -t httpd_sys_content_t /home/www

/home/www는 원하는 폴더를 지정하면 된다.

2011년 12월 7일 수요일

windows에서 samba에 다른 계정으로 로그인 하기.

상식적으로 생각해 볼 때 당연히 쉽게 되어야 할 것 같지만, 공유폴더에 어떤 계정으로 자동로그인을 걸어 버리면 그걸 풀기가 정말정말정말 힘듭니다. 아니 대체 어떻게 하면 풀 수 있는지 알 수가 없더군요. 연구실에서 제가 관리하는 머신에 삼바를 깔았는데, 다른 사람 계정으로 자동로그인해 버렸더니 제 계정으로 접근할 수가 없어서 몇 달 정도 사용을 못하고 묵혀 두고 있었답니다.

오늘 마음먹고 찾아봤더니.. 가능하더군요. net use 명령을 쓰면 됩니다 ;


C:\>net use
새 연결 정보가 저장됩니다.

상태 로컬 원격 네트워크
-------------------------------------------------------------------------------
OK Z: \\192.168.0.40\sjlee Microsoft Windows Network
OK \\147.46.11x.13x\IPC$ Microsoft Windows Network
OK \\147.46.12x.12x\IPC$ Microsoft Windows Network
명령을 잘 실행했습니다.


현재 연결된 공유폴더 목록을 볼 수 있습니다. 여기서, 로그인 계정을 변경하고자 하는 머신으로의 모든 연결을 수동으로 끊어 줘야 합니다.


C:\>net use \\147.46.12x.12x\IPC$ /delete
\\147.46.12x.12x\IPC$이(가) 제거되었습니다.


이제 다시 목록을 확인해 봅시다.


C:\>net use
새 연결 정보가 저장됩니다.

상태 로컬 원격 네트워크
-------------------------------------------------------------------------------
OK Z: \\192.168.0.40\sjlee Microsoft Windows Network
OK \\147.46.114.135\IPC$ Microsoft Windows Network
명령을 잘 실행했습니다.


확실히 끊어졌지요. 이제 다시 연결해 봅시다.


C:\>net use \\147.46.12x.12x * /user:sjlee
\\147.46.12x.12x에 대한 암호를 입력하십시오:
명령을 잘 실행했습니다.

C:\>net use
새 연결 정보가 저장됩니다.

상태 로컬 원격 네트워크
-------------------------------------------------------------------------------
OK Z: \\192.168.0.40\sjlee Microsoft Windows Network
OK \\147.46.11x.13x\IPC$ Microsoft Windows Network
OK \\147.46.12x.12x\IPC$ Microsoft Windows Network
명령을 잘 실행했습니다.

C:\>
 
 
 
=========================================================================================================================
=========================================================================================================================


http://www.cyworld.com/moonriver_13/3781673

처음 PC 전원 킨 후 네트워크 공유 폴더에 암호가 걸려있을 경우 '사용자 이름'과 '암호'를 넣게 되어 있다.
한번 로그인 되면 다시 부팅 되기 전까진 자동으로 들어가게 되어 있다.

여기서 문제는 공유폴더가 여러개이며 각각의 공유폴더마다 다른 계정으로 로그인 하게 되어 있다면
해결은 재부팅이었다.(몰랐기 때문에 ㅠㅠ)

[재부팅 없이 로그인된 계정을 로그오프 한후 다른 계정으로 로그인하는 방법]
1. 연결정보 확인하기 (예시문)
 ※net use 명령어 사용하기 - 명령어를 사용하기 위해서는 도스창을 띄워야 함
    (도스창을 열기위해서는 시작-실행-열기란에 'cmd')

================검정색의 도스창===시작================================================
C:\>net use새 연결 정보가 저장됩니다.

상태          로컬          원격                               네트워크
-------------------------------------------------------------------------------
OK                           \\147.46.11x.13x\IPC$   Microsoft Windows Network
OK                           \\147.46.12x.12x\IPC$   Microsoft Windows Network
명령을 잘 실행했습니다.
================검정색의 도스창===끝==================================================코멘트: 현재 연결된 공유폴더 2개 목록을 볼 수 있습니다. (주의:예시이므로 각 사용자는 다를 수 있음)

2.수동으로 연결끊기
================검정색의 도스창===시작================================================C:\>net use \\147.46.12x.12x\IPC$ /delete
\\147.46.12x.12x\IPC$이(가) 제거되었습니다.
================검정색의 도스창===끝==================================================

코멘트: 로그인 계정을 변경하고자 하는 머신으로의 모든 연결을 수동으로 끊어 줘야 함.

3. 연결정보 재확인
================검정색의 도스창===시작================================================
C:\>net use
새 연결 정보가 저장됩니다.

상태          로컬          원격                               네트워크
-------------------------------------------------------------------------------
OK                           \\147.46.11x.13x\IPC$   Microsoft Windows Network
명령을 잘 실행했습니다.
================검정색의 도스창===끝==================================================

RHEL_AS4 samba servre setting.

1.samba pkg확인.
rpm -qa |grep samba

2.samba pkg install.
rpm -ivh |grep sambaxxx.rpm

3.samba service 등록.
  ntsysv

4.samba user 생성 및 pw변경.
  smbpasswd -a "smbuser"
  smbpasswd smbuser
 *.samba password생성을 위해서는 해당유저가 linux system에 생성되어 있어야함.
5.설정파일/etc/samba/smb.conf 수정.

5.smb service start
  service smb start


RHEL_AS4 vnc server setting.

1.vnc pkg설치확인
   rpm -qa |grep vnc
2.vnc pkg설치.
  rpm -ivh xxxx.rpm
3.vnc service 설정.
  ntsysv

우선 여기까지 설정후 테스트 해보고 안되면 아래 절차대로 진행.
****STEP1. On the system you want to control with VNC, run the program vncpasswd as root to set a VNC password. You will use this password when connecting with vncviewer or another VNC remote control program.

****STEP2. Edit the file /etc/X11/xorg.conf on RHEL 5

[A] Create the section called Module in the end of the file and add following lines:
Section "Module"
Load "glx"
Load "dbe"
Load "extmod"
Load "freetype"
Load "type1"
Load "dri"
Load "vnc"
EndSection
Make sure this is on a new line before EndSection.

[B] In section called Screen, add this line:
Option "passwordFile" "/root/.vnc/passwd"

Make sure this is on a new line before EndSection.


****STEP3 – Allow the ports in Firewall

1. SSH to the server and Run the following tool:
2. # system-config-securitylevel
3. In the "Other ports", please add a range as in below example. Note that those will be TCP ports as below:

5900-5904:tcp

4. Save and close the tool then restart firewall:
# service iptables restart

****STEP4: Make sure using chkconfig that vncserver is enabled for level 2,3,4,5. Then RESTART the machine.

Note: If you suspect the firewall blocking, then disable the firewall altogether and test VNC if it works. I use tightVNC to test.

VNC will typically use port 59xx, where "xx" is the console number. Use the command netstat -na | less to see the ports that are open on the system. Look in the 5xxx range for VNC.