■ CentOS 7 64bit [제가포스팅한 설치이후 환경에서 작업]

■ kernel 4.9 [저는 최신 커널에서 작업합니다. 기존커널에서 작업하셔도 됩니다]

■ APM [Apache 2.4.x 이상 버전이 설치된 환경입니다. 버전은 달라도 작동방식은 거의 대부분 비슷합니다]

■ 일부 설정이나 경로가 다를수 있습니다. 실서버가 아닌 VMware 환경에서 작업이 이루어집니다.


가상호스트 (virtual host)란?


기본적으로 웹서버에 존재하는 주 호스트 즉 예로 (aaa.com) 이라는 도메인을 등록하여 사용하고 있지만 추가적으로 한서버에 (bbb.com) / (ccc.com) 등 여러도메인을 등록하여 사용한다는 의미입니다. 가상호스트에도 여러종류의 방면으로 운용을 할수 있지만 일반적으로 하나의 컴퓨터(서버)나 IP로여러 이름의 도메인으로 각각 운용할수 있다는 부분입니다.


 일반적인 웹서버 (서버 3대)

 가상호스트 웹서버 (서버 1대)

 aaa.com (IP : 111.111.111.111)

 aaa.com (IP : 111.111.111.111)

 bbb.com (IP : 222.222.222.222)

 bbb.com (IP : 111.111.111.111)

 ccc.com (IP : 333.333.333.333)

 ccc.com (IP : 111.111.111.111)

이러한 가상 호스트서버를 이용하여 제한된 공간안에서 여러개의 홈페이지를 제공해주는 서비스가 (웹,메일 등) 호스팅 서비스 입니다. 


그럼 지금부터 서버한대에 여러 도메인을 등록하는 방법을 알아보겠습니다.

■  Apache - 가상호스트(httpd.conf) 설정

1. httpd.conf 파일을 열어 추가 수정

BASH

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

.

. (맨 아래라인에 추가 / 이미 있다면 # 주석제거)


356 NameVirtualHost *:80 ( 추가 / Apache 2.4.x 이상이므로 해당 버전에서는 추가 안해도 됩니다. ) 357 358 include /etc/httpd/conf/vhost.conf (추가)

359 360 <Directory "/home"> (추가) 361 AllowOverride None 362 Require all granted 363 </Directory>


:wq (저장)

[참고]


■ NameVirtualHost *:80

이름 기반의 가상호스트(도메인별) 사용하겠다는 뜻입니다.


추가내용(2017-02-27)

Apache 2.4.x 이상버전에서 [NameVirtualHost *:80] 옵션을 넣을시 아래와 같은 문구가 발생하는데요.

AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf/httpd.conf:356

문제는 없습니다. 다만 이상버전에서는 사용선언을 안해도 적용되게끔 변경이 된건데... 어쩐지 처음 httpd.conf 설정파일에 없었던 이유가 있었네요.

다음 릴리즈에서는 해당 오류 메세지를 없앤다고하니 무시하셔도 되는 로그 입니다. 신경이 쓰인다면 지우는것을 권고합니다.


Apache 2.4.x 이하버전에서는 꼭  해주시기 바랍니다.


■ include /etc/httpd/conf/vhost.conf

httpd.conf 안에 바로 설정하여도 되지만 여러개의 도메인을 등록하여 관리를 하실려고 하신다면 별도의 파일을 만들어 관리하시는게 좋습니다.

(Yum으로 설치한 아파치는 샘플파일이 없기때문에 직접 생성하여 등록을 진행해야 합니다.)

Source 직접 설치하였다면 일반적인 경로는 ../apache/conf/extra/httpd-vhosts.conf 혹은 vhost.conf 샘플파일이 있습니다.


■ <Directory "경로" , Require all granted> 추가

/home 경로에 도메인을 소스 업로드 및 홈페이지 테스트 불러올수 있게 디렉토리 접근 권한을 허용해야 합니다. 

만약 하지 않으면 다음과 같이 페이지 접근 할 수 없다는 에러페이지가 뜨실겁니다.

[Thu Feb 23 15:48:06.717299 2017] [authz_core:error] [pid 4172] [client 192.168.223.1:55533] AH01630: client denied by server configuration


 Apache 2.4 버전 이상일 경우

 Apache 2.4 버전 이하일 경우

 <Directory "/디렉토리 경로">

   AllowOverride None

   Require all granted

</Directory>

 <Directory "/디렉토리 경로">

   AllowOverride None

   Order allow,deny

   Allow from all

</Directory>


와 같이 셋팅하시면 됩니다.


2. vhost.conf 파일 생성 및 설정

BASH

[root@localhost ~]# vi /etc/httpd/conf/vhost.conf


############### webtest11.com Start ############### <VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com DocumentRoot /home/test ServerName webtest11.com ServerAlias www.webtest11.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> ############### webtest11.com End ################# ############### webtest22.com Start ############### <VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com DocumentRoot /home/test2 ServerName webtest22.com ServerAlias www.webtest22.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> ############### webtest11.com End #################


:wq (저장)

[참고]


■ 잘모르겠다면 그대로 전체 복사하여 저장 및 진행하시면 됩니다.


■ 각 설정 의미 (아래 호스트하나가 한 셋트입니다 / # 주석처리는 선택사항입니다, 없어도 됩니다. )

<VirtualHost *:80>

  #    ServerAdmin webmaster@dummy-host.example.com  ← 서버관리자(임의로 설정)

        DocumentRoot /home/test                       ← 홈디렉토리

        ServerName webtest11.com                       ← 연결할도메인(DNS설정이랑 같게해야함)

        ServerAlias www.webtest11.com                ← 연결할도메인(다른 도메인, DNS설정이랑 같게해야함)

  #    ErrorLog logs/dummy-host.example.com-error_log                     ← 에러로그(선택사항)

  #    CustomLog logs/dummy-host.example.com-access_log common   ← 접속로그(선택사항)

 </VirtualHost>


3. 홈페이지 경로(DocumentRoot) 및 테스트 페이지 생성

BASH

[root@localhost ~]# mkdir /home/test (DocumentRoot 경로 생성) [root@localhost ~]# mkdir /home/test2 (DocumentRoot 경로 생성)

BASH

[root@localhost ~]# vi /home/test/index.html (test할 페이지 생성)

webtest11.com Test page! <br/> If you see this screen, it is good setting!


:wq (저장)

BASH

[root@localhost ~]# vi /home/test2/index.html (test2할 페이지 생성)

webtest22.com Test page! <br/> If you see this screen, it is good setting!


:wq (저장)

BASH

[root@localhost ~]# chmod -R 755 test (읽기 쓰기 권한 부여)

[root@localhost ~]# chmod -R 755 test2 (읽기 쓰기 권한 부여)


[root@localhost ~]# ls -al /home (권한 변경 및 생성 확인)

.

.

drwxr-xr-x (권한 확인) 2 root root 4096 2??23 16:36 test drwxr-xr-x (권한 확인) 2 root root 4096 2??23 16:38 test2



4. 아파치(Apache) 재시작 적용

BASH

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# ps -ef | grep httpd

root 4517 1 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 4519 4517 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 4520 4517 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 4521 4517 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 4522 4517 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 4523 4517 0 16:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 4525 2195 0 16:45 pts/0 00:00:00 grep --color=auto httpd

■  실전테스트(웹 페이지 연결)

원래는 홈페이지를 연결하기위해서는 실제 도메인을 네임서버에 A레코드를 연결해야하지만 현재는 도메인이 존재하지 않기때문에 본인PC 에서 강제로 호스트를 지정하여 홈페이지를 연결하는 방법을 알려드리도록 하겠습니다. 해당 방법을 알고 있다면 굳이 호스팅업체에 맡길필요없이 홈페이지 소스를 업로드 하여 페이지가 정상적으로 뜨는지를 확인 및 테스트할수 있습니다.


1. 개인PC (hosts 파일 수정)

경로 : C:\Windows\System32\drivers\etc

(경로는 Windows 7, Windows 8.1, Windows 10 버전 동일합니다.)



[다음]



[만약 저장시 권한이 없다고 뜬다면 백신프로그램에 의해 보호 받고 있는지 확인 OFF 진행]




2. 연결 테스트


명령 프롬프트를 통해 PING 테스트를 확인합니다.



최종적으로 실제 브라우저를 통해 홈페이지가 정상적으로 연결이 되는지 확인해 봅니다.



위와같이 페이지가 보인다면 정상적으로 가상 호스트 설정이 완료가 되었습니다.

※ 이는 자기 PC에서만 확인 가능한방법입니다. [혹은 공유기가 연결된 같은 사설(내부)네트워크]


렇게 가상호스트설정을 적절하게 잘 이용한다면 한서버에 여러개의 홈페이지를 셋팅하여 이용할수 있으며 호스팅 비용을 절약할수 있는 효과를 볼수 있습니다. 그리고 한서버에 업로드를 하기때문에 관리차원에서도 편합니다.


이렇게 가상호스트에 대해서 알아보았는데요. 최대한 쉽게 전달하기위해 모든 테스트 화면을 직접 보여드리지만 이마저도 어렵게 느껴지는 분들이 있을수 있습니다. 책이나 매뉴얼을 만드는 저자분들은 대단하다고 생각이 듭니다.


※ 출처 : http://aeac.tistory.com/23

'프로그래밍 > linux' 카테고리의 다른 글

RHEL/CentOS 7 에서 방화벽(firewalld) 설정하기  (0) 2018.03.08
CentOS SELinux 설정 및 해제하기  (0) 2018.03.08
CentOS 7 웹서버 구축 [APM] - YUM설치  (0) 2018.03.08
SVN 명령어  (0) 2018.03.02
용량확인  (0) 2018.03.02

◇ [설치환경]

■ 릴리즈 설치 테스트 갱신 : 2017년 2월 19일


■ CentOS 7 64bit [제가포스팅한 설치이후 환경에서 작업]

■ kernel 4.9 [저는 최신 커널에서 작업합니다. 기존커널에서 작업하셔도 됩니다]

■ 일부 설정이나 경로가 다를수 있습니다. 실서버가 아닌 VMware 환경에서 작업이 이루어집니다.

 이전에 포스팅한 내용과 비슷하지만 이번에는 Apache2.4(유지), PHP7, MariaDB 10 최신버전으로 진행합니다.


웹서버 구축을 하기위해 APM [Apache, Mysql(Maria), PHP] 3개의 패키지가 설치가 되야합니다.

웹을 개발할려는 환경에따라 버전에 맞게 RPM(소스파일로 설치)하는게 좋지만 크게 영향을 받지 않는다면 일반적으로 YUM(자동설치)으로 쉽게 설치할수 있습니다. (Source 으로 설치하는건 나중에 따로 포스팅하도록 하겠습니다.)


시작합니다.


■ [APM] Apache, PHP7, MariaDB 10.1 Install(설치) Guide


1. 의존성 라이브러리 설치


□ 아래는 라이브러리가 설치되어있는지 확인해보는 부분이며 APM에 꼭 필요한 패키지가 있습니다.

BASH

[root@localhost ~]# rpm -qa libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel


libpng-1.5.13-7.el7_2.x86_64 gcc-c++-4.8.5-11.el7.x86_64 freetype-2.4.11-12.el7.x86_64 libjpeg-turbo-1.2.90-5.el7.x86_64 libpng12-1.2.50-10.el7.x86_64 gcc-4.8.5-11.el7.x86_64

□ Yum 으로 아래의 필요한 라이브러리를 한번에 전부 설치합니다. (한번에 관련된 의존성도 같이 설치가 됩니다.)

BASH

[root@localhost ~]# yum install libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel


.

.

======================================================================================================== Package Arch Version Repository Size ======================================================================================================== Installing: freetype-demos x86_64 2.4.11-12.el7 base 183 k freetype-devel x86_64 2.4.11-12.el7 base 356 k gd x86_64 2.0.35-26.el7 base 146 k gd-devel x86_64 2.0.35-26.el7 base 79 k gd-progs x86_64 2.0.35-26.el7 base 36 k gdbm-devel x86_64 1.10-8.el7 base 47 k libjpeg-turbo-devel x86_64 1.2.90-5.el7 base 98 k libjpeg-turbo-static x86_64 1.2.90-5.el7 base 120 k libjpeg-turbo-utils x86_64 1.2.90-5.el7 base 76 k libpng-devel x86_64 2:1.5.13-7.el7_2 base 122 k libpng-static x86_64 2:1.5.13-7.el7_2 base 92 k libpng12-devel x86_64 1.2.50-10.el7 base 111 k ncurses-devel x86_64 5.9-13.20130511.el7 base 713 k Installing for dependencies: expat-devel x86_64 2.1.0-10.el7_3 updates 57 k fontconfig-devel x86_64 2.10.95-10.el7 base 128 k libICE x86_64 1.0.9-2.el7 base 65 k libSM x86_64 1.2.2-2.el7 base 39 k libX11-devel x86_64 1.6.3-3.el7 base 980 k libXau-devel x86_64 1.0.8-2.1.el7 base 14 k libXpm x86_64 3.5.11-3.el7 base 54 k libXpm-devel x86_64 3.5.11-3.el7 base 36 k libXt x86_64 1.1.4-6.1.el7 base 173 k libxcb-devel x86_64 1.11-4.el7 base 1.1 M xorg-x11-proto-devel noarch 7.7-13.el7 base 281 k zlib-devel x86_64 1.2.7-17.el7 base 50 k Transaction Summary ======================================================================================================== Install 13 Packages (+12 Dependent packages) Total download size: 5.0 M Installed size: 14 M Is this ok [y/d/N]:y


.

.


Installed: freetype-demos.x86_64 0:2.4.11-12.el7 freetype-devel.x86_64 0:2.4.11-12.el7 gd.x86_64 0:2.0.35-26.el7 gd-devel.x86_64 0:2.0.35-26.el7 gd-progs.x86_64 0:2.0.35-26.el7 gdbm-devel.x86_64 0:1.10-8.el7 libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7 libjpeg-turbo-static.x86_64 0:1.2.90-5.el7 libjpeg-turbo-utils.x86_64 0:1.2.90-5.el7 libpng-devel.x86_64 2:1.5.13-7.el7_2 libpng-static.x86_64 2:1.5.13-7.el7_2 libpng12-devel.x86_64 0:1.2.50-10.el7 ncurses-devel.x86_64 0:5.9-13.20130511.el7 Dependency Installed: expat-devel.x86_64 0:2.1.0-10.el7_3 fontconfig-devel.x86_64 0:2.10.95-10.el7 libICE.x86_64 0:1.0.9-2.el7 libSM.x86_64 0:1.2.2-2.el7 libX11-devel.x86_64 0:1.6.3-3.el7 libXau-devel.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.11-3.el7 libXpm-devel.x86_64 0:3.5.11-3.el7 libXt.x86_64 0:1.1.4-6.1.el7 libxcb-devel.x86_64 0:1.11-4.el7 xorg-x11-proto-devel.noarch 0:7.7-13.el7 zlib-devel.x86_64 0:1.2.7-17.el7 Complete!


2. [APM] Apache, PHP, MariaDB 설치 [순서는 : Apache, Maria, PHP 진행]



□ 아파치(Apache 2.4) 설치

BASH

[root@localhost ~]# yum install httpd


.

.

======================================================================================================= Package Arch Version Repository Size ======================================================================================================== Installing: httpd x86_64 2.4.6-45.el7.centos base 2.7 M Installing for dependencies: httpd-tools x86_64 2.4.6-45.el7.centos base 84 k mailcap noarch 2.1.41-2.el7 base 31 k Transaction Summary ======================================================================================================== Install 1 Package (+2 Dependent packages) Total download size: 2.8 M Installed size: 9.6 M Is this ok [y/d/N]: y

.

.

Installed: httpd.x86_64 0:2.4.6-45.el7.centos Dependency Installed: httpd-tools.x86_64 0:2.4.6-45.el7.centos mailcap.noarch 0:2.1.41-2.el7 Complete!


□ 마리아(Maria DB 10.1) 설치


기존의 Yum 으로 설치할경우는 Maria DB 5.5 버전이 설치가 됩니다. 

최신버전으로 설치할경우 Yum 미러경로를 직접지정해야 합니다.


배포사이트 : http://mariadb.org/

버전별 셋팅방법 : http://downloads.mariadb.org/mariadb/repositories/


먼저 Yum 저장소 생성

BASH

[root@localhost ~]# vi /etc/yum.repos.d/MariaDB.repo


# MariaDB 10.1 CentOS repository list # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1


:wq (저장)

이후 설치 진행

BASH

[root@localhost ~]# yum install MariaDB-server MariaDB-client


.

.

======================================================================================================================== Package Arch Version Repository Size ======================================================================================================================== Installing: MariaDB-client x86_64 10.1.21-1.el7.centos mariadb 39 M MariaDB-server x86_64 10.1.21-1.el7.centos mariadb 101 M MariaDB-shared x86_64 10.1.21-1.el7.centos mariadb 1.3 M replacing mariadb-libs.x86_64 1:5.5.52-1.el7 Installing for dependencies: MariaDB-common x86_64 10.1.21-1.el7.centos mariadb 43 k boost-program-options x86_64 1.53.0-26.el7 base 156 k galera x86_64 25.3.19-1.rhel7.el7.centos mariadb 8.0 M jemalloc x86_64 3.6.0-1.el7 mariadb 104 k lsof x86_64 4.87-4.el7 base 331 k perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k perl-DBI x86_64 1.627-4.el7 base 802 k perl-IO-Compress noarch 2.061-2.el7 base 260 k perl-Net-Daemon noarch 0.48-5.el7 base 51 k perl-PlRPC noarch 0.2020-14.el7 base 36 k Transaction Summary ======================================================================================================================== Install 3 Packages (+11 Dependent packages) Total download size: 151 M Is this ok [y/d/N]: y


.

.


Total 1.7 MB/s | 151 MB 00:01:28 Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Importing GPG key 0x1BB943DB: Userid : "MariaDB Package Signing Key <package-signing-key@mariadb.org>" Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Is this ok [y/N]: y


.

.


Installed: MariaDB-client.x86_64 0:10.1.21-1.el7.centos MariaDB-server.x86_64 0:10.1.21-1.el7.centos MariaDB-shared.x86_64 0:10.1.21-1.el7.centos Dependency Installed: MariaDB-common.x86_64 0:10.1.21-1.el7.centos boost-program-options.x86_64 0:1.53.0-26.el7 galera.x86_64 0:25.3.19-1.rhel7.el7.centos jemalloc.x86_64 0:3.6.0-1.el7 lsof.x86_64 0:4.87-4.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Replaced: mariadb-libs.x86_64 1:5.5.52-1.el7 Complete!


□ PHP 7 설치


PHP 역시 기존의 Yum 으로 설치할경우는 PHP 5.4 버전이 설치가 됩니다. 

최신버전으로 설치하기위해 Webtatic EL 저장소를 추가합니다.


버전별 참고사이트  : https://webtatic.com/projects/yum-repository/


먼저 Yum 저장소 생성

BASH

[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


이후 설치

BASH

[root@localhost ~]# yum install php70w


.

.

======================================================================================================================== Package Arch Version Repository Size ======================================================================================================================== Installing: php70w x86_64 7.0.15-1.w7 webtatic 2.8 M Installing for dependencies: php70w-cli x86_64 7.0.15-1.w7 webtatic 2.9 M php70w-common x86_64 7.0.15-1.w7 webtatic 1.2 M Transaction Summary ======================================================================================================================== Install 1 Package (+2 Dependent packages) Total download size: 6.9 M Installed size: 27 M Is this ok [y/d/N]: y


.

.

Total 1.2 MB/s | 6.9 MB 00:00:05 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7 Importing GPG key 0x62E74CA5: Userid : "Webtatic EL7 <rpms@webtatic.com>" Fingerprint: 830d b159 6d9b 9b01 99dc 24a3 e87f d236 62e7 4ca5 Package : webtatic-release-7-3.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7

Is this ok [y/N]: y


.

.

Installed: php70w.x86_64 0:7.0.15-1.w7 Dependency Installed: php70w-cli.x86_64 0:7.0.15-1.w7 php70w-common.x86_64 0:7.0.15-1.w7 Complete!

관련 PHP7 패키지 설치 (자주 쓰이는것을 골라봤습니다.)

BASH

[root@localhost ~]# yum install php70w-mysql php70w-pdo php70w-pgsql php70w-odbc php70w-mbstring php70w-mcrypt php70w-gd [root@localhost ~]# yum install php70w-pear php70w-pdo_dblib php70w-pecl-imagick php70w-pecl-imagick-devel php70w-xml php70w-xmlrpc


.

.

======================================================================================================================== Package Arch Version Repository Size ======================================================================================================================== Installing: php70w-gd x86_64 7.0.15-1.w7 webtatic 136 k php70w-mbstring x86_64 7.0.15-1.w7 webtatic 542 k php70w-mcrypt x86_64 7.0.15-1.w7 webtatic 26 k php70w-mysql x86_64 7.0.15-1.w7 webtatic 83 k php70w-odbc x86_64 7.0.15-1.w7 webtatic 51 k php70w-pdo x86_64 7.0.15-1.w7 webtatic 91 k php70w-pdo_dblib x86_64 7.0.15-1.w7 webtatic 20 k php70w-pear noarch 1:1.10.1-1.w7 webtatic 337 k php70w-pecl-imagick x86_64 3.4.2-0.1.w7 webtatic 128 k php70w-pecl-imagick-devel x86_64 3.4.2-0.1.w7 webtatic 5.0 k php70w-pgsql x86_64 7.0.15-1.w7 webtatic 89 k php70w-xml x86_64 7.0.15-1.w7 webtatic 129 k php70w-xmlrpc x86_64 7.0.15-1.w7 webtatic 48 k Installing for dependencies: ImageMagick x86_64 6.7.8.9-15.el7_2 base 2.1 M OpenEXR-libs x86_64 1.7.1-7.el7 base 217 k freetds x86_64 0.95.81-1.el7 epel 635 k ghostscript x86_64 9.07-20.el7_3.1 updates 4.3 M ghostscript-fonts noarch 5.50-32.el7 base 324 k ilmbase x86_64 1.0.3-7.el7 base 100 k lcms2 x86_64 2.6-3.el7 base 150 k libXfont x86_64 1.5.1-2.el7 base 150 k libfontenc x86_64 1.1.2-3.el7 base 30 k libmcrypt x86_64 2.5.8-13.el7 epel 99 k librsvg2 x86_64 2.39.0-1.el7 base 123 k libtool-ltdl x86_64 2.4.2-21.el7_2 base 49 k libwmf-lite x86_64 0.2.8.4-41.el7_1 base 66 k libxslt x86_64 1.1.28-5.el7 base 242 k pcre-devel x86_64 8.32-15.el7_2.1 base 479 k php70w-devel x86_64 7.0.15-1.w7 webtatic 2.5 M php70w-process x86_64 7.0.15-1.w7 webtatic 41 k poppler-data noarch 0.4.6-3.el7 base 2.2 M postgresql-libs x86_64 9.2.18-1.el7 base 232 k unixODBC x86_64 2.3.1-11.el7 base 413 k urw-fonts noarch 2.4-16.el7 base 3.0 M xorg-x11-font-utils x86_64 1:7.5-20.el7 base 87 k Transaction Summary ======================================================================================================================== Install 13 Packages (+22 Dependent packages) Total download size: 19 M Installed size: 73 M Is this ok [y/d/N]: y


.

.

Total 3.8 MB/s | 19 MB 00:00:05 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Importing GPG key 0x352C64E5: Userid : "Fedora EPEL (7) <epel@fedoraproject.org>" Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Package : epel-release-7-9.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Is this ok [y/N]: y


.

.

Installed: php70w-gd.x86_64 0:7.0.15-1.w7 php70w-mbstring.x86_64 0:7.0.15-1.w7 php70w-mcrypt.x86_64 0:7.0.15-1.w7 php70w-mysql.x86_64 0:7.0.15-1.w7 php70w-odbc.x86_64 0:7.0.15-1.w7 php70w-pdo.x86_64 0:7.0.15-1.w7 php70w-pdo_dblib.x86_64 0:7.0.15-1.w7 php70w-pear.noarch 1:1.10.1-1.w7 php70w-pecl-imagick.x86_64 0:3.4.2-0.1.w7 php70w-pecl-imagick-devel.x86_64 0:3.4.2-0.1.w7 php70w-pgsql.x86_64 0:7.0.15-1.w7 php70w-xml.x86_64 0:7.0.15-1.w7 php70w-xmlrpc.x86_64 0:7.0.15-1.w7 Dependency Installed: ImageMagick.x86_64 0:6.7.8.9-15.el7_2 OpenEXR-libs.x86_64 0:1.7.1-7.el7 freetds.x86_64 0:0.95.81-1.el7 ghostscript.x86_64 0:9.07-20.el7_3.1 ghostscript-fonts.noarch 0:5.50-32.el7 ilmbase.x86_64 0:1.0.3-7.el7 lcms2.x86_64 0:2.6-3.el7 libXfont.x86_64 0:1.5.1-2.el7 libfontenc.x86_64 0:1.1.2-3.el7 libmcrypt.x86_64 0:2.5.8-13.el7 librsvg2.x86_64 0:2.39.0-1.el7 libtool-ltdl.x86_64 0:2.4.2-21.el7_2 libwmf-lite.x86_64 0:0.2.8.4-41.el7_1 libxslt.x86_64 0:1.1.28-5.el7 pcre-devel.x86_64 0:8.32-15.el7_2.1 php70w-devel.x86_64 0:7.0.15-1.w7 php70w-process.x86_64 0:7.0.15-1.w7 poppler-data.noarch 0:0.4.6-3.el7 postgresql-libs.x86_64 0:9.2.18-1.el7 unixODBC.x86_64 0:2.3.1-11.el7 urw-fonts.noarch 0:2.4-16.el7 xorg-x11-font-utils.x86_64 1:7.5-20.el7 Complete!

[참고사항]

다음 명령어로 php7 관련 패키지 설치할수 있는 리스트들을 확인할수 있습니다. 

위 설치외에 필요한 패키지가 있다면 추가로 설치하면 됩니다.

BASH

[root@localhost ~]# yum search php70w


.

.

================================================= N/S matched: php70w ================================================== php70w.x86_64 : PHP scripting language for creating dynamic web sites php70w-bcmath.x86_64 : A module for PHP applications for using the bcmath library php70w-cli.x86_64 : Command-line interface for PHP php70w-common.x86_64 : Common files for PHP php70w-dba.x86_64 : A database abstraction layer module for PHP applications

.

.

php70w-tidy.x86_64 : Standard PHP module provides tidy library support php70w-xml.x86_64 : A module for PHP applications which use XML php70w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol Name and summary matches only, use "search all" for everything.


□ 설치 확인 및 버전확인

BASH

root@localhost ~]# httpd -v


Server version: Apache/2.4.6 (CentOS) Server built: Nov 14 2016 18:04:44

BASH

[root@localhost ~]# php -v


PHP 7.0.15 (cli) (built: Jan 19 2017 21:35:05) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

BASH

root@localhost ~]# mysql -V


mysql Ver 15.1 Distrib 10.1.21-MariaDB, for Linux (x86_64) using readline 5.1


아래부터는 설정 동일합니다.

■ [APM] Apache, PHP, MariaDB config(설정) 및 구동

1. 아파치(Apache) 설정 및 구동


□ 기본설정

BASH

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf


.

.

62 # User/Group: The name (or #number) of the user/group to run httpd as. 63 # It is usually good practice to create a dedicated user and group for 64 # running httpd, as with most system services. 65 # 66 User nobody (apache → nobody 변경) 67 Group nobody (apache → nobody 변경)

.

.

93 # If your host doesn't have a registered DNS name, enter its IP address here. 94 # 95 #ServerName www.example.com:80

96 ServerName 192.168.122.128:80 (도메인 또는 해당서버 IP 입력 추가)

.

.


:wq (저장)

[참고]


■ apache → nobody 변경

ROOT 권한으로 실행된 아파치의 하위 프로세스를 이곳에서 지정한 사용자로 실행한다는 의미, 

기본값으로 apache 또는 daemon 으로 되어있지만 대부분 nobody로 변경하여 이용한다. 약간 보안적인 의미를 포함


■ ServerName

자기 서버가 이 도메인을 사용한다는것을 알리기 위한 수단, 예를 들어

ServerName www.test.com:80 → 홈페이지 접속시 해당 도메인(http://www.test.com)으로 연결

ServerName 192.168.122.128:80 → 홈페이지 접속시 해당 도메인((http://192.168.122.128)으로 연결 (도메인이 없을경우 IP 입력)


■ IP는 자기서버 IP 셋팅

[root@localhost ~]# ifconfig

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

        inet 192.168.223.129 (이부분)  netmask 255.255.255.0  broadcast 192.168.223.255



□ 방화벽 설정


환경설정이 완료가 되었으니 웹을 열기위해선 방화벽 80번 포트를 오픈해야합니다.

BASH

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


# sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT (추가) -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT



:wq (저장)

[참고]


■ iptables 에서 순서는 매우 중요합니다. 일반적으로 적용되는 순서는 위에서부터 아래로 순차적으로 읽어옵니다.

예를들어 추가한 맨 아래의 라인쪽에 추가를 하게되면 적용이 정상적으로 안됩니다. 이해가 안되실경우는 스크린샷 그대로 따라진행해주세요. 나중에 별도로 iptables 설명을 하도록 하겠습니다.



□ 방화벽 재시작

BASH

[root@localhost ~]# service iptables restart

Redirecting to /bin/systemctl restart iptables.service

□ 적용 확인

BASH

[root@localhost ~]# iptables -nL


Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 (확인완료) REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination

□ 아파치 시작

BASH

[root@localhost ~]# systemctl start httpd


부팅후 자동 실행 설정

[root@localhost ~]# systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.


팅후 자동 실행 설정(해제)

[root@localhost ~]# systemctl disable httpd Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.


Service 명령어 이용 가능

[root@localhost ~]# service httpd start(stop)

□ 아파치 구동 확인

BASH

[root@localhost ~]# ps -ef |grep httpd


root 17652 1 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 17654 17652 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 17655 17652 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 17656 17652 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 17657 17652 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 17658 17652 0 13:46 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 17715 2983 0 13:51 pts/1 00:00:00 grep --color=auto httpd

□ 실제 웹 구동 테스트 확인



2. PHP 환경설정 및 구동(경로)


□ 기본설정

BASH

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

.

.

161 # DirectoryIndex: sets the file that Apache will serve if a directory 162 # is requested. 163 # 164 <IfModule dir_module> 165 DirectoryIndex index.html index.htm index.php (추가) 166 </IfModule>

.

.

270 # AddType allows you to add to or override the MIME configuration 271 # file specified in TypesConfig for specific file types. 272 # 273 #AddType application/x-gzip .tgz 274 AddType application/x-httpd-php .php .html .htm .inc (추가)

275 AddType application/x-httpd-php-source .phps (추가)


:wq (저장)

[참고]


■ 실제 PHP환경설정을 관리하는 파일은 아래의 경로입니다.

[root@localhost ~]# vi /etc/php.ini


위 httpd.conf 쪽에 셋팅하는건 아파치에 php 관련 처리를 할수 있게 추가를 하는 부분입니다. 

php.ini 파일설정은 사용할려는 웹환경에 맞게튜닝을 해야하지만 현재는 기본셋팅으로 갑니다. 나중에 따로 설명하도록 하겠습니다.



□ PHP 적용


Yum 설치시 html 업로드 기본 디렉토리는 아래와 같습니다.

BASH

[root@localhost ~]# cd /var/www/html/



해당 경로에서 PHP의 정보를 보여주는 함수의 파일을 하나 생성합니다.

BASH

[root@localhost html]# vi /var/www/html/phpinfo.php


<?php phpinfo(); ?> :wq (저장) [root@localhost html]# ls (파일생성 확인) phpinfo.php

PHP 환경설정을 적용하기위해 아파치(Apache)도 한번 재시작을 합니다.

BASH

[root@localhost html]# service httpd restart

Redirecting to /bin/systemctl restart httpd.service

항상 아파치(Apache) 구동이 제대로 되고 있는지 확인합니다.

BASH

[root@localhost html]# ps -ef | grep httpd


root 18135 1 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 18137 18135 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 18138 18135 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 18139 18135 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 18140 18135 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 18141 18135 0 16:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 18143 2983 0 16:58 pts/1 00:00:00 grep --color=auto httpd

□ PHP 적용 확인 테스트


개인 PC에서 인터넷창에 접속 테스트를 진행하면 됩니다.

이전 경로에 생성하였던 경로를 입렵합니다. URL : http://192.168.223.129/phpinfo.php



3. Maria DB 구동 및 설정


□ Maria DB 구동 및 구동 확인

BASH

[root@localhost ~]# systemctl start mariadb


[root@localhost ~]# ps -ef | grep mysql mysql 41093 1 1 19:48 ? 00:00:00 /usr/sbin/mysqld root 41130 11663 0 19:49 pts/1 00:00:00 grep --color=auto mysql

□ Maria DB 기본설정 (DB가 구동된 상태에서 진행가능)

BASH

[root@localhost ~]# mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): 패스워드가 없기때문에 엔터


OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y (DB ROOT 패스워드 설정) New password: 패스워드입력 Re-enter new password: 재확인 패스워드입력 Password updated successfully! Reloading privilege tables.. ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y (익명의 접근을 막을것인지? 보안을 위해 Y 엔터) ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y (DB ROOT 원격을 막을것인지? 보안을 위해 Y 엔터)

... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y (Test 용으로 생성된 데이터베이스를 삭제할것인가? Y 엔터)

- Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately.


Reload privilege tables now? [Y/n] Y (현재 설정한 값을 적용할것인지? 당연히 Y 엔터)

... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! (끝)

□ Maria DB 최종 접속 확인

BASH

[root@localhost ~]# mysql -u root -p Enter password: 패스워드 입력


Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.1.21-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

[참고]


Maria(Mysql) 환경설정을 관리하는 파일은 아래의 경로입니다.

[root@localhost ~]# vi /etc/my.cnf


my.cnf 파일설정은 사용할려는 DB환경에 맞게 튜닝을 해야하지만 현재는 기본셋팅으로 갑니다. 나중에 따로 설명하도록 하겠습니다.



이상 위에 순서대로 웹구축만하여도 웹서버를 구동하는데에는 크게 문제가 없습니다. 만약 직접 웹홈페이지 개발을 한다면 충분히 연습할수 있는 공간을 만들수 있을것으로 보입니다.



※ 출처 : http://aeac.tistory.com/21


'프로그래밍 > linux' 카테고리의 다른 글

CentOS SELinux 설정 및 해제하기  (0) 2018.03.08
Linux Apache - 가상호스트설정(Apache virtual host)  (1) 2018.03.08
SVN 명령어  (0) 2018.03.02
용량확인  (0) 2018.03.02
netstat 옵션  (0) 2018.03.02

# SVN 서버와 파일비교

svn diff [PATH1] [PATH2] ... 

svn diff -r 4 test.c (리비전 4의 test.c 파일비교)

# SVN 파일추가

svn add [PATH1]

# SVN 파일삭제

svn delete [PATH1]

# SVN 커밋

svn ci [PATH1] [PATH2] ... 

제목입력 후 wq!

svn ci -m '{커밋내용}' [PATH1] [PATH2] ... 

# SVN 업데이트(내려받기)

svn up [PATH1] [PATH2] ... 

# SVN 로그내역

svn log [PATH1]

지정된 로컬 PATH에 대한 로그를 출력한다. -r 옵션을 지정하면 출력할 리비젼 범위등을 정할 수 있다.

예제1) svn log -r 30:100 test.c

예제2) svn log public_html/testgirls.php | head -n20

# 롤백

svn merge -r HEAD:PREV [PATH]

# 보기

svn cat -r 8016 [PATH]


# SVN 상태조회

svn status [PATH]

-u 옵션을 주면 저장소의 최신 리비젼이 얼마인지 알려준다.

'프로그래밍 > linux' 카테고리의 다른 글

CentOS SELinux 설정 및 해제하기  (0) 2018.03.08
Linux Apache - 가상호스트설정(Apache virtual host)  (1) 2018.03.08
CentOS 7 웹서버 구축 [APM] - YUM설치  (0) 2018.03.08
용량확인  (0) 2018.03.02
netstat 옵션  (0) 2018.03.02

현재용량 확인

df -k : 킬로바이트 단위로 현재 남은 용량을 확인

df -m : 메가바이트 단위로 남은 용량을 왁인 

df -h : 보기 좋게 보여줌

df . : 현재 디렉토리가 포함된 파티션의 남은 용량을 확인


디스크용량 확인


전체용량

KB단위 : df -P | grep -v ^Filesystem | awk '{sum += $2} END { print sum " KB" }'

GB단위 : df -P | grep -v ^Filesystem | awk '{sum += $2} END { print sum/1024/1024 " GB" }'


전체사용량

KB단위 : df -P | grep -v ^Filesystem | awk '{sum += $3} END { print sum " KB" }'

GB단위 : df -P | grep -v ^Filesystem | awk '{sum += $3} END { print sum/1024/1024 " GB" }'

전체남은용량

KB단위 : df -P | grep -v ^Filesystem | awk '{sum += $4} END { print sum " KB" }'

GB단위 : df -P | grep -v ^Filesystem | awk '{sum += $4} END { print sum/1024/1024 " GB" }'


특정디스크 확인 -h로

전체 : df -P -h | grep /dev/sda3 | awk '{ print $2}'

사용량 : df -P -h | grep /dev/sda3 | awk '{ print $3}'

남은 : df -P -h | grep /dev/sda3 | awk '{ print $4}'


폴더용량 확인

du -hs 폴더

'프로그래밍 > linux' 카테고리의 다른 글

CentOS SELinux 설정 및 해제하기  (0) 2018.03.08
Linux Apache - 가상호스트설정(Apache virtual host)  (1) 2018.03.08
CentOS 7 웹서버 구축 [APM] - YUM설치  (0) 2018.03.08
SVN 명령어  (0) 2018.03.02
netstat 옵션  (0) 2018.03.02

netstat 명령어의 주요 옵션

    * -a : --all 과 같으며, listen 되는 소켓정보와 listen 되지 않는 소켓 정보를 모두 출력

    * -n : --numberic 과 같으며, 10진수의 수치 정보로 결과를 출력

    * -r : --route 와 같으며, 설정된 라우팅 정보를 출력

    * -p : --program 과 같으며, 실행되고 있는 각 프로그램과 PID 정보를 출력

    * -i : --interface=iface 와 같으며, 모든 네트워크 인터페이스 정보를 출력 또는, 특정 네트워크 인터페이스를 지정할 수도 있음

    * -c : --continuous 와 같으며, netstat 결과를 연속적으로 출력

    * -l : --listening 과 같으며, 현재 listen 되고 있는 소켓 정보를 출력

    * -s : --statistics 와 같으며, 각 프로토콜에 대한 통계 정보를 출력

        ex) netstat -rn    --> 라우팅 테이블 출력

netstat 명령의 실행결과로 출력되는 State 항목 값

    * 비어있음 : 연결되어 있지 않음

    * FREE : 소켓은 존재하지만 할당되어 있지 않음

    * LISTENING : 외부 연결요구에 응답준비가 되어 있는 상태

    * CONNECTING : 연결이 막 이루어진 상태

    * DISCONNECTING : 연결 해제되고 있는 상태

    * UNKNOWN : 알 수 없는 연결 즉, 알려지지 않은 연결상태

    * LISTEN : 연결 가능하도록 관련 데몬이 떠 있으며 연결이 가능함을 나타냄

    * SYS-SENT : 연결을 요청한 상태

    * SYN_RECEIVED : 연결 요구에 응답을 한 후에 확인 메시지를 기다리고 있는 상태

    * ESTABLISHED : 앞의 3단계 연결 과정이 모두 종료된 후에 연결이 완료된 상태

    * FIN-WAIT1, CLOSE-WAIT, FIN-WAIT2 : 연결 종료를 위해 종료 요청을 받은 후의 종료 과정임

    * CLOSING : 전송된 메시지가 유실된 상태

    * TIME-WAIT : 연결 종료 후에 한 동안 유지하고있는 상태

    * CLOSED : 연결이 완전히 종료됨

    ex) netstat -an |grep LISTEN

    ex) netstat -an |grep 192.168.108.130

    ex) netstat -atp    --> 열려진 포트를 사용하고 있는 프로세스 확인하는 방법

    ex) netstat -anp | grep LISTEN

    ex) netstat -tulpn | grep LISTEN  -> 현재 열려있는 포트확인

'프로그래밍 > linux' 카테고리의 다른 글

CentOS SELinux 설정 및 해제하기  (0) 2018.03.08
Linux Apache - 가상호스트설정(Apache virtual host)  (1) 2018.03.08
CentOS 7 웹서버 구축 [APM] - YUM설치  (0) 2018.03.08
SVN 명령어  (0) 2018.03.02
용량확인  (0) 2018.03.02

+ Recent posts