본문으로 바로가기

centos 6.9 최소 설치 후 환경설정

category 시스템/CENTOS6 2017. 7. 10. 16:17

centos 6.9 최소 설치 후 환경설정

CENTOS6 minimal 설치를 진행하고 나서 기본적인 명령어나 서버에 필요한 환경설정에 대해 포스팅합니다.

 

설치환경

CENTOS 6.9 minimal

 

1. 네임서버 설정

yum, dns 및 도메인 조회를 위해 DNS 를 설정합니다.

(통상적으로 1차,2차 KT DNS를 많이 설정하지만 가끔 SSH 접속시 세션 지연 현상으로 인하여 데이콤을 1차로 설정했습니다.)

 

vi /etc/resolv.conf

nameserver 164.124.101.2            데이콤 1차 DNS

nameserver 168.126.63.2             KT 2차 DNS

 

2. YUM 미러 변경

기본으로 써도 사용엔 문제가 없으나, 속도 향상을 위해 국내 미러 사이트로 변경합니다.

아래의 3줄을 입력하여 국내 미러사이트로 변경합니다.

 

[root@bashlinux ~]# sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo
[root@bashlinux ~]# sed -i "s/#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/centos.mirror.cdnetworks.com/g" /etc/yum.repos.d/CentOS-Base.repo
[root@bashlinux ~]# sed -i "s/gpgkey=http:\/\/mirror.centos.org/gpgkey=http:\/\/centos.mirror.cdnetworks.com/g" /etc/yum.repos.d/CentOS-Base.repo

 

3. 호스트네임 설정

 

[root@bashlinux ~]# vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=bashlinux

 

4. epel,기본 패키지 설치, update

 

[root@bashlinux ~]# yum install epel-release

[root@bashlinux ~]# yum install rdate rsync net-snmp net-snmp-libs ntsysv wget gcc vim* openssh-clients bind-utils jwhois sysstat rsync man lrzsz xinetd irqbalance dmidecode smartmontools nrpe

[root@bashlinux ~]# yum update

 

 

각각의 패키지의 용도는 아래와 같습니다.

 

 rdate

 시간 동기화 명령어 rdate 패키지

 rsync

 원격 파일/디렉토리 동기화 명령어 패키지

 net-snmp, net-snmp-libs

 snmp 사용을 위한 패키지

 ntsysv

 그래픽 환경으로 서버 재부팅 시 데몬 on/off 설정을 할수 있는 툴

 wget

 외부 웹서버등 에서 콘텐츠를 가져오는 명령어

 gcc

 컴파일러

 openssh-clients

 ssh 클라이언트 (rsync, scp 등을 이용하기 위해 필수 설치)

 bind-utils

 도메인의 IP, 네임서버 등을 조회하는 dig, nslookup 명령어 패키지

 jwhois

 도메인의 정보를 조회할수 있는 whois 명령어 패키지

 sysstat

 iostat,mpstat 등 시스템 상태를 조회하기 위한 명령어 패키지

 man

 매뉴얼 패키지

 lrzsz

 Xshell에서 파일업로드, 다운로드를 간편하게 하는 툴 (다른 원격접속 툴(putty, securecrt) 등을 사용한다면 설치안해도됨)

 xinetd

 슈퍼데몬 서비스 주로 rsync나 tftp 등을 많이 사용

 irqbalance

 두개 이상의 CPU 에서 분산처리를 가능하게 하는 유틸 (듀얼CPU 이상에선 필수패키지)

 dmidecode

 서버 정보나 하드웨어 상태 확인 유틸

 smartmontools

 디스크 상태 확인 및 검출 유틸

 nrpe

 nagios의 에이전트 (nagios를 사용하지 않는다면 설치 안해도됨)

 

5. 언어설정

 

[root@bashlinux ~]# vi /etc/sysconfig/i18n

LANG="ko_KR.UTF-8"    # 한글 utf8로 변경

 

6. selinux 해제

 

[root@bashlinux ~]# 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        # disable로 변경
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

7. vi -> vim 교체

 

[root@bashlinux ~]# vi /root/.bashrc

 # .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'    # 구문 추가

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
f

[root@bashlinux ~]# source .bashrc    # 설정내용 저장

 

8. time 설정

 

[root@bashlinux ~]# rdate -s 203.248.240.140 && rdate -s time.bora.net      #    time.bora.net 타임서버와 동기화
[root@bashlinux ~]# echo "59 23 * * * root rdate -s time.bora.net" >> /etc/crontab         # 매일 23시 59분에 실행되도록 crontab 설정

 

9. sshd_config, sftp로깅 설정

 

[root@bashlinux ~]# /bin/sed -i "s/\#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config    # ROOT 접속 차단 (단 일반 계정 생성 이후 진행) 

[root@bashlinux ~]# /bin/sed -i "s/sftp-server/sftp-server -f user -l DEBUG/g" /etc/ssh/sshd_config    # SFTP 로깅 설정

[root@bashlinux ~]# perl -p -i -e '$.==50 and print "user.* /var/log/sftp.log\n"' /etc/rsyslog.conf    # rsyslog에 sftp 구문 추가 

[root@bashlinux ~]# useradd bashlinux     # root를 차단했으므로 유저생성

[root@bashlinux ~]# passwd bashlinux      # 패스워드 설정

Changing password for user bashlinux.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

 

10. sftp 로그 로테이트 설정

 

[root@bashlinux ~]# vi /etc/loglotate.d/sftp

 /var/log/sftp.log {
  rotate 30    # 30개 보관
  daily    # 일 단위 로테이트
  dateext    # 날짜형식 사용
  compress    # 압축
  missingok    # 로그파일 없어도 에러메세지 출력 안함
  notifempty    # 로그 내용이 없으면 로테이트 하지않음

}

 

logrotate -f /etc/logrotate.d/sftp     # 로테이트 실행

 

11. iptables 설정

현재 접속세션, 개인 PC 외에는 들어오는 패킷에 대하여 모두 차단하는 정책이므로 실서버에 사용 시엔 주의가 필요합니다.

(해당 정책은 참고사항이며 정책 적용 이후 문제 발생시 책임은 사용자 본인에게 있음을 알려드립니다.)

 

 

[root@bashlinux ~]# vi /etc/sysconfig/iptables

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]


-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT    # icmp 허용
-A INPUT -i lo -j ACCEPT 

-A INPUT -s 127.0.0.1 -j ACCEPT

 

# 허용 IP (1.1.1.1 이라고 가정)
-A INPUT -s 1.1.1.1 -j ACCEPT    # 1.1.1.1 대신 서버에 접속할 개인PC나, 사무실PC의 공인 IP를 입력 (공인ip 확인방법 ipconfig.co.kr 접속 후 빨간 글씨)

 

# 서비스포트

-A INPUT -p tcp --dport 22 -j ACCEPT     # SSH 포트 모두 허용 , 실서버에서는 보안상 이유로 수정 필요
#-A INPUT -p tcp --dport 80 -j ACCEPT    # 현재는 사용하지 않으므로 주석

 

# 차단정책

-A INPUT -j DROP    # 위의 명시된 정책 외에 들어오는 모든 정책에 대하여 차단
-A FORWARD -j DROP 

-A OUTPUT -j ACCEPT    # 아웃바운드 정책 모두 허용

COMMIT

 

12. ntsysv 설정

crond, iptables, irpbalance, network, rsyslog, sshd

필수 서비스이며 이외에 xinetd 등을 체크하고 나머지는 disabled 합니다.

 

13. 서버 재부팅

 

 

이로써 기본적인 세팅이 완료 되었습니다.

이런 반복적인 업무를 매번 수동입력 하는 것보다 스크립트를 하나 만들어서 계속 사용 하는것이 편리합니다.

사실 디테일하게 적용한다면 할것은 많지만, 일단은 필수적인 설정에 대해 다뤄보았습니다.