※[Ubuntu + Nginx1.24.0(hc) + php8.1-fpm + MariaDB] 종합(표준경로설치) > Linux/Apm

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

Linux/Apm

※[Ubuntu + Nginx1.24.0(hc) + php8.1-fpm + MariaDB] 종합(표준경로설치)

페이지 정보

작성자 sbLAB 댓글 0건 조회 1,764회 작성일 23-06-21 22:30

본문

1) Ubuntu22.04 + nginx-1.24.0 + nginx_upstream_check_module 컴파일 설치(표준경로) 


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

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

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


[표준설치 + 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.


 아래 표준경로 형태 권장  

- 아래 표준 경로 옵션 사용(certbot 등 다른 툴과 호환위함)

./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


[방화벽 80, 443 허용]

# ufw enable

ufw status

ufw allow 80

ufw allow 443


[nginx 웹루트 html 경로 생성]  <--- 위 과정 설치 시 /etc/nginx/html 로 웹루트가 생성되어 있음.

/var/www/html


[nginx 사용자 추가]

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


# cat /etc/passwd

nginx:x:1001:1001::/var/www/html:/usr/sbin/nologin


# cd /var/www

# chown nginx:nginx html -R


# cd /etc/nginx/html  <--- 위 과정 설치 시 /etc/nginx/html 로 웹루트가 생성되어 있음. 

cp * /var/www/html/  <--- 웹루트로 사용할 /var/www/html/ 아래에 웹페이지들 복사



/etc/nginx/nginx.conf 메인설정파일에  root /var/www/html;  선언


user  nginx;
worker_processes  auto;
pid   /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  mysite.kr www.mysite.kr;
        root /var/www/html;

        location / {
            index  index.html index.htm;
        }
    }
}
 


# cd /usr/sbin

# ./nginx

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

nginx -s stop 정지

nginx -s reload 재시작

nginx -t 설정파일 체크

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


/usr/lib/systemd/system/nginx.service 파일 생성 

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

[Unit]

Description=A high performance web server and a reverse proxy server

Documentation=man:nginx(8)

After=network.target nss-lookup.target


[Service]

Type=forking

PIDFile=/run/nginx.pid

ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'

ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'

ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload

ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid

TimeoutStopSec=5

KillMode=mixed


[Install]

WantedBy=multi-user.target

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

# systemctl daemon-reload 


[자동시작 등록]

systemctl enable nginx.service  

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

service nginx strop
service nginx start
service nginx reload
service nginx restart
service nginx status 


[웹서버 예시 nginx.conf 설정] 

# nano /etc/nginx/nginx.conf

   
    user  nginx;
    worker_processes  auto;
    pid   /run/nginx.pid;
    events {
        worker_connections  1024;
    }

    http {
        include       mime.types;
        default_type  application/octet-stream;    
        sendfile        on;

        server {
            listen       80;
            server_name  mysite.kr www.mysite.kr;
            root /var/www/html;

            location / {
                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        4935       1  0 17:36 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

nginx       4936    4935  0 17:36 ?        00:00:00 nginx: worker process

nginx       4937    4935  0 17:36 ?        00:00:00 nginx: worker process

root        4948    2651  0 17:41 pts/1    00:00:00 grep --color=auto nginx

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


[경로확인]

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

/etc/nginx/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
------------------------------------------------

※ systemctl restart php8.1-fpm

 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 /var/www/html/phpmyadmin


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


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

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

※ /etc/nginx/nginx.conf 설정에서 user 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  --->   /usr/lib/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 서비스들 위치함


/usr/lib/systemd/system/nginx.service  <- nginx.service 파일 위치


# service nginx status 


service nginx restart


모니터링 --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

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


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
392
어제
482
최대
1,279
전체
221,645

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