[linux]apache 실행 실패 - 오류 No space left .. 관련

apache 웹서버가 죽었다.......

콘솔에서 상태 확인 후 재시작을 했는데도 안된다....

 

apache 재작시 아래와 같은 메세지가 나왔다.

[~]# service httpd status
httpd is stopped
[~]# service httpd start
Starting httpd:                                            [FAILED]
[~]# service httpd stop
Stopping httpd:                                            [  OK  ]
[~]# service httpd status
httpd is stopped

 

오류 내용으로 구글 검색을 해보니,

여러 경우에 대한 내용이 나왔고, 

그 중 웹로그 error log도 확인을 해보라는 내용이 있어 확인 해보니, 

 

[~]# cat /var/log/httpd/error_log
[Mon Apr 15 10:31:29 2024] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Apr 15 10:31:29 2024] [error] (28)No space left on device: Cannot create SSLMutex
Configuration Failed

 

언젠가 한번 본 듯 한 오류 내용 이긴 한 거 같은데....

apache 웹서버 재시작(restart)가 안된다 | 써브 개발 (tistory.com)

 

저 때도 그랬는데.. 그걸 까먹고 해매네.... 

암튼, 

이렇게 No space left .... 와 같은 오류가 발생 하면서 apache(httpd) 실행에 실패 할 때
semaphore 관련 설정을 확인해 본다.

 

//현재 설정 확인
[~]# ipcs -ls

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

[~]# cat /proc/sys/kernel/sem
250     32000   32      128


#현재 사용량 확인
[~]# ipcs -us

------ Semaphore Status --------
used arrays = 134
allocated semaphores = 134

설정값 128 보다 현재 사용량 134로 초과 되어 사용중으로 이런 경우 apache 재시작시 "No space .... " 관련 오류가 발생하게 된다.

해결 하기 위해서
"max number of arrays = 128"  값을 늘려 준다.

해당 설정은 "/etc/sysctl.conf"에서 적용해 준다.
kernel.sem = 250 32000 32 256

 

위 설정값중 맨 뒤 값을 수정해 주면 된다. 너무 크면 서버에 부담이 될 수 있으니, 적당히 올려 주고 모니터링을 해보는게 좋겠다.


설정 변경후 "/etc/sysctl.conf" 재적용 해준다.
[~]# sysctl -p

이후 apach 서비스를 다시 시작해준다.

[~]# service httpd start

 

 

 

 

 

rsync failed to connect 발생시 확인

rsync를 이용해서 백업 스케줄을 진행하고 있는 상태에서 

로그를 확인해보니, 일부 스케줄에 오류가 있었다.

 

로그는 아래와 같았다.

 

[root@svr151 rsync]# tail rsync_123_daara.log-20240411
2024/04/11 00:00:01 [21879] rsync: failed to connect to 192.168.0.123: Connection refused (111)
2024/04/11 00:00:01 [21879] rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.6]

위와 같은 오류 발생시 source 서버쪽에 rsyncd 데몬이 실행되고 있는지 확인 필요하다
[root@svr123 ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

#systemctl start rsyncd
실행시켜 준다

 

apache ssl 적용할때 mod_ssl.so 관련 에러 이슈

아파치(apache) 웹서버에서 ssl 설정을 하려고 할 때,

vhost 설정후 httpd -t 로 syntax 테스트를 해보면 오류 메세지가 나올때가 있다.

 

[root@ㅁㅁ]# httpd -t
httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 12 of /etc/httpd/conf.d/ssl.conf: Cannot load /etc/httpd/modules/mod_ssl.so into server: /etc/httpd/modules/mod_ssl.so: cannot open shared object file: No such file or directory
[root@ㅁㅁ]# whereis mod_ssl.so
mod_ssl:
[root@ㅁㅁ]# which mod_ssl.so
/usr/bin/which: no mod_ssl.so in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@ㅁㅁ]# vi /etc/httpd/conf/httpd.conf
[root@ㅁㅁ]# httpd -l
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c

 

mod_ssl.so 를 찾아봐도 안나오고, 이럴땐 mod_ssl을 설치해줘야 한다.

 

[root@ㅁㅁ]#yum install mod_ssl

 

이후 ssl vhost 설정해주고, httpd -t 로 syntax 체크해 보고, 이상 없으면, apache restart 해주면 된다.

 

mod_so.c 와 mod_ssl.so 모두 있어야 ssl설정 가능함
없으면 yum으로 설치
#yum install mod_ssl

letsencrypt wildcard 인증서 자동 갱신 실패 이슈

letsencrypt wildcard 인증서 자동 갱신 실패 이슈

멀티 서브 도메인의 ssl인증서를 한번에 적용하는 인증서가 wildcard(*) 인증서다.
유료로 신청해서 사용할 수 있지만, 무료 letsencrypt 로도 발급 받을 수 있다.
다만, wildcard 인증서는 자동 갱신시 오류가 발생된다.


#certbot renew
Processing /etc/letsencrypt/renewal/aaabbb.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)
Failed to renew certificate bizdaara.com with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)

certbot renew 를 실행해보면, "--manual-auth-hook" 로 발급 받은 경우 동일하게 다시 발급해야 한다고 한다.
이건, --manual-auth-hook 로 발급 받을때 DNS에 txt 레코드를 추가 하는 과정이 다시 필요해서 그렇다고 한다.
즉, letsencrypt의 wildcard 인증서는 재발급시 DNS txt레코드도 새로 발급되어 DNS에 새로 등록 해줘야 하는 과정이 필요한데..
자동 갱신에선 이걸 해주지 못하니, 수동으로 발급을 해줘야 한다는 거다.

아쉽지만, 공짜 wildcard 인증서를 사용하려면, 3개월 마다 수동으로 갱신을 해줘야 한다.

또 새로운걸 알아가네~~

letsencrypt 와일드카드(Wildcard) 인증서 생성하기

우선 와일드카드(Wildcard) 인증서가 뭔지 보자.

구글에서 "와일드카드 인증서"라고 검색해보면 아래와 같은 내용이 나온다.

와일드카드(Wildcard) 인증서란, 도메인(FQDN) 의 하위 서브 도메인 호스트에 대해서 무제한 적용할수 있는 SSL 인증서 타입 입니다. 최근에 SSL 인증서 발급 약 40% 선이 Wildcard SSL 인증서로 발급이 되고 있으며, 이는 그만큼 효용성이 높다는 것을 증명합니다.

 

이 와일드카드 인증서를 생성하기 위해서는 SSL인증서 발급기관에 의뢰하게 되면 대충 10만원 이상의 비용이 발생한다.

하지만, letsencrypt를 이용하면 무료로 발급할 수 있다.

다만, 3개월에 한번씩 갱신해줘야 하는 단점이 있지만.. 이도 자동으로 갱신 설정을 해놓으면 된다.

 

이제 letsencrypt 로 와일드카드 인증서 생성을 하는 과정을 보자.

 

생성하고자 하는 도메인을 "abcd.com" 이라고 하자.

여기에 *.abcd.com 을 운영을 위해 와일드카드(wildcard) SSL 인증서를 만들어 보자.

[root@svr ~]# certbot certonly --manual --preferred-challenges dns -d "*.abcd.com" -d "abcd.com"

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/abcd.com.conf)

It contains these names: abcd.com

You requested these names for the new certificate: *.abcd.com,
abcd.com.

Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: E
Renewing an existing certificate for *.abcd.com and abcd.com
Performing the following challenges:
dns-01 challenge for abcd.com
dns-01 challenge for abcd.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.abcd.com with the following value:

0l5sfzMfdL7gpoQaEbssassdfaIMqWNdf0o4drAZmmQasdfR9Smd

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

위에서 확인된 DNS TXT값을 도메인관리 기관에서 해당 도메인의 TXT값으로 추가해준다.

호스트값 : _acme-challenge 

값 : 0l5sfzMfdL7gpoQaEbssassdfaIMqWNdf0o4drAZmmQasdfR9Smd

 

위 두개 값으로 dns관리에 추가해준다. 추가 dns에 적용이 된 후 이후 작업을 해야 하니,

아래 url에서 dns txt가 적용이 되었는지 확인을 해본다.
https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.domain.com
위 페이지에 접속해 조회할 도메인 정보를 입력하고 TXT 결과값을 확인해본다.
txt 결과값이 나오면 인증서 신청 화면에서 엔터를 치고,

두번째 TXT값을 확인한다.

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.abcd.com with the following value:

8aOhySsbHUSKTsdfnDa9qwOstslSjlewLRjNx10cpsRqqaW

Before continuing, verify the record is deployed.
(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue


첫번째 TXT값과 동일한 등록 작업을 하고, dns txt값이 잘 나오는지 확인한 후 에 엔터를 친다.



IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/abcd.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/abcd.com/privkey.pem
   Your certificate will expire on 2024-03-11. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

letsencrypt wildcard 인증서가 모두 생성이 되면 위와 같은 마지막 메세지가 나온다.

여기에서 위에 붉은색 부분을 이제 웹서버의 ssl vhost 설정에 추가해 주면 된다.


SSLCertificateFile /etc/letsencrypt/live/abcd.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/abcd.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/abcd.com/fullchain.pem

 

ssl vhost의 해당 도메인 부분에 위 인증서 정보를 추가해주고, 웹서버를 재시작 해주면 된다.

 

 

Support EFF's Work on Let's Encrypt

Protect digital privacy and free expression. The Electronic Frontier Foundation's public interest legal work, activism, and software development preserve fundamental rights.  EFF is a U.S. 501(c)(3) nonprofit,...

supporters.eff.org

 

 

 

리눅스 x윈도우 환경 설정하기 - xset

리눅스 설치 후 x윈도우 사용시 x윈도우에 대한 콘솔 설정하기

명령어 : xset

- x-window 환경에 대한 옵션을 설정한다

 

리눅스 데스크탑 설치후 스크린세이버, 절전모드를 비활성화하기 위해서 gui관리 메뉴를 통해 설정을 했지만 제대로 적용되지 않았다.

 

구글링을 해보니 xset 이라는 명령어를 통해 간단히 설정 할 수 있었다.

 

* screensaver off 하기

[root@localhost ~]# xset s off

 

* 절전모드 중지하기

[root@localhost ~]# xset -dpms

 

* 현재 설정되어 있는 x윈도우 환경 보기

[root@localhost ~]# xset -q

 

참고1 : xset 설정 (tistory.com)

 

xset 설정

xset SYNOPSISxset ← prompt 상에서 xset 명령어를 치시게 되면 아래와 같은 도움말이 출력됩니다. usage : xset [-display host:dpy] option ... To turn bell off: -b b off b 0 To set bell volume, pitch and duration: b [vol [pitch [dur]]

deois.tistory.com

참고2 : xset 명령 - IBM Documentation

 

xset 명령

용도X-Windows 환경에 대한 옵션을 설정합니다. 구문xset [  -디스플레이 디스플레이 ] [  b [  볼륨  [  피치  [  지속 기간  ] ] ] |  -b |   ... 에 대한 |  b 오프 ] [  백작 | tert-부틸  ]  c.  

www.ibm.com

 

업로드 디렉토리 php 실행 방지하기

apache 서버로 파일서버 운영하면서

업로드 디렉토리에 원치 않는 php, html 등과 같은 실행파일이 올라가는 경우가 있다

이럴 경우,

특정 디렉토리를 제외한 모든 업로드 디렉토리에서 php가 실행 되지 않게 해야 할 경우

 

"php_admin_flag engine off

 

를 이용해 주면 된다.

이 옵션을 httpd.conf에 설정해 여러 vhost에 동일하게 적용할 수 있다.

또는 특정 VirtualHost 부분에만 추가해서 적용도 가능하다.

 

<Directory "/home/제한할디렉토리/">
    <FilesMatch "\.(html|php|php3)$">
        php_admin_flag engine off
    </FilesMatch>
</Directory>

 

php 코드가 실행되지 않게 하려면 위와 같은 코드를 httpd.conf에 추가해 주면 된다.

이때, 특정 디렉토리는 php 실행을 허용해야 한다면, 

 

<Directory "/home/허용할디렉토리/">
    <FilesMatch "\.(html|php|php3)$">
        php_admin_flag engine on
    </FilesMatch>
</Directory>

 

와 같이 해주면 된다.

 

위 설정은

- apache2.4

- php 5.6

환경에서 적용한 방법이다.

certbot 갱신 실패 - apache plugin 오류

인증서 갱신일이 얼마 안남았다고 인증서 생성시 지정한 메일로 알림 메일을 받았다.
자동으로 갱신하도록 크론탭에 작성을 해놨었는데....
수동으로 확인을 해보니.. 아래와 같은 내용이 출력되며 갱신 실패.

[root@kidd ~]# /usr/bin/certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/AAAA.co.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not yet due for renewal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/BBBB.co.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Could not choose appropriate plugin: The requested apache plugin does not appear to be installed
Failed to renew certificate kidd.co.kr with error: The requested apache plugin does not appear to be installed

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/CCCC.co.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not yet due for renewal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.AAAA.co.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not yet due for renewal

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following certificates are not due for renewal yet:
  /etc/letsencrypt/live/AAAA.co.kr/fullchain.pem expires on 2023-01-27 (skipped)
  /etc/letsencrypt/live/BBBB.co.kr/fullchain.pem expires on 2023-02-17 (skipped)
  /etc/letsencrypt/live/www.AAAA.co.kr/fullchain.pem expires on 2023-02-03 (skipped)
All renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/BBBB.co.kr/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)


내용인 즉, apache plugin이 설치가 안되었다는 거 같은데...
letsencrypt 설치할때.. 그런거를 못봤던거 같고. 
인증서 생성시 생성 옵션이 뭔가 이전보다 적었다는거... 그정도 생각이 떠오른다..

구글신에게 물어보니...
"The requested apache plugin does not appear to be installed" 이 질문에 대한 여러 답변중에
python 관련 apache plugin을 설치하라는거가 있었다.
"python2-certbot-apache" - CentOS 7"python3-certbot-apache" - CentOS 8

현재 설치된 letsencrypt 의 plugin을 확인해보니, 아래와 같다.

[root@~]# certbot plugins
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* standalone
Description: Spin up a temporary webserver
Interfaces: IAuthenticator, IPlugin
Entry point: standalone = certbot._internal.plugins.standalone:Authenticator

* webroot
Description: Place files in webroot directory
Interfaces: IAuthenticator, IPlugin
Entry point: webroot = certbot._internal.plugins.webroot:Authenticator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

역시, apache 어쩌고는 없다.


현재 서버 버젼이 CentOS7 버젼이니, "python2-certbot-apache"를 설치하면 되겠다.
[root@~]# yum install certbot python2-certbot-apache

설치하고 나서 갱신을 해보니, 잘 되고, plugin도 확인해보니, apache plugin이 나온다.

[root@~]# certbot plugins
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* apache
Description: Apache Web Server plugin
Interfaces: IAuthenticator, IInstaller, IPlugin
Entry point: apache = certbot_apache._internal.entrypoint:ENTRYPOINT

* standalone
Description: Spin up a temporary webserver
Interfaces: IAuthenticator, IPlugin
Entry point: standalone = certbot._internal.plugins.standalone:Authenticator

* webroot
Description: Place files in webroot directory
Interfaces: IAuthenticator, IPlugin
Entry point: webroot = certbot._internal.plugins.webroot:Authenticator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


결론, 
letsencrypt 를 설치하고 인증서 생성시 apache 옵션이 안보이거나,
인증서 갱신시 apache plugin 어쩌고 하는 빨간색 오류줄이 보이면,
주저없이 OS버젼에 맞게 python2-certbot-apache를 설치해주면 된다.

 

letsencrypt 설치시 처음부터 apache plugin까지 설치하면 더 좋겠다.

[root@~] yum install certbot python2-certbot-apache 

특정IP가 아닌 user-agent 네이밍(이름)으로 접속이 많은 경우 차단하기

1. 접속하는 user-agent를 확인하다.
- 로그 기록을 combined 로 변경해 user-agent가 기록 되게 수정
- 로그 체크해서 user-agent를 확인한다.
- http.conf 를수정한다.


SetEnvIfNoCase User-Agent "^amazonaws" bad_bot
SetEnvIfNoCase User-Agent "^amazonaws.com" bad_bot
SetEnvIfNoCase User-Agent "^compute-1.amazonaws.com" bad_bot
SetEnvIfNoCase User-Agent "^BUbiNG" bad_bot
SetEnvIfNoCase User-Agent "^MJ12bot" bad_bot
<Directory "/home/daara">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Deny from env=bad_bot
</Directory>

- 웹서버 재시작해준다.
- 로그 체크해보면 403 forbidden 상태 기록되는거 확인한다.

 

이 방법은 크롤링하는것들중 잡스러운것들에 대한 접속 차단할때 유용하다.

 

letsencrypt ssl인증서 갱신, 생성 오류 사례

신규 인증서 생성시 아래와 같은 오류 발생 대처
에러1 -------------------------
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
An unexpected error occurred:
TypeError: __str__ returned non-string (type Error)
Please see the logfiles in /var/log/letsencrypt for more details.
해결 -------------------------
pip install urllib3==1.26.7
pip install requests==2.11.1



에러2 --------------------------
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
An unexpected error occurred:
SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

해결 ---------------------------
# --no-verify-ssl 옵션을 추가해서 생성한다. 
certbot certonly --no-verify-ssl

apache 웹서버 재시작(restart)가 안된다

우씨~ apache(httpd)가 갑자기 실행이 안된다......
별로 한것도 없는데.. 

[root@test119 ~]# systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@test119 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 목 2021-11-25 10:23:58 KST; 20s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 7536 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 32225 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
  Process: 7523 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 7523 (code=exited, status=1/FAILURE)

11월 25 10:23:58 test119 systemd[1]: Starting The Apache HTTP Server...
11월 25 10:23:58 test119 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
11월 25 10:23:58 test119 kill[7536]: kill: cannot find process ""
11월 25 10:23:58 test119 systemd[1]: httpd.service: control process exited, code=exited status=1
11월 25 10:23:58 test119 systemd[1]: Failed to start The Apache HTTP Server.
11월 25 10:23:58 test119 systemd[1]: Unit httpd.service entered failed state.
11월 25 10:23:58 test119 systemd[1]: httpd.service failed.


config파일들 syntex는 이상없는데..
ssl인증서 기간도 남아 있는데.. 
이것저것 구글링을 하다 보니, 에러로그를 확인해보라고 한다.
내가 아는 에러로그는 apache(httpd) 실행중에 생기는 문제를 기록하는것으로 아는데...
apache가 실행되면서도 잠깐이지만 바로 로그를 기록하는듯... 암튼.
로그를 확인해보니, 

[root@test119 conf.d]# tail /var/log/httpd/error_log
AH00016: Configuration Failed
[Thu Nov 25 10:23:58.816796 2021] [suexec:notice] [pid 7523] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Nov 25 10:23:58.817714 2021] [core:emerg] [pid 7523] (28)No space left on device: AH00023: Couldn't create the ssl-cache mutex
AH00016: Configuration Failed
[Thu Nov 25 10:28:10.437030 2021] [suexec:notice] [pid 7634] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Nov 25 10:28:10.459085 2021] [core:emerg] [pid 7634] (28)No space left on device: AH00023: Couldn't create the rewrite-map mutex
[Thu Nov 25 10:28:10.459102 2021] [:emerg] [pid 7634] AH00020: Configuration Failed, exiting
[Thu Nov 25 10:29:02.522577 2021] [suexec:notice] [pid 7684] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Nov 25 10:29:02.544507 2021] [core:emerg] [pid 7684] (28)No space left on device: AH00023: Couldn't create the rewrite-map mutex
[Thu Nov 25 10:29:02.544526 2021] [:emerg] [pid 7684] AH00020: Configuration Failed, exiting

첨 보는 에러로그다. 
No space left on device: AH00023 ...... 이거 공간이 부족한가?

[root@test119 conf.d]# df
Filesystem           1K-blocks      Used  Available Use% Mounted on
/dev/mapper/cl-root 1942918240 179468112 1763450128  10% /
devtmpfs               4021816         0    4021816   0% /dev
tmpfs                  4037988         0    4037988   0% /dev/shm
tmpfs                  4037988    189684    3848304   5% /run
tmpfs                  4037988         0    4037988   0% /sys/fs/cgroup
tmpfs                  4037988         0    4037988   0% /tmp
/dev/sda2              1038336    169552     868784  17% /boot
/dev/sda1               204580      9672     194908   5% /boot/efi
tmpfs                   807600         0     807600   0% /run/user/0

디시크공간 이상없는데...

Couldn't create the ssl-cache mutex AH00016: Configuration Failed
이건 뭘까.... 구글링 해보자.

 


두번째 "내일은 치킨집 CEO"님의 포스팅 먼저...(국문이라...).
https://www.enteroa.com/tag/no-space-left-on-device/

"Semaphore"라는 프로세스가 생성되었다가 없어지지 않아서...
엄밀히 말하면, "Semaphore" 프로세스 생성 가능한 숫자를 이미 초과해서(No space left on device) 
apache(httpd)가 시작시 새로운 "Semaphore"를 생성하지 못하면서 apache(httpd) 실행이 안된다고 한다.

이건, "Semaphore"가 아파치의 여러 프로세스간 데이타 동기화를 위해 필요한데..
apache(httpd)가 비정상적으로 종료될때 이미 생성된 "Semaphore"를 초기화 되지 못해 그렇다고 한다.

암튼, 일단 
해당 프로세스가 얼마나 있는지 확인

[root@test119 conf.d]# ipcs -s | wc -l
130

130개가 현재 존재중이다.

그럼 최대가능수는?
[root@test119 conf.d]# ipcs -ls

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

현재 max number of arrays 는 128개라고 한다.
이미 초과했고, 초기화(종료) 되어 있지 않아서 apache(httpd)가 실행이 안되니, 
현재 생성되어 있는 Semaphore 를 초기화 하자.
[root@test119 conf.d]# ipcrm -a
[root@test119 conf.d]# ipcs -s | wc -l
4

이제 4개 있다고 한다.(어디서 생성되었지? 초기화 하자 마자 생성되네...)
다시 apache(httpd) 실행을 해보니 잘된다.
[root@test119 conf.d]# systemctl start httpd


이번 에러는 첨 경험해보는 경우이다.
system관리 ..... 넘 어려줘~~



참조 페이지
https://www.enteroa.com/tag/no-space-left-on-device/
https://serverfault.com/questions/991946/no-space-left-on-device-ah00023-couldnt-create-the-mpm-accept-mutex-when-re

letsencrypt 인증서 다른서버로 복사하기

letsencrypt 인증서 생성 후 서버를 이전 또는 이중화 하는 경우가 있을것이다.

이때 기존 생성한 인증서를 복사한 방법은 아래와 같다.

 

우선 인증서가 설치된 위치로 이동한다.

cd /etc/letsencrypt

이동 후 하위의 디렉토리들을 확인하고, 하위 디렉토리중 

인증서 정보, 설정 정보, 갱신정보가 있는

"archarchive", "live", "renewal", "renewal-hooks" 를 복사한다.

이때, 특정 도메인만 하겠다고 하면 해당 도메인 인증서만 복사한다.

 

두번째로 기존 인증서에 사용하는 계정정보(account)를 확인해 둔다.

이 부분이 중요한데, 다른서버에서 계정정보가 다르기 때문에 타겟 서버에 이동후 인증서 파일정보에 있는 계정을 타켓서버에 맞게 변경을 해줘야 한다.

 

타겟서버에서도 letsencrypt의 인증서 계정정보를 확인한다.

ls /etc/letsencrypt/accounts/acme-v02.api.letsencrypt.org/directory/

위와 같이 하거나, 타겟서버에서 생성된 인증서가 있다면 해당 인증서의 설정 파일을 열어 확인해도 된다.

 

복사한 원본 letsencrypt 인증서를 타겟서버에 복사한다.

 

마지막으로 복사한 인증서 정보에서 account 를 변경해 준다.

sed -i 's/old계정/new계정/' /etc/letsencrypt/renewal/*

 

참고 url : community.letsencrypt.org/t/copy-etc-letsencrypt-or-regenerate-to-move/141684/3

 

letsencrypt ssl인증서 만료 갱신 오류 해결 - webroot 관련

ssl인증서는 최근 웹서비스에서는 필요불가결한 서비스이다.

여러 웹서비스를 운영할 경우 상당히 많은 부분에 ssl 인증서가 필요하다 보니 비용 문제에 직면하게 된다.

 

그래서, 무료로 사용이 가능한 letsencrypt 인증서를 많이들 사용하는데....

잘만 관리해주면 상당히 괞찮은 ssl 적용 방법이라고 생각된다.

 

다만, 가끔씩 갱신이 잘 안된다거나, 갱신 오류가 발생하기도 하는데...

오늘은 아래와 같은 오류에 대해서 해결하는 방법을 공유해 본다.

 

 

letsencrypt ssl 인증서 갱신하기

 

우선, 인증서를 적용하는 도메인을 aaaa.bbbb.kr 이라고 가정하고..

 

리눅스 크론탭(crontab)에 통해 매달 2일정도 갱신을 시도하도록 스케줄링을 적용해 놓았다.

# letsencrypt renew
00 5 10,16 * * root /root/letsencrypt/certbot-auto renew >> /var/log/letsencrypt/renew.log

 

그런데, 확인을 해보니, 인증서 만료일이 갱신되지 못하고 실패가 나고 있었다.

그래서, 직접 갱신 시도를 해보았다.

 

#cd /root/letsencrypt

#./certbot-auto renew

 

갱신을 실행해 보니, 아래와 같은 메세지가 출력되었다.

 

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/aaaa.bbbb.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for aaaa.bbbb.kr
Cleaning up challenges
Attempting to renew cert (aaaa.bbbb.kr) from /etc/letsencrypt/renewal/aaaa.bbbb.kr.conf produced an unexpected error: Missing command line flag or config entry for this setting:
Input the webroot for aaaa.bbbb.kr:. Skipping.
All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/aaaa.bbbb.kr/fullchain.pem (failure)

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

All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/aaaa.bbbb.kr/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)

 

내용을 보니, 뭔가 수정을 하라는거 같은데....

오류 내용에 뭔가 빠져 있다고 하는거 같고... 그게 webroot 와 관련되는거 같고...

그래서 구글링을 통해 확인을 해보니...

configuration 파일(/etc/letsencrypt//renewal/aaaa.bbbb.kr.conf)에 webroot 정보가 빠져서 그렇다고 한다.

 

설정파일을 열어 확인해보니, 해당 부분이 없서 추가 해주었다.

 

#vi /etc/letsencrypt/renewal/aaaa.bbbb.kr.conf

# renew_before_expiry = 30 days
version = 0.38.0
archive_dir = /etc/letsencrypt/archive/aaaa.bbbb.kr
cert = /etc/letsencrypt/live/aaaa.bbbb.kr/cert.pem
privkey = /etc/letsencrypt/live/aaaa.bbbb.kr/privkey.pem
chain = /etc/letsencrypt/live/aaaa.bbbb.kr/chain.pem
fullchain = /etc/letsencrypt/live/aaaa.bbbb.kr/fullchain.pem

# Options used in the renewal process
[renewalparams]
server = https://acme-v02.api.letsencrypt.org/directory
authenticator = webroot
account = asdfasfasfasfdasfdasfdasfdasdfa

 

설정 파일 내용을 보면, webroot에 대한 정보가 없다.

그래서, aaaa.bbbb.kr 에 대한 웹루트(/webroot/aaaa.bbbb.kr) 정보를 설정 파일 하단에 추가 주었다.

 

[[webroot_map]]
aaaa.bbbb.kr = /webroot/aaaa.bbbb.kr

 

 

이렇게 수정을 마치고, 다시 갱신 시도를 해보니 오류 없이 잘 되었다.

 

#./certbot-auto renew

 

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/aaaa.bbbb.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for aaaa.bbbb.kr
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/aaaa.bbbb.kr/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/aaaa.bbbb.kr/fullchain.pem (success)

 

 

 

 

notepad++ 이용중에 sftp 인증 오류 날때

notepad++ 이용중에 sftp 인증 오류 날때.

 

잘 사용하던 notepad++ 에서 sftp로그인중 갑자기 접근 인증 오류가 발생해 난감할때가 있다.

이는 어떤 이유에선지 모르겠지만, 호스트키(host key)정보가 잘못 저장되어 일어나는 경우로 보인다.

 

해결하는 방법은

C:\Users\사용자계정\AppData\Roaming\Notepad++\plugins\config\NppFTP

부분으로 이동해서

known_hosts 파일을 찾아 에디터로 열어서 sftp 접속 문제가 발생하는 서버의 호스트(IP)를 찾아 지운 후 저장하고,

notepad++을 다시 접속해서 사용하면 된다.

 

 

난감할때가 있긴한데, 알고 보면 간단하다.

 

또한, notepad++의 sftp정보의 백업도 간단하다.

위 디렉토리에 있는 NppFTP.xml 파일만 백업하면, sftp에 설정한 접속정보를 백업할 수 있다.

 

 

 

영문 Putty 설치후 한글이 깨져서 보일때

영문 Putty 설치후 한글이 깨져서 보일때가 있다.
이때, Putty 설정에서 character set을 변경해주면 되는데...여기에 cp949가 없을 경우가 있다.

cp949가 Putty "Window > Translation"에서 보이지 않을경우 레지스트리를 수정해주면 되는데.
"[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\저장된세션이름"에서 LineCodePageFontCharSet 을 변경해주면 된다.
1. FontCharset을 클릭하여 16진수 선택하고 81 을 입력해준다.
2. LineCodePage 클릭후 cp949를 입력해준다.

위와 같이 레지스트리 변경후 EUC-KR 서버에 SSH로 원격 접속을 해보면 한글 입출력이 잘된다.
참고로 저장된 세션이 여러개이면, 개별적으로 모두 해주어야 모든 세션에서 한글을 사용할수 있다.

참조 url : http://blog.pincoin.co.kr/2013/01/08/euc-kr-%EB%A6%AC%EB%88%85%EC%8A%A4-%EC%84%9C%EB%B2%84%EC%97%90-putty-ssh-%EC%A0%91%EC%86%8D/


[리눅스 명령어] 폴더별 사용량보기

du

특정 디렉토리에서 하부디렉토리까지 포함한 디스크의 사용량을 보여준다.


[사용법]


du [Option] [Files]

* Option
-a  : 디렉토리에 있는 파일 하나하나의 크기를 출력한다.
-s  : 총 사용량만 표시한다. (간단하게 전체 용량을 확인할 때는 단순하게 이 옵션을 쓰자.)

 

du -s


-k  : KiloByte 단위로 표시한다.
-h  : 용량을 사람이 보기 가장 좋게 표시한다.

[예제]
'du -a' : 현재 디렉토리의 디스크 사용량을 파일단위로 모두 출력한다.
'du -s *' : 현재 디렉토리의 첫번째 단계까지만 디스크의 사용량을 출력한다.
              'du -h --max-depth=0 *' 와 동일
'du -h --max-depth=1 '

--max-depth=1 에서 마지막의 숫자는 폴더의 깊이이다.  

[리눅스] 서버 명령어 모음

<사용자 관련>

 adduser [계정이름] : 계정생성
 passwd [계정이름] : 해당계정의 비번변경
 userdel -r [계정이름] : 계정삭제 및 계정의 파일폴더 모두 삭제(-r)
 w : 현재 사용중인 사용자
 last : 최근 이용한 접속자

 

<파일/디렉토리>

 ll : 전체폴더구조 보기
 ls : 폴더구조 간단히 보기
 ls -al : 숨긴파일 까지 다 보기
 ls [디렉토리명] : 해당 디렉토리보기
 ls [파일명 또는 일부] : 해당되는 파일만 보여주기
 
 cd : 디렉토리 이동
 chmod 755 [디렉토리] : 파일권한변경 (내꺼, 같은그룹, 전체) 


 mkdir [디렉토리] : 디렉토리생성
 mkdir -p a/b : a디렉토리 생성후 하위에 b디렉토리 생성


 rm [파일명] : 파일삭제
 rmdir [디렉토리명] : 디렉토리삭제 (파일존재시 삭제 불가)
 rm -rf [디렉토리명] : 하위 디렉토리 및 파일 까지 모두 삭제 


 touch [파일명] : 해당파일의 수정일을 현재시각으로 변경(파일없을시 빈파일 생성) 


 cp [파일1] [파일2] : 파일1을 파일2로 복사
 cp -r [디렉토리1] [디렉토리2] : 디렉토리1을 디렉토리2로 하위폴더와 파일까지 복사
 cp -a [파일1] [파일2] : 소유권을 유지하면서 복사


 move [파일/디렉토리] [디렉토리] : 파일 및 디렉토리 이동
 
 cat [파일명] : 파일내용 출력
 cat /dev/cdrom > linux.iso : CD롬에 있는 내용을 CD 이미지 파일로 만듦
 cat a.txt >> b.txt : b.txt 파일 하단에 a.txt 파일의 내용 추가
 
 more [파일명] : 파일내용을 페이지단위로 출력 (space:다음페이지, b:이전페이지)
 
 ln [해당디렉토리 또는 파일] [링크이름] : 하드링크
 ls -s [해당디렉토리 또는 파일] [링크이름] : 심볼릭링크
 
 | : 파이프로 두개의 명령을 연결시켜줌
 (예: ls -l /usr/bin | more : ls에서 검색된 파일 폴더를 페이지별로 보여줌)
 
 파일권한 (자신/그룹/나머지: 4:읽기, 2:쓰기, 1:실행)
 chown -R ohhappy.wheel /home/ohhappy/* : /home/ohhappy하위의 모든 파일 디렉토리의 소유자를 ohhappy로 그룹을 wheel로 변경
 
 mount -t iso9660 /dev/cdrom /mnt/cdrom : cdrom 마운트
 mount -t vfat /dev/fd0 /mnt/floppy : floppy 마운트
 umount /dev/cdrom 또는 umount /mnt/cdrom


  
<검색>

 find [경로] -name [파일명] : 하위경로의 파일찾기
 /[찾을 문서명] : 문서나 메뉴얼안에서 문자찾기
 which [명령어] : 명령어의 절대경로를 알려줌
 whereis [명령어] : 명령어의 바이너리, 소스, 맨페이지위치 알려줌
 
  
<시스템/프로세스 관련>

 top : 시스템 프로세스 및 메모리 및 CPU 사용량
 uname -a : 운영체제,호스트명,커널버전,시스템부팅시간,아키텍쳐 보여줌
 uname -m : cpu 보여줌
 free -m : 메모리 보여줌(-m 메가단위, -k kb단위)
 df -h : 마운트되어있는 디스크 사용량
 du --max-depth=1 -h /home : 각 계정별로 이용량 확인
 lsdev : 현재 사용중인 장치정보
 w : 현재 사용중인 사용자
 last : 최근 이용한 접속자
 date : 현재 설정된 시간
 clock : Cmos에 설정된 시간
 rdate -s soback.kornet.nm.kr : soback.kornet.nm.kr에서 시간을 전송받아 시간 수정
 clock -w : cmos 시간으로 수정
 netstat -tu : 시스템에 연결된 소켓정보 
 ifconfig : 네트웍 장치설정 정보
  
 ps -[옵션]: 현재 시스템에서 구동중인 프로세스 상태확인
 (-a:전체사용자, -l:자세히보기, -x:제어터미널이 없는 프로세스, -f:pstree명령어와 같은 프리구조로 출력)
 (상태값: D:구동일시중지중, R:구동중, S:쉬는중, T:구동정지중, Z:좀비프로세스, W:메모리를 안쓰는 스와핑상태)
 ps auxfw -width=300 : 프로세스의 사용자 확인 (주로 | more 필요)
 pstree : 구동중인 프로세스를 투리구조로 보여줌
 
 kill -9 [프로세스번호] : 프로세스 강제종료
 killall -9 [프로세스이름] : 프로세스 강제종료
 
<시스템 종료>

 init0 : 시스템 종료
 halt : 시스템 종료
 reboot : 시스템 재부팅
 
 <압축>

 tar cvf [생성될 파일명:예 httpd.tar] [묶을 디렉토리] : 설정한 디렉토리를 포함한 하위 디렉토리 및 파일을 묶음
 tar xvf [묶인파일:예 httpd.tar] : tar파일을 현재 디렉토리에 품
 tar tvf [묶인파일:예 httpd.tar] : tar파일을 풀지 않고, 파일리스트만 출력
 tar cvfz [압축파일명 :예 httpd.tar.gz] [압축할 디렉토리] : 파일을 묶어서 압축함
 tar xvfz httpd.tar.gz : tar.gz 압축해제
 tar xvfj httpd.tar.bz2 : tar.bz2 압축해제
 
<ftp>

 quit : ftp 종료
 get : 다운로드 명령
 mget : 현재폴더내 모든 파일 다운로드
 mget -R * : 현재폴더 및 하위 폴더 파일 다운로드

[linux 명령어]여러 파일 권한 한번에 바꾸기


여러파일 권한 바꾸기
 find ./ -type f -name 파일명 -exec chmod 777 {} \;
find 디렉토리시작위치 -type 타입구분(f=팡일 ,d=directory) -name 파일명 -exec chmod 권한 {} \;

위 명령을 이용하면, 디렉토리시작위치에서 하위에 있는 모든 디렉토리에 포함된 파일을 한번에 권한 설정을 해줄수 있다.

SSL 인증서를 도메인 별로 신청해야 하나요?


SSL인증서는 SSL서버가 돌아가는 웹사이트 주소별로 받는 것이 원칙입니다. 예를들어, www.a.com, secure.a.com 두 사이트에 SSL 서버를 설치하면 두개의 인증서를 신청해야 합니다.

그러나, 인증서의 신청은 여러분 회사의 SSL서비스 정책에 따라 달라집니다. 실제 SSL통신이 필요한 부분은 회원가입, 로그인, 정보수정, 전자상거래, 금융거래 개인정보 열람 등의 중요한 정보가 노출되는 부분이라고 할 수 있습니다.

일반적인 웹사이트 전체에 SSL 암호통신을 하다보면, 암호화된 데이터의 암호 복호화 시에 많은 서버부하를 주게 됩니다. 따라서, 일반적으로 특정 서버에 위의 중요한 데이터 통신 부분에 대한 웹서버에만 SSL통신(https)을 서비스하고, 그 이후는 일반 웹통신(http)을 하도록 하는 것이 관례적입니다.

출처 : http://www.certkorea.co.kr/cs.asp?faq_ssl

트랜잭션 복제중에 'sp_replcmds'을 실행할 수 없습니다. 라는 오류 발생할때.

트랜잭션 복제중에 'sp_replcmds'를 실행할수 없다는 오류가 발생해다. (오류 번호 : 18759)
일단 뭔 내용인지 몰라서, help를 뒤져 sp_replcmds가 뭔지 부터 확인했다.

sp_replcmds 설명 내용중에 보면,
"텍스트 포인터가 같은 트랜잭션에서 검색되지 않아 sp_replcmds가 텍스트 명령을 복제할 수 없는 경우에는 경고 메시지 18759번이 Microsoft® SQL Server™ 오류 로그 및 Microsoft Windows® 응용 프로그램 로그에 모두 추가됩니다." 라는 오류 18759에 대한 내용이 있다.

이것을 참고로 해서 텍스트 포인터를 확인해 주는 textvalid()함수를 이용해서 , 복제중에 오류를 발생시키고 있는 table의 text, ntext, image 필드에 대한 텍스트 포인터 유효성을 확인 해보았다.
일부 데이타중에 텍스트 포인터가 유효하지 않은것이 있어 해당 필드들에 대해서 초기화(update시킴)를 시켜주고,
다시 복제를 초기화를 진행해 주었다.

계속 모니터링을 해봐야 하겠지만, 현재로서는 복제가 잘되고 있다.