개발개발/LINUX

centos 6.x 서버 세팅기. (기본설정 + APM)

꾸냥 2012. 11. 14. 18:29

집에 서버로 쓰는 컴 한대가 있는데... 항상 켜놓고 안정적인 환경에서 도는... 그냥... 가상화 서버가 가지고 싶었다.


이제 세팅을 시작해 보자면...


0. 서버의 생명은 우선 시간!!! 시간 동기화 해주고

# rdate -s time.bora.net


1. 사용할 아이디 생성 (root 직접 접근은 보안상 안좋음)

#useradd memberId

#passwd memberId

Changing password for user memberId.
New password:
Retype new password:

passwd: all authentication tokens updated successfully.


2. 생성한 아이디로 외부에서 접속해보기


3. vim 설치 (파일 편집하기 위해선 필요)

# yum install vim


4. 직접 root 접속 못하게 막기 (이건 외부에 접속 가능한 일반 아이디가 확실히 있는지 확인하고 해야됨^^)

# vim /etc/ssh/sshd_config

PermitRootLogin no

# service sshd restart

Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]


5. APM 설치하기 (mysql => apache => php)

# yum install mysql mysql-server

# yum install httpd

# yum install php


// 그리고 추가적으로 php 에서 사용하는 라이브러리가 좀되니 그건 기본적으로 설치해줌

# yum install gd gd-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel fontconfig  fontconfig-devel libxml2 libxml2-devel openssl openssl-devel gmp gmp-devel mhash mhash-devel libmcrypt libmcrypt-devel mysql-server php-mysql php-devel php-gd php-mbstring php-mhash


// 참고로 mysql 까지 한방설치하기

# yum groupinstall "MySQL Database" "Web Server"


6. 부팅시 apache 와 mysql 자동 띄우기

# chkconfig --level 2345 httpd on

# chkconfig --level 2345 mysqld on


7. mysql 설정하기 (자세한 설정은 디비 사용하면서 잡기)

7.1 디비 설정파일 복사  샘플 위치 /usr/share/mysql/my-{종류}.cnf, 

종류: huge:1GB 이상, large:512MB ~ 1GB, medium.:128MB ~ 256MB, small:64MB 이하

# cp /usr/share/mysql/my-large.cnf /etc/my.cnf 


7.2 서버시작

# service mysqld start


// 시작이 안되면

mysql_install_db --user=mysql


7.3 비밀번호 설정 및 접속 확인

# mysqladmin -uroot password 비밀번호

# mysql -uroot -p

Enter password: 비밀번호

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

....


// 혹시 비밀번호 등록 안되어있는 사용자 업데이트 하기

mysql> use mysql;
Database changed

mysql> update user set password=password('비밀번호') where password='';


7.4 사용자 등록 및 디비 생성

// mysql 디비로 이동

mysql> use mysql;
Database changed


// 디비 생성

mysql> create database `db_name` character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)


// 사용자 생성 (로컬접속 & 전체접속)
mysql> GRANT ALL PRIVILEGES ON db_name.* TO 'user_id'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)


mysql> GRANT ALL PRIVILEGES ON db_name.* TO 'user_id'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)


// 디비와 사용자 연결하기 (테스트용이니 권한은 모조리, 자리수 틀릴지 모름 필요한 권한만 잡아 넣어줌 됨)

mysql> INSERT INTO db VALUES ('localhost','db_name','user_id','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db VALUES ('%','db_name','user_id','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');


// 디비와 사용자 연결하기 다른 방법 (모든 권한 주기)
mysql> GRANT ALL ON db_name.* TO 'user_id';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL ON db_name.* TO 'user_id@localhost';
Query OK, 0 rows affected (0.00 sec)


// 디비에 바로 반영 시키기
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


// 외부에서 접근 안되면 3306번 방화벽 열어주기

# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

# service iptables restart

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:                         [  OK  ]



8. apache 기본설정 (세밀한건 운영하면서 잡고, 우선 기본적인것만)

8.1 기본설정

ServerName domain:80

DirectoryIndex index.html index.php index.htm


8.2 PHP 연결하기 (AddType application 위치를 찾는다), 아래 내용 추가

AddType application/x-httpd-php .htm .html .php .ph php3 .php4 .phtml .inc

AddType application/x-httpd-php-source .phps


# service httpd restart


// 외부에서 접속이 안된다면. 80 포트 방화벽 등록, 저장 => 재시작

# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

# service iptables restart

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:                         [  OK  ]


8.2 vhost 설정

// vhost 사용할 도메인 등록

# vim /etc/httpd/conf.d/httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin adminEmail@emaildomain.com
        DocumentRoot /home/htdocs/
        ServerName www.domain.com
        ServerAlias www.domain.com
</VirtualHost>


// 접속 테스트

Forbidden

You don't have permission to access / on this server.
Apache/2.2.15 (CentOS) Server at www.domain.com Port 80


// /home/htdocs/ 권한 확인함. 폴더는 rwx r-x r-x 로 되어야함(소유자:읽고쓰고실행, 그룹,전체:읽고쓰기)

# chmod -R 755 /home/htdocs/


끝~~~












반응형