NGINX Service Unavailable

LINUX 2017. 7. 5. 17:22

NGINX Service Unavailable



엔진엑스는 아래와 같은 에러가 자주 발생하는 듯 하네요~


아파치만 사용하다 nginx 는 아직 적응이 안되는군요~


Service Unavailable


The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.



이런 경우엔 nginx 재시작 해주면 됩니다.



# systemctl restart php-fpm

# systemctl restart nginx


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

MariaDB open_files_limit 값 변경하기



CentOS 7.x 버전에서 아래처럼 명령어로도 open_files_limit 변경이 안되는 문제가 있습니다.


set global open_files_limit = 10000

#1238 Variable 'open_files_limit' is a read only variable



먼저 /etc/security/limits.conf 에 아래 내용을 추가합니다.


*                -       nofile          65536

또는

*                hard    nofile          65536

*                soft    nofile          65536


저장 후에 재부팅 또는 재접속을 합니다.

아니면 임시로 # ulimit -n 65536 명령어를 실행합니다.


# ulimit -Hn -Sn

open files                      (-n) 65536

open files                      (-n) 65536


위 처럼 값이 변경되었는지 확인 후 다음으로 넘어갑니다.


/etc/systemd/system/multi-user.target.wants/mariadb.service 파일에 아래 내용을 추가합니다.


[Service]

LimitNOFILE=10000


LimitNOFILE=infinity 로 설정하면 ulimit 의 값을 따라갑니다.


systemd 를 reload 후 mariadb 를 재시작 하면 됩니다.


# systemctl daemon-reload

# systemctl restart mariadb


이제 open_files_limit 값을 확인해보세요~



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x Apache + MariaDB + PHP 설치 쉘스크립트



리눅스 VPS 개설 후 매번 LAMP 설치가 귀찮아서 한번 만들어보았습니다.


#!/bin/sh


if [ `rpm -qa | grep httpd | wc -l` = 0 ] ; then

yum -y install httpd mariadb mariadb-server php php-common php-devel php-fpm php-gd php-mbstring php-mysql

fi


if [ `cat /etc/my.cnf | grep "set names utf8" | wc -l` = 0 ] ; then

echo "[mysqld]" >> /etc/my.cnf

echo "init_connect='set names utf8'" >> /etc/my.cnf

echo "character-set-server=utf8" >> /etc/my.cnf

echo "max_connections=1000" >> /etc/my.cnf

echo "log_slow_queries = On" >> /etc/my.cnf

echo "long_query_time = 5" >> /etc/my.cnf

echo "join_buffer_size = 16MB" >> /etc/my.cnf

echo "key_buffer_size = 8MB" >> /etc/my.cnf

echo "read_rnd_buffer_size = 32MB" >> /etc/my.cnf

echo "sort_buffer_size = 32MB" >> /etc/my.cnf

echo "query_cache_limit = 256KB" >> /etc/my.cnf

echo "query_cache_min_res_unit = 4096" >> /etc/my.cnf

echo "query_cache_size = 16MB" >> /etc/my.cnf

echo "thread_cache_size = 8" >> /etc/my.cnf

echo "table_open_cache = 16384" >> /etc/my.cnf

echo "max_heap_table_size = 256MB" >> /etc/my.cnf

echo "tmp_table_size = 256MB" >> /etc/my.cnf

echo "[Service]" >> /etc/systemd/system/multi-user.target.wants/mariadb.service

echo "LimitNOFILE=32768" >> /etc/systemd/system/multi-user.target.wants/mariadb.service

fi


if [ `cat /etc/php.ini | grep "short_open_tag = On" | wc -l` = 0 ] ; then

sed -i 's/^short_open_tag\ =\ Off/short_open_tag\ =\ On/g' /etc/php.ini

sed -i 's/^allow_url_fopen\ =\ On/allow_url_fopen\ =\ Off/g' /etc/php.ini

sed -i 's/^post_max_size\ =\ 8M/post_max_size\ =\ 32M/g' /etc/php.ini

sed -i 's/^upload_max_filesize\ =\ 2M/upload_max_filesize\ =\ 5M/g' /etc/php.ini

sed -i 's/^;date.timezone\ =/date.timezone\ =\ Asia\/Seoul/g' /etc/php.ini

sed -i 's/^session.gc_maxlifetime\ =\ 1440/session.gc_maxlifetime\ =\ 43200/g' /etc/php.ini

fi

if [ `cat /etc/httpd/conf.d/php.conf | grep "^AddType application/x-httpd-php" | wc -l` = 0 ] ; then

sed -i 's/^AddType\ text\/html\ .php/AddType\ text\/html\ .php\nAddType\ application\/x-httpd-php\ .htm\ .html\ .php\ .php3\ .php4\ .inc/g' /etc/httpd/conf.d/php.conf

fi


systemctl enable httpd.service

systemctl enable mariadb.service

systemctl start httpd.service

systemctl start mariadb.service

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

mysql_secure_installation


my.cnf 튜닝은 환경에 따라 다르게 설정되어야 합니다.


그리고 php.ini 환경 설정도 개인 마다 다를 수 있으니 참고하시면 됩니다.


CentOS-7.x-LAMP-install.sh.txt


'LINUX' 카테고리의 다른 글

NGINX Service Unavailable  (0) 2017.07.05
MariaDB open_files_limit 값 변경하기  (0) 2017.07.05
리눅스 아파치 로그 IP 정렬방법  (0) 2017.07.03
아파치 BLEXBot 차단하기  (0) 2017.06.26
NGINX phpMyAdmin 연결  (0) 2017.06.26
블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 아파치 로그 IP 정렬방법



아파치 로그를 분석할 때 중복된 아이피는 거르고 아이피를 소트해서 보고 싶을 때가 있지요?



▶ 아이피만 뽑아내기


cat /var/log/httpd/www.example.com | awk '{print $2}'


이렇게 하면 아이피 정보가 스페이스바 기준으로 두번째 필드에 있으므로 아이피만 가져오게 됩니다.


awk 뒤에 옵션이 없으면 스페이스바를 기준으로 split 을 합니다.


awk -F ' ' 와 동일합니다.



▶ 아이피를 정렬하기


cat /var/log/httpd/www.example.com-access_log | awk '{print $2}' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4


그냥 sort 만 하면 이상하게 소팅이 됩니다.


sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 아이피를 정렬하는 방법입니다.


-n : --numeric-sort


-t : --field-separator


-k : --key=POS1,POS2



▶ 아이피 정렬 후 중복제거


cat /var/log/httpd/www.example.com-access_log | awk '{print $2}' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq


이제 원하는 결과값을 볼 수 있을겁니다.


여기서 카운트를 할려면 wc -l 을 더 붙여주면 됩니다.


'LINUX' 카테고리의 다른 글

MariaDB open_files_limit 값 변경하기  (0) 2017.07.05
CentOS 7.x Apache + MariaDB + PHP 설치 쉘스크립트  (0) 2017.07.05
아파치 BLEXBot 차단하기  (0) 2017.06.26
NGINX phpMyAdmin 연결  (0) 2017.06.26
NGINX https Redirect 방법  (0) 2017.06.23
블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

아파치 BLEXBot 차단하기



Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)


위의 유저에이전트로 너무 많은 로그가 발생해서 확인을 해봤습니다.



[root@vps httpd]# cat www.example.com-access_log | grep "136.243.36.84" | wc -l

36819

[root@vps httpd]# cat www.example.com-access_log | wc -l

100993

[root@vps httpd]# cat www.example.com-error_log | grep "136.243.36.84" | wc -l

9465

[root@vps httpd]# cat www.example.com-error_log | wc -l

14270


access_log 에서 1/3 넘게 error_log 에서는 절반 넘게 차지하는군요~


뭐하는 사이트인지를 모르겠지만 트래픽 부담이 만만치 않는 것 같습니다.


방화벽에서 차단하기 전에 크롤러니깐 robots.txt 에 아래 내용을 추가해 보았습니다.


User-agent: BLEXBot

Disallow: /


위 내용을 저장하고 얼마 지나지 않아서 robots.txt 파일을 긁어 가더니 그 뒤로는 크롤링을 하지 않는군요~


그래도 말을 잘 듣는 로봇인가봅니다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

NGINX phpMyAdmin 연결

LINUX 2017. 6. 26. 09:34

NGINX phpMyAdmin 연결



아파치에서는 설치하면 자동으로 Alias 로 연결이 되었습니다.


nginx 는 Alias 대신에 심볼릭 링크를 걸어주면 잘 작동 하는군요~



server {

    listen       80;

    server_name  www.example.com;

    root         /var/www/html;

}


nginx 환경설정에 root 폴더가 /var/www/html 이라면


# ln -s /usr/share/phpMyAdmin /var/www/html/phpmyadmin


이렇게 심볼릭링크를 걸어주고 웹브라우저에서 http://www.example.com/phpmyadmin 으로 접속을 하면 됩니다.


'LINUX' 카테고리의 다른 글

리눅스 아파치 로그 IP 정렬방법  (0) 2017.07.03
아파치 BLEXBot 차단하기  (0) 2017.06.26
NGINX https Redirect 방법  (0) 2017.06.23
NGINX 확장자 html 에서도 php 동작되도록  (0) 2017.06.23
CentOS 원격백업 rsnapshot  (0) 2017.06.22
블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

NGINX https Redirect 방법

LINUX 2017. 6. 23. 17:14

NGINX https Redirect 방법



아파치에서는 아래처럼 .htaccess 에서 80 포트로 오면 443 으로 리디렉션을 시켜줄 수가 있습니다.


RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]



이것을 nginx 에서 설정하는 방법입니다.


server {
    listen       80;
    server_name  www.example.com;
    root         /var/www/html;

    location / {
        index    index.html index.htm index.php;
        return 301 https:$host$request_uri;
    }
}


이제 엔진엑스를 재시작하고 확인하면 됩니다.


'LINUX' 카테고리의 다른 글

아파치 BLEXBot 차단하기  (0) 2017.06.26
NGINX phpMyAdmin 연결  (0) 2017.06.26
NGINX 확장자 html 에서도 php 동작되도록  (0) 2017.06.23
CentOS 원격백업 rsnapshot  (0) 2017.06.22
ssh-copy-id 에러시 키 복사 방법  (0) 2017.06.22
블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

NGINX 확장자 html 에서도 php 동작되도록



엔진엑스 설정만으로는 index.html 파일에서 php 가 작동이 안됩니다.


html 에서도 동작이 되도록 하려면 아래 처럼 설정하면 됩니다.



▶ /etc/php-fpm.d/www.conf 수정


security.limit_extensions = .php .php3 .php4 .php5 .htm .html


위 부분을 찾아서 주석을 해제하고 .htm .html 을 추가하고 저장합니다.


# systemctl restart php-fpm



▶ /etc/nginx/conf.d/www.example.com.conf 엔진엑스 설정


server {

    listen       80;

    server_name  www.example.com;

    root         /var/www/html;


    location / {

        index    index.html index.htm index.php;

    }


    location ~ [^/]\.(php|htm|html)(/|$) {

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_index index.html;

        fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;

        include       fastcgi_params;

    }

}


server {

    listen       443;

    server_name  www.example.com;

    root         /var/www/html;


    ssl on;

    ssl_certificate /etc/letsencrypt/live/www.example.com/cert.pem;

    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;


    location / {

        index    index.html index.htm index.php;

    }


    location ~ [^/]\.(php|htm|html)(/|$) {

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_index index.html;

        fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;

        include       fastcgi_params;

    }

}


# systemctl restart nginx


이제 잘 되는지 확인하시면 됩니다.


'LINUX' 카테고리의 다른 글

NGINX phpMyAdmin 연결  (0) 2017.06.26
NGINX https Redirect 방법  (0) 2017.06.23
CentOS 원격백업 rsnapshot  (0) 2017.06.22
ssh-copy-id 에러시 키 복사 방법  (0) 2017.06.22
리눅스 VPS 스왑 용량 변경하기  (0) 2017.06.21
블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 원격백업 rsnapshot



rsnapshot 으로 원격지의 서버를 백업할 수가 있습니다.


ssh 와 rsync 를 사용하는 것이기 때문에 rsync 로 쉘스크립트를 짜서 원격 백업해도 상관이 없습니다.


rsnapshot 이라는 유틸로도 백업이 가능하다는 것입니다.


단점이 있다면 대용량 백업인 경우에 몇일 이상 분량의 백업데이터를 받을려면 원격지 서버의 디스크 용량 보다 백업 서버의 용량이 몇 배는 더 커야 한다는 점입니다.



▶ ssh key 복사


# ssh-keygen

# ssh-copy-id root@192.168.1.100


원격지 서버에 ssh key 를 미리 넣어 놓아야 ssh 접속시 비밀번호를 묻지 않습니다.



▶ rsnapshot 설치


# yum install rsnapshot



▶ rsnapshot 설정 ( /etc/rsnapshot.conf 수정 )


아래 설정에서 구분은 공백이 아닌 탭으로 하여야 합니다.


snapshot_root   /.snapshots/

cmd_ssh /usr/bin/ssh

ssh_args -p 22

rsync_long_args --delete --bwlimit=3840

retain daily 7

backup  root@192.168.1.100:/home/      192.168.1.100/home/

backup  root@192.168.1.100:/etc/       192.168.1.100/etc/


snapshot_root : 백업되는 경로입니다. 적절하게 수정하여 주면 됩니다.

cmd_ssh : ssh 파일의 경로를 넣어줍니다.

ssh_args : ssh 포트가 22 번이 아니라면 지정합니다.

rsync_long_args : rsync 옵션을 나열합니다.

retain : 백업 주기를 알리는 옵션입니다. 뒤에 숫자는 해당 카운트가 되면 이전 백업을 삭제하여 줍니다.

예를 들어 houly, daily, weekly, monthly 이렇게 사용할 수 있습니다.

단순히 알아먹게 하기위한 단어입니다.

실제 구현은 크론으로 설정하여 백업되게 하여야 합니다.

backup : 백업할 디렉토리를 정의합니다.



▶ rsnapshot 설정 테스트


# rsnapshot configtest

Syntax OK


Syntax OK 가 나오면 정상입니다.

Error 가 나오면 메시지를 보고 수정해 주어야 합니다.



▶ rsnapshot 테스트


# rsnapshot -t daily

echo 1704 > /var/run/rsnapshot.pid

mkdir -m 0700 -p /.snapshots/


실제 백업하는게 아닙니다.

크론탭에 등록하기 전에 한번 테스트해보세요.



▶ cron 등록 ( /etc/cron.d/rsnapshot 생성 )


00 03 * * * root /usr/bin/rsnapshot daily


매일 새벽3시에 rsnapshot 을 실행합니다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

ssh-copy-id 에러시 키 복사 방법



아래와 같은 에러가 나는 경우에 ssh key 를 원격지에 복사하는 방법입니다.


# ssh-copy-id root@192.168.1.100

Pseudo-terminal will not be allocated because stdin is not a terminal.

ssh: Could not resolve hostname exec sh -c 'cd; umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys && (test -x /sbi: Name or service not known



▶ cat & ssh 로 복사


# cat .ssh/id_rsa.pub | ssh root@192.168.1.100 "cat >> ~/.ssh/authorized_keys"



원격지에 authorized_keys 파일이 아직 없는 경우에는 아래처럼 하면 됩니다.


# cat .ssh/id_rsa.pub | ssh root@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"



▶ scp 로 복사


# scp .ssh/id_rsa.pub root@192.168.1.100:~/.ssh/authorized_keys


scp 로 복사를 할 수도 있겠지만 authoirized_keys 파일이 있다면 다른 파일 명으로 복사한 다음에 원격지에서 cat 로 추가하여 주면 됩니다.



ssh 포트가 default 22 번이 아니라면 ssh, ssh-copy-id 는 -p포트번호 를 추가하여 주면 됩니다.


scp 는 -P포트번호 입니다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,