Tempo Di Valse

[Linux] Nginx 소스 컴파일 (베껴)설치하기 본문

개발/ETC

[Linux] Nginx 소스 컴파일 (베껴)설치하기

TempoDiValse 2022. 3. 10. 14:02

우선, 서버 엔지니어가 아닌 관계로.. 정확한 정보에 대해서 아는 바는 별로 없지만, 설치한 경험대로 기록을 해 보도록 하겠다.


NGINX 를 소스를 이용하여 설치 할 일이 생겨버렸다. 

 

지금까지 AWS EC2 인스턴스 하나 만들어서 sudo yum install -y  nginx 만 치면 알아서 RPM 깔리듯이 셋팅에 대해 신경쓰지않고 좌르륵 잘 깔렸는데, 이번에는 외부 접속이 되지 않는 바람에 yum 이고 뭐고 쓸 수가 없게 되었다 ㅠㅠ

 

방법은 하는 수 없이 NGINX 소스를 다운 받아서 설치를 해야 된다는 것이다. 그래서 열심히 여러 구글링을 모아보며 NGINX 를 뚫어본 경험에 대해서 작성해 보도록 하겠다.

 

1. 필요 패키지 설치하기

NGINX 를 설치하기 전에, 필요한 패키지 들이 있는데 그것들은 다음과 같다. 해당 라이브러리들이 서버에 있는 지 확인하고, 만약 설치 되어있지 않은 경우에는 미리 준비를 하거나 잘 모르겠다 싶으면 NGINX 를 설치하면서 어떤 라이브러리를 필요로 하는지 확인하면서 설치하면 되겠다. 

1. gcc (여기서 gcc 는 사실 이미 서버에 설치가 되어있어서 스킵을 했다.)
2. pcre
3. zlib
4. openssl

스킵한 부분은 제쳐두고,

 

- pcre 설치

 

yum 을 통해서 설치 한다면 pcre-devel 패키지를 다운로드 설치했겠지만, 그러지 못했기에.. 소스를 다운 받았다.

 

PCRE - Browse Files at SourceForge.net

×

sourceforge.net

PCRE2 가 아니라 PCRE 를 받도록 한다. 내가 받았던 버전은 pcre-8.45 버전이었다.

 

압축 파일을 다운 받아서 FileZila 를 통해 서버에 적절한 곳에 옮겨 담고서,

tar -xvf pcre-8.45.tar.bz2

를 호출했다.

 

압축이 풀린 다음에는 cd 를 통해 압축을 푼 디렉토리에 들어가고서

sudo ./configure

를 호출하였고 별 이상이 없으면 Makefile 이 디렉토리 안에 생성이 되었을 것이다. 그 다음에,

$ sudo make
...
...
...
$ sudo make install

 

sudo make 를 한 후 뭔가 실행이 되고, 에러가 없이 동작이 마무리 되면 sudo make install 을 실행하여 pcre 설치를 마무리하도록 한다. 대략 설치가 되는 모습이,

[xxx@xxx pcre-8.45]$ sudo ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
....
...
..
.
..
...
....
    Buffer size for pcregrep ........ : 20480
    Link pcregrep with libz ......... : no
    Link pcregrep with libbz2 ....... : no
    Link pcretest with libedit ...... : no
    Link pcretest with libreadline .. : no
    Valgrind support ................ : no
    Code coverage ................... : no

[xxx@xxx pcre-8.45]$ sudo make
rm -f pcre_chartables.c
ln -s ./pcre_chartables.c.dist pcre_chartables.c
make  all-am
make[1]: Entering directory `/home/xxx/utils/pcre-8.45'
  CC       pcretest-pcretest.o
  CC       pcretest-pcre_printint.o
  CC       libpcre_la-pcre_byte_order.lo
  CC       libpcre_la-pcre_compile.lo
  CC       libpcre_la-pcre_config.lo
  CC       libpcre_la-pcre_dfa_exec.lo
  
....
...
..
.
..
...
....
  CXX      pcre_scanner_unittest-pcre_scanner_unittest.o
  CXXLD    pcre_scanner_unittest
  CXX      pcre_stringpiece_unittest-pcre_stringpiece_unittest.o
  CXXLD    pcre_stringpiece_unittest
make[1]: Leaving directory `/home/xxx/utils/pcre-8.45'

[xxx@xxx pcre-8.45]$ sudo make install
make  install-am
make[1]: Entering directory `/home/xxx/utils/pcre-8.45'
make[2]: Entering directory `/home/xxx/utils/pcre-8.45'
 /bin/mkdir -p '/usr/local/lib'
 /bin/sh ./libtool   --mode=install /usr/bin/install -c   libpcre.la libpcreposix.la libpcrecpp.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libpcre.so.1.2.13 /usr/local/lib/libpcre.so.1.2.13
....
...
..
.
..
...
....
ln -sf pcre_utf32_to_host_byte_order.3	 /usr/local/share/man/man3/pcre32_utf32_to_host_byte_order.3
ln -sf pcre_version.3			 /usr/local/share/man/man3/pcre32_version.3
make[3]: Leaving directory `/home/xxx/utils/pcre-8.45'
make[2]: Leaving directory `/home/xxx/utils/pcre-8.45'
make[1]: Leaving directory `/home/xxx/utils/pcre-8.45'

길기 때문에, 명령어만 보도록 한다. 

 

설치가 완료되면 /usr/local/pcre 폴더가 생성이 되고 파일들이 많이 들어가져 있을 것이다.

 

- zlib 설치

 

이것도 다음의 사이트에서 다운을 받았다.

 

 

zlib Home Site

<!-- H4 ALIGN="center" IMG WIDTH=42 HEIGHT=44 ALIGN="middle" SRC="images/happyicon.png" ALT="[happy face, because it's so darned useful!]" /H4 --> A Massively Spiffy Yet Delicately Unobtrusive Compression Library (Also Free, Not to Mention Unencumbered by

zlib.net

썸네일 참 투박하다.

 

PCRE와 똑같은 방식으로 FTP 를 통해 압축파일을 전송하고, 같은 명령어로 입력하여 설치를 해주었다.

$ sudo ./configure
$ sudo make
$ sudo make install

 

- openssl 설치

 

openssl 이 버전을 확인해보니 기존에 깔려 있긴 했는데, devel 패키지가 아니어서 그런지 컴파일 할 때 필요한 라이브러리를 찾지 못하는 그지같음을 보여주어서, 버전도 낮고 하니 버전 업그레이드 해 줄 겸 같이 설치했다.

 

/source/index.html

The master sources are maintained in our git repository, which is accessible over the network and cloned on GitHub, at https://github.com/openssl/openssl. Bugs and pull patches (issues and pull requests) should be filed on the GitHub repo. Please familiari

www.openssl.org

내가 다운 받았던 버전은 1.1.1m 인가보다.

 

똑같이 FTP 로 넣어주긴 했는데, 이번에는 명령어가 좀 다르다.

$ sudo ./config
$ sudo make
$ sudo make install

./configure 가 아니라 ./config  이다.

 

내 경우는 새로 설치하는 것이 아닌, 기존의 것을 변경하는 것이기 때문에 설치 후에도 변경이 잘 되었는 지 openssl 의 버전을 확인 할 필요가 있었다.

$ openssl version

확인했는데, 설치가 덮어 씌워지는 것이 아니었는 지 원래 바라보던 그 버전이 나오는 것이었다.

 

그래서 다음과 같은 방법을 하였다.

1. 기존 파일이 있는 /usr/bin 폴더에 들어가서 openssl 의 이름을 변경한다.
2. 새로 설치한 openssl 의 위치에서 심볼릭 링크로 openssl 을 전달하도록 한다.

코드로 풀면,

$ cd /usr/bin
$ sudo mv openssl openssl.old
$ sudo ln -s /usr/local/bin/openssl /usr/bin/openssl

이렇게 되겠지. 그러고서 다시 openssl version 으로 버전을 확인하게 되면 바뀐 버전을 확인할 수 있다.

 

만약, libssl.so 와 libcrypto.so 에 대한 에러 메세지가 나온다면 다음의 사이트를 참고해보도록 한다.

 

OpenSSL 소스 컴파일 설치

#openssl version 버전 체크 #yum groupinstall "Development tools" 먼저 Development tools설치. gcc는 기본으로 설치되어 있어야 합니다. #cd /usr/local/src #wget https://www.openssl.org/source/openssl-1...

xaida.tistory.com

 

2. NGINX 설치하기

 

이제 NGINX 를 설치해보자. NGINX 설치한 버전은 NGINX 1.20.2 버전이 되겠다. 여기에서 나는 제목 따라 "베껴" 설치를 하는 것이다.

 

NGINX 도 위의 아이들과 비슷하게 ./configure 를 통해서 설치하는 것은 맞다만 단순히 그것만 치는 것이 아니라 여러 옵션들도 함께 건드려주어야 사용을 할 수 있는 것이기 때문에, NGINX 를 configure 할 때 함께 사용하는 옵션에 대한 사이트를 본다면 이걸 어떻게 써야되는가 싶다.

 

Building nginx from Sources

Building nginx from Sources The build is configured using the configure command. It defines various aspects of the system, including the methods nginx is allowed to use for connection processing. At the end it creates a Makefile. The configure command supp

nginx.org

저렇게 많은 것 중에서 무슨 옵션이 어떤 것과 관련되어있고, 이걸 허용 하지 않으면 뭐가 안되는 그런게 있을 까봐 어떻게 할까 생각하다가 테스트 서버로 사용하고 있는 곳에서 configure 를 따오는게 낫겠다 생각을 했다.

 

테스트 서버에서는 yum 으로 설치를 해서 설정된 옵션들이 있을까 했는데 다행하게도,

$ sudo nginx -V

nginx 에 -V 옵션이 configure 할 때 어떤 옵션을 사용했는 지 나타내주는 것이 있었다. 대문자 V 로 해야되며 소문자 v 는 버전 표시가 되는 사소한 점에 주의하자.

 

테스트 서버에서 쳐 본 결과 다음과 같았다.

여기에서 불 필요한 아이들을 정리한 다음 필요한 옵션만 보자면,

./configure \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=root \
--group=root \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module

이렇게나 많은 옵션들이 yum 으로 설치하게 되면 깔린다는 것이다. 여기에서 그래도 알아야 하는 주요 옵션은,

--user
> 유저명
--group
> 그룹명
--sbin-path
> nginx 실행파일이 떨궈질 곳이라고 생각하면 편하다. "nginx -명령어" 칠 수 있게 하는 그 nginx 실행 파일이다.
--conf-path
> nginx 의 서버 세팅 configure 파일의 위치를 지정한다.
--error-log-path
> nginx 를 거쳐가는 통신에서 에러가 나는 경우에 발생하는 로그 기록을 남기는 곳의 위치를 지정한다.
--http-log-path
> nginx 를 접근하는 통신에 대한 로그 기록을 남기는 곳의 위치를 지정한다.
--pid-path
> nginx 가 실행 될 때 생기는 Process ID 에 관련된 파일의 위치를 지정해주는 곳 같다. 정확히는 뭔지 모르겠다.

그 외에는 무슨 옵션이 있는지는 잘 모르겠고, 저 정도만 알아보도록 하겠다.

 

그럼 복사해온 커맨드를 앞에 sudo 만 붙여서 실행해보면, 

PCRE 라이브러리를 이곳저곳 찾는 중에 시스템에 없으니 에러를 발생시켰다. 그것 뿐만이 아니다.

OpenSSL 도 시스템에서 라이브러리가 없으면 없다고 나온다.

확인해 보니 이미 설치가 되어있어도 라이브러리 소스 파일 같은 것을 찾을 수 없으면 설치가 되지 않는 것 같았다. 그래서 미리 확인 한 후에 필요한 라이브러리를 설치하는 것이다.

 

두 에러메세지에서 제시해 준 마지막 문장에는 --with-[LIBRARY]=<path> 가 있는데, 이 값을 configure 로 길게 써 놓았던 것 마지막에 추가를 하면 되겠다. 각각,

./configure \
    ...\
    --with-pcre=../pcre-8.45
    --with-openssl=../openssl-1.1.1m

이렇게 써주면 되겠다.

 

zlib 의 경우에는 서버에 설치를 하게되면 NGINX 가 찾는 위치에 설치 되는지 시스템에서 존재한다고 인식을 하기 때문에 신경을 쓰지 않아도 되었다.

 

다시 돌린 다음에 다음 메세지가 뜨면 일단은 성공이다.

configure 에 성공한 후 차례대로 make 와 make install 을 호출하면, 별일 없이 make[1] : Leaving directory '${PATH}' 하면서 마지막 메세지를 남겨준다. 

 

NGINX 의 설정을 담당하는 conf 파일의 위치는 /etc/nginx 안에 있고, 해당 파일을 설정한 후에 브라우저를 통해서 접근해보면

연결이 잘 되었음을 확인할 수 있었다.


pcre 의 configure 를 설정해주면 pcre 도 시스템에서 발견할 수 있도록 할 수 있는 방법을 알아냈다.

$ ./configure \
    --prefix=/usr \
    --docdir=/usr/share/doc/pcre-8.45 \
    --enable-pcre16 \
    --enable-pcre32 \
    --enable-unicode-properties
반응형
Comments