[Ubuntu + Nginx1.24.0(hc) + php8.1-fpm + MariaDB] 종합(default경로) > Linux/Apm

본문 바로가기
사이트 내 전체검색

Linux/Apm

[Ubuntu + Nginx1.24.0(hc) + php8.1-fpm + MariaDB] 종합(default경로)

페이지 정보

작성자 sbLAB 댓글 0건 조회 2,239회 작성일 23-06-17 14:55

본문

1) Ubuntu22.04 + nginx-1.24.0 + nginx_upstream_check_module 컴파일 (default경로) default경로) 

※ 기존 xampp, mysql(mariaDB) 모두 삭제 후 설치시작.

※  nginx_upstream_check_module 때문에 compile 설치한 것으로, 일반적인 웹서버는 apt install nginx 로 표준 설치(certbot 호환 등 경로 문제없음 )


※  컴파일 설치인 경우에도 아래 Configuring NGINX Paths 목록 참고하여 apt install nginx  표준 설치 경로 파라미터로 컴파일 권장.

[표준 설치 경로 파라미터로 컴파일] =>  http://sebom.com/gb/bbs/board.php?bo_table=tech&wr_id=111  로 이동.


[표준설치 + ssl + auto ssl renew 설정은 아래 링크사용]

http://sebom.com/gb/bbs/board.php?bo_table=tech&wr_id=110 


 Settings  

-  Ubuntu22.04

-  nginx-1.24.0          http://nginx.org/en/download.html

-  nginx_upstream_check_module check_1.20.1+.patch (Health-Check open source) https://github.com/yaoweibin/nginx_upstream_check_module

-  ssl(libssl-dev)


※ nginx-1.24.0 버전 + ginx_upstream_check_module 은 check_1.20.1+.patch => 버전이 정확히 일치하지 않으나 아래와 같이 컴파일 설치 진행완료.

※ nginx-1.20.1 버전 + ginx_upstream_check_module 은 check_1.20.1+.patch => 컴파일 할때, 

--with-http_ssl_module  SSL모듈에서 오류 발생.(설치된 libssl-dev ssl라이브러리 최신 버전(3.0)에서 Deprecated된 함수를  nginx-1.20.1 에서 사용하려 한다는 오류)


 Compile Install  nginx-1.24.0 버전 + nginx_upstream_check_module 은 check_1.20.1+.patch

# apt update

# cd /home/myhome

# mkdir nginx

# cd nginx

# apt install git

# git clone https://github.com/yaoweibin/nginx_upstream_check_module.git

# wget 'http://nginx.org/download/nginx-1.24.0.tar.gz'

# tar -xvf nginx-1.24.0.tar.gz

# cd nginx-1.24.0   


※ 기존 check_1.20.1+.patch 패치한 nginx-1.24.0 을 그대로 사용하지 말것!  새로 tar -xvf nginx-1.24.0.tar.gz 압축해제 해서 패치 할것! 

# patch -p1 < ../nginx_upstream_check_module/check_1.20.1+.patch

--------

patching file src/http/modules/ngx_http_upstream_hash_module.c

patching file src/http/modules/ngx_http_upstream_ip_hash_module.c

patching file src/http/modules/ngx_http_upstream_least_conn_module.c

patching file src/http/ngx_http_upstream_round_robin.c

patching file src/http/ngx_http_upstream_round_robin.h

---------


# gcc --version

--------------

Command 'gcc' not found

--------------

# apt install gcc

# apt install build-essential

# apt install libpcre3-dev

# apt install zlib1g-dev

# apt install libssl-dev   // --with-http_ssl_module 에 사용될 ssl 라이브러리

-------------

※위 gcc 설치 과정에서 아래오류! libc6=2.35-0ubuntu3 버전이 필요하다는 뜻!

The following packages have unmet dependencies:

 libc6-dev : Depends: libc6 (2.35-0ubuntu3) but 2.35-0ubuntu3.1 is to be installed

-------------

# apt install libc6=2.35-0ubuntu3 


# gcc --version

-----------

gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0

-----------


Configuring NGINX Paths  - 설치경로 설정 Parameter 들 정보
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/

meterDescription
--prefix=<PATH>

Directory for NGINX files, and the base location for all relative paths set by the other 

configure scriptoptions (excluding paths to libraries) and for the path

to the nginx.conf configuration file. Default: /usr/local/nginx.

--sbin-path=<PATH>

Name of the NGINX executable file, which is used only during installation.

Default: **/sbin/nginx

--conf-path=<PATH>

Name of the NGINX configuration file.

You can, however, always override this value at startup by specifying a different file with 

the -c <FILENAME> option on the nginx command line. Default: **conf/nginx.conf

--pid-path=<PATH>

Name of the nginx.pid file, which stores the process ID of the nginx master process.

After installation, the path to the filename can be changed with the pid directive

 in the NGINX configuration file. Default: **/logs/nginx.pid

--error-log-path=<PATH>

Name of the primary log file for errors, warnings, and diagnostic data.

After installation, the filename can be changed with the error_log directive in the NGINX configuration file.

Default: **/logs/error.log

--http-log-path=<PATH>

Name of the primary log file for requests to the HTTP server. After installation,

the filename can always be changed with the access_log directive in the NGINX configuration file. 

Default: **/logs/access.log

--user=<NAME>

Name of the unprivileged user whose credentials are used by the NGINX worker processes.

After installation, the name can be changed with the user directive in the NGINX configuration file. 

Default: nobody

--group=<NAME>

Name of the group whose credentials are used by the NGINX worker processes.

After installation, the name can be changed with the user directive in the NGINX configuration file. 

Default: the value set by the --user option.

--with-pcre=<PATH>

Path to the source for the PCRE library,

which is required for regular expressions support in the location directive and the Rewrite module.

--with-pcre-jitBuilds the PCRE library with “just-in-time compilation” support (the pcre_jit directive).
--with-zlib=<PATH>Path to the source for the zlib library, which is required by the Gzip module.


// nginx_upstream_check_module Health-Check 모듈과, ssl 모듈stub_status 모듈을 적용시킴

./configure --add-module=../nginx_upstream_check_module --with-http_ssl_module --with-http_stub_status_module 


 아래 표준경로 형태 권장  

- 이글에서는 컴파일 설치를 디폴트 값으로 진행했으나, 아래 표준 경로 옵션 사용(certbot 등 다른 툴과 호환위함) 

- [표준 설치 경로 파라미터로 컴파일] =>  http://sebom.com/gb/bbs/board.php?bo_table=tech&wr_id=111  로 이동. 


./configure --add-module=../nginx_upstream_check_module --with-http_ssl_module --with-http_stub_status_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx 

------------------------------------------------------------------------------------

Configuration summary

  + using system PCRE library

  + using system OpenSSL library

  + using system zlib library


  nginx path prefix: "/etc/nginx"

  nginx binary file: "/usr/sbin/nginx"

  nginx modules path: "/etc/nginx/modules"

  nginx configuration prefix: "/etc/nginx"

  nginx configuration file: "/etc/nginx/nginx.conf"

  nginx pid file: "/run/nginx.pid"

  nginx error log file: "/var/log/nginx/error.log"

  nginx http access log file: "/var/log/nginx/access.log"

  nginx http client request body temporary files: "client_body_temp"

  nginx http proxy temporary files: "proxy_temp"

  nginx http fastcgi temporary files: "fastcgi_temp"

  nginx http uwsgi temporary files: "uwsgi_temp"

  nginx http scgi temporary files: "scgi_temp"

------------------------------------------------------------------------------------


# make 

# make install


# cd /usr/local/nginx/sbin

# ./nginx

---------------------------------------

nginx -s stop 정지

nginx -s reload 재시작

nginx -t 설정파일 체크

/usr/local/nginx/conf 메인설정파일 위치

-----------------------------------------


/etc/systemd/system/nginx.service 파일 생성 

--------------------------------------------------------

[Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network-online.target remote-fs.target nss-lookup.target


[Service] 

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPost=/bin/sleep 1

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true


[Install]

WantedBy=multi-user.target

----------------------------------------------------

[자동시작 등록]

systemctl enable nginx.service  

/etc/systemd/system/multi-user.target.wants/ 안에 nginx.service -> /etc/systemd/system/nginx.service 심볼릭 링크 생성됨 

systemctl start nginx 
systemctl stop nginx
systemctl status nginx
systemctl restart nginx


[nginx 루트 html 확인]

/usr/local/nginx/html


[nginx 사용자 추가]

# useradd --shell /usr/sbin/nologin --home-dir /usr/local/nginx/html nginx


# cat /etc/passwd

nginx:x:1001:1001::/usr/local/nginx/html:/usr/sbin/nologin


# cd /usr/local/nginx/

# chown nginx:nginx html -R


[웹서버 용도 기본  nginx.conf 설정]

# nano /usr/local/nginx/conf/nginx.conf

--------------------------------------------------------
user  nginx; 

worker_processes  auto;

pid     /usr/local/nginx/logs/nginx.pid;


events {

    worker_connections  1024;

}

http { 

    include       mime.types;

    default_type  application/octet-stream;    

    sendfile        on;


    server {

        listen       80;

        server_name  *.mysite.kr;


        location / {

            root   html;

            index  index.html index.htm index.php;

        }

        location /nginx_status {

          stub_status;

        }

       # redirect server error pages to the static page /epage/***.html     

      error_page  404              /epage/404.html;

      error_page  403              /epage/403.html;

      error_page  500 502 503 504  /epage/50x.html;


        #*.php-fpm

        location ~ \.php$ {

                try_files $uri =404;

                include fastcgi.conf;

                include fastcgi_params;

                fastcgi_index index.php;

                fastcgi_pass unix:/run/php/php8.1-fpm.sock;

               

    }

}

---------------------------------------------------------


 2) PHP8.1-FPM  세팅 


[php-fpm 설치] 

# apt install php-fpm

# php -v

# apt install php8.1-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}

# php -m


# ps -ef | grep nginx

-----------------------

root       28869       1  0 20:35 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

www-data   28870   28869  0 20:35 ?        00:00:00 nginx: worker process

www-data   28871   28869  0 20:35 ?        00:00:00 nginx: worker process

root       29499    3044  0 20:59 pts/1    00:00:00 grep --color=auto nginx

------------------------


[경로확인]

/etc/php/8.1/fpm/php.ini    <-- php.ini 

/usr/local/nginx/conf/nginx.conf  <= nginx.conf 


/run/php/php8.1-fpm.sock     <= php8.1-fpm.sock 경로

/etc/php/8.1/fpm/  <= php-fpm.conf  php.ini 경로

/etc/php/8.1/fpm/pool.d/www.conf <= www.conf


# nano /etc/php/8.1/fpm/pool.d/www.conf 설정 

------------------------------------------------

user = nginx

group = nginx

...
listen = /run/php/php8.1-fpm.sock
...
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
------------------------------------------------

 3) Mariadb DB세팅  


# apt install mariadb-server mariadb-client php-mysql


[경로정보]

/var/lib/mysql      <--- mysql data 디렉토리 경로

/etc/mysql/my.cnf  <---  mysql 설정파일들

/usr/bin              <---  mysql ... mysqldump ....


# mysql_secure_installation

------------------------------

root 의 현재 비밀번호 입력(없으면 입력): root 비밀번호입력

root  암호를 설정하시겠습니까? [Y/n] y

익명 사용자를 제거하시겠습니까? [Y/n] y

원격으로 root 로그인을 허용하지 않습니까? [Y/n] n   

테스트 데이터베이스를 제거하고 액세스하시겠습니까? [Y/n] n

지금 권한 테이블을 다시 로드하시겠습니까? [Y/n] y

---------------------------------


※ 리눅스 root 계정인 경우는 mysql 또는 mysql -root 만으로 mysql 접속됨.

※ 리눅스 일반유저 계정은 mysql -uroot -p루트비밀번호 입력해야 접속가능.


# apt install phpmyadmin      


# find / -name phpmyadmin

--------------------------

/usr/share/phpmyadmin <--- 설치경로 확인

--------------------------


[nginx 웹루트 /usr/local/nginx/html/ 아래에 심볼릭링크 생성]

# ln -s /usr/share/phpmyadmin /usr/local/nginx/html/phpmyadmin


http://192.168.0.9/phpmyadmin 으로 웹접속 가능


[phpmyadmin 웹접속시 경고 표시 처리] 

※(cat /etc/passwd) nginx:x:1002:1003::/usr/local/nginx/html:/usr/sbin/nologin

※ /usr/local/nginx/conf/nginx.conf 설정에서 user nginx; 이므로, nginx 로 변경해주는 것이 요점.


1) TempDir(tmp) 경고표시

2) 암호화 문자열(blowfish_secret)을 필요 경고표시


[해결]

# cd /var/lib/phpmyadmin/

# ll

-----------------

-rw-r-----  1 root     www-data   68  6월 17 13:12 blowfish_secret.inc.php 

drwxr-xr-x  2 www-data www-data 4096  1월 21  2022 tmp/

-----------------

# chown nginx:nginx tmp -R   <- tmp 디렉토리와 그 아래 파일까지 모두 nginx 유저:그룹으로 변경해줌(OK) 

# chown nginx:nginx blowfish_secret.inc.php   <- nginx 유저:그룹으로 변경해줌(OK) 


#ll

----------------

-rw-r-----  1 nginx nginx   68  6월 17 13:12 blowfish_secret.inc.php 

drwxr-xr-x  3 nginx nginx 4096  6월 17 14:26 tmp/

----------------


#reboot 해도 mysql / php8.1-fpm 서비스 자동 시작 됨(apt 설치 할때 service에 자동 등록됨)

php8.1-fpm.service / mariadb.service  --->  /usr/lib/systemd/system/ 아래에 설치 시 service 파일 생성 및 자동 시작에 등록되어 있음

nginx.service  --->  /etc/systemd/system/nginx.service 경로에 수동으로 생성했음.


그러나, nginx 서비스가 정상 작동 하지 않음, 아래처럼 원인 확인 -> 80 포트를 다른 서비스가 사용 중이라는 이유


# systemctl status nginx

------------------------------------

nginx[2340]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

-------------------------------------


# netstat -ntlp | grep  80

---------------------------------------------------------------------------------------------

tcp6       0      0 :::80                   :::*                    LISTEN      750/apache2

----------------------------------------------------------------------------------------------


[패키지 설치 중에 apache2가 함께 설치되거나, 리눅스에 기본 설치된 경우가 있음]


# apt stop apache2

# apt remove apache2

# systemctl disable apache2

/etc/systemd/system 아래 *.service 서비스들 위치함


# systemctl status nginx

--------------------------

nginx.service: Failed to parse PID from file /usr/local/nginx/logs/nginx.pid: Invalid argument

--------------------------


# nano /etc/systemd/system/nginx.service

----------------------------------------

PIDFile=/usr/local/nginx/logs/nginx.pid

----------------------------------------


# nano /usr/local/nginx/conf/nginx.conf

----------------------------------------

pid     /usr/local/nginx/logs/nginx.pid;

----------------------------------------


※ 위와 같이 일치하는지 확인


# systemctl restart nginx

----------------------------

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


그러나, systemctl status nginx 에서 Invalid argument 경고 표시가 불규칙적으로 나타남.

----------------------------


[원인설명]

1) 무시해도 됨

This is simply a case of nginx and systemd competing for resources. 

This warning is harmless since systemd only uses the PIDFile option to remove PIDFile after the nginx service terminates.


2) 

The workaround is to add the following line to /etc/systemd/system/nginx.service

ExecStartPost=/bin/sleep 1


[위 2)방법 적용 - ExecStartPost=/bin/sleep 1 추가] <- 위  nginx  설치 단계에서 이미 추가해 놓음.(없다면 아래처럼 추가)

# nano /etc/systemd/system/nginx.service

--------------------------------------------------------------

Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network-online.target remote-fs.target nss-lookup.target


[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPost=/bin/sleep 1

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true


[Install]

WantedBy=multi-user.target

------------------------------------------------------------


# systemctl daemon-reload

# systemctl stop nginx

# systemctl restart nginx


# systemctl status nginx

----------------------------

nginx[1774]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 

systemd[1]: Started The NGINX HTTP and reverse proxy server. 

----------------------------


모니터링 --with-http_stub_status_module  (위 컴파일 할때 포함 시킴 + nginx.conf 에서 nginx_status 설정함)

https://mysite.kr/nginx_status 


[opcache + jit 활성화]

#nano /etc/php/8.1/fpm/php.ini 

-----------------------------------

zend_extension=opcache

[opcache]

opcache.enable=1

opcache.jit_buffer_size=100M

opcache.jit=tracing


opcache.enable_cli=1

opcache.validate_timestamps=1

opcache.revalidate_freq=20

----------------------------------


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
74
어제
401
최대
1,279
전체
221,728

그누보드5
Copyright © sebom.com All rights reserved.