centos7에서 letsencrypt 설치하기
- 일반적으로 certbot 클라이언트를 사용하면 된다. 따라서 certbot 패키지를 설치한다.
1. epel 저장소 활성화 하고.
#yum install epel-release -y
2. certbot설치한다.
#yum install certbot python2-certbot-apache -y
별 문제 없다면 간단히 설치가 가능하다.
이후, 인증서를 생성해서 이용하면된다.
주로 사용하는 명령은,
certbot certonly :: 신규 생성할때
certbot renew :: 갱신할때.
ㄴ실행시 인증과 관련된 문제가 있을때 "--no-verify" 명령 옵션을 넣주고 실행한다.
ㄴ갱신 테스트 해볼때는 "--dry-run" 옵션을 추가해서 실행한다.
cerbot certificates :: 설치된 인증서 확인할때.
'server'에 해당되는 글 34건
- centos7에서 letsencrypt 설치하기
- certbot renew 실패 오류 - apache plugin 관련
- linux 서버에서 메일 보내기 관련 설치 프로그램
- php-fpm 설정시 html php 확장자 관련 에러 해결 하기 1
- Rokey linux 8에서 모니터링 zabbix-agent 설치하기
- Rokey linux 8에서 ssh 접근 제어하기
- [linux]apache 실행 실패 - 오류 No space left .. 관련
- rsync failed to connect 발생시 확인
- apache ssl 적용할때 mod_ssl.so 관련 에러 이슈
- letsencrypt wildcard 인증서 자동 갱신 실패 이슈
- letsencrypt 와일드카드(Wildcard) 인증서 생성하기
- 리눅스 x윈도우 환경 설정하기 - xset
- 업로드 디렉토리 php 실행 방지하기
- certbot 갱신 실패 - apache plugin 오류
- 특정IP가 아닌 user-agent 네이밍(이름)으로 접속이 많은 경우 차단하기
- letsencrypt ssl인증서 갱신, 생성 오류 사례 1
- apache 웹서버 재시작(restart)가 안된다 2
- letsencrypt 인증서 다른서버로 복사하기
- letsencrypt ssl인증서 만료 갱신 오류 해결 - webroot 관련
- notepad++ 이용중에 sftp 인증 오류 날때
centos7에서 letsencrypt 설치하기
certbot renew 실패 오류 - apache plugin 관련
무료 인증서 letsencrypt 관리 프로그램 certbot 설치하기
letsencrypt 를 설치(dnf install letsencrypt) 후
기존 사용하던 인증서를 복사해서
renew(certbot renew) 를 해 봤을때,
실패가 나면서 아래와 같은 오류 메세지가 있다면,
"The requested apache plugin does not appear to be installed"
certbot 실행에 필요한 apache plugin이 없다는 것이다.
certbot 관련 plugin은 letsencrypt를 설치 후 확인해 보면,
[root@sv]# yum list installed | grep certbot
certbot.noarch 1.11.0-2.el7 @epel
python2-certbot.noarch 1.11.0-2.el7 @epel
두가지만 나오는데,
갱신(renew)시 실패나면서 필요하다는 apache plugin은 없는 상태가.
certbot apache plugin은 찾아보면, python 관련되는 플러그인으로
위에 나온 python2-certbot 유형으로 찾으면 되는데.
위 의 경우는
python2-certbot-apache 가 필요한 상태이다.
설치는
yum install -y python2-certbot-apache
하면 된다.
이후 다시 확인해보면,
[root@sv]# yum list installed | grep certbot
certbot.noarch 1.11.0-2.el7 @epel
python2-certbot.noarch 1.11.0-2.el7 @epel
python2-certbot-apache.noarch 1.11.0-1.el7 @epel
추가된 항목이 보인다.
CentOS 7까지는 위와 같이 하면 될거고,
Rokey linux 에서는
설치된 버젼 확인후 apache plugin을 설치해 주면 된다.
apache plugin까지 설치하고 확인해보면, 아래와 같을 것이다.
[root@svr]# dnf list installed | grep certbot
certbot.noarch 1.22.0-1.el8 @epel
python3-certbot.noarch 1.22.0-1.el8 @epel
python3-certbot-apache.noarch 1.22.0-1.el8 @epel
linux 서버에서 메일 보내기 관련 설치 프로그램
postfix 와 mailx 가 필요하다.
설치 되어 있지 않다면, 설치해 준다.
설치 확인
#dnf list installed | grep postfix
postfix.x86_64 2:3.5.8-7.el8 @baseos
# dnf list installed | grep mailx
mailx.x86_64 12.5-29.el8 @baseos
검색 결과가 나오지 않았다면, 설치해 줘야 한다.
#dnf install -y postfix mailx
설치가 완료되면, 필요한 작업을 한다.
나의 경우,
서버 백업 쉘스크립트에서, 담당자에게 메일 보내는 작업에 사용중이다.
php-fpm 설정시 html php 확장자 관련 에러 해결 하기
php-fpm 사용시
html, php 확장자 사용 관련 수정 사항
/etc/httpd/conf.d/php.conf
에서
<IfModule mod_php.c>
<FilesMatch \.(php|html|phar)$>
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
<IfModule !mod_php.c>
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch \.(php|html|phar)$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
</IfModule>
</IfModule>
두 부분에 html 확장자 추가
추가로,
php-fpm 관련 www.conf 파일을 수정해 줘야 한다.
/etc/php-fpm.d/www.conf
#vi /etc/php-fpm.d/www.conf
해당 파일에서 내용중
## 주석해제 후 내용수정
#security.limit_extensions = .php .php3 .php4 .php5 .php7
주석 되어 있던 부분을 해제 하고 .html 을 추가해 준다.
security.limit_extensions = .php .php3 .php4 .php5 .php7 .html
위 부분과 관련한 에러 로그는 아래과 같이 보일 수 있으니 참고 하시라...
[Wed Apr 02 17:59:36.338751 2025] [proxy_fcgi:error] [pid 25475:tid 139693190534912] [client 127.0.0.1:57039] AH01071: Got error 'Access to the script '/home/aaa/404.html' has been denied (see security.limit_extensions)', referer: https://aaa/index.html
Rokey linux 8에서 모니터링 zabbix-agent 설치하기
Rokey linux 8에서 모니터링 zabbix-agent 설치하기
Rokey linux 8에서 zabbix는
dnf install 이나, yum install 로 바로 설치 되지 않는다.
레포지토리 관련한 이슈가 있다고 한다.
(자세한건 잘 모름)
그래서, 우선 레포지토리 관련되는 rpm 먼전 설치하고 진행해야 한다.
아래 진행 순서 기록해 둔다.
[root@svr ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm(을)를 복구합니다
경고: /var/tmp/rpm-tmp.CMnyz3: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying... ################################# [100%]
준비 중... ################################# [100%]
Updating / installing...
1:zabbix-release-6.0-4.el8 ################################# [100%]
[root@svr ~]# dnf install -y zabbix-agent
Zabbix Official Repository -x86_64 302 kB/s | 573 kB 00:01
Zabbix Official Repository (non-supported) - x86_64 1.2 kB/s | 1.4 kB 00:01
Zabbix Official Repository (Agent2 Plugins) -x86_64 1.4 kB/s | 1.7 kB 00:01
종속성이 해결되었습니다.
==================================================================================
꾸러미 구조 버전 저장소 크기==================================================================================
설치 중:
zabbix-agent x86_64 6.0.39-release1.el8 zabbix 585 k
연결 요약
=======================================================================================
설치 1 꾸러미
전체 내려받기 크기: 585 k
설치된 크기 : 2.2 M
꾸러미 내려받기 중:
zabbix-agent-6.0.39-release1.el8.x86_64.rpm 452 kB/s | 585 kB 00:01
-----------------------------------------------------------------------------------------------------------------------------------------------------------------합계 451 kB/s | 585 kB 00:01
Zabbix Official Repository - x86_64 1.6 MB/s | 1.7 kB 00:00
GPG키 0xA14FE591 가져오는 중:
사용자 ID : "Zabbix LLC <packager@zabbix.com>"
지문: A184 8F53 52D0 22B9 471D 83D0 082A B56B A14F E591
출처 : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
키 가져오기에 성공했습니다
연결 확인 실행 중
연결 확인에 성공했습니다.
연결 시험 실행 중
연결 시험에 성공했습니다.
연결 실행 중
준비 중 : 1/1
구현 중 : zabbix-agent-6.0.39-release1.el8.x86_64 1/1
설치 중 : zabbix-agent-6.0.39-release1.el8.x86_64 1/1
구현 중 : zabbix-agent-6.0.39-release1.el8.x86_64 1/1
확인 중 : zabbix-agent-6.0.39-release1.el8.x86_64 1/1
설치되었습니다:
zabbix-agent-6.0.39-release1.el8.x86_64
완료되었습니다!
* 설정 파일 수정하기
vi /etc/zabbix/zabbix_agentd.conf
변경할 부분은
zabbix server IP가 192.168.0.1 이고,
모니터링 대상 zabbix agent 서버 ip가 192.168.0.2 이라고 할때
Server=192.168.0.1
StartAgents=1
ServerActive=192.168.0.1
Hostname=192.168.0.2
이 정도만 변경 셋팅하면 된다.
이후,
#systemctl start zabbix-agent
#systemctl enable zabbix-agent
zabbix 설정 끝.
Rokey linux 8에서 ssh 접근 제어하기
Rokey linux 8 이상 사용시
이전 centos 7버젼까지 사용하던
hosts.deny, hosts.allow가 보안상 사용 제외 되었다고 한다.
대신, firewalld 와 iptables를 사용해야 한다는데...
이러면, 개별 서버별로 포트관리나, ip별 접근 제어를 해야 해서 복잡하게 되었다.
업그레이드 해서 좋았는데..
이런 어려움이 있네. 공부해야 하겠다.
어려운 부분은 서버 관리업체에 맏기고,
이전에 하던거 처럼 ssh에 대한 접근 제어만 해보도록 하자.
firewalld, iptables 사용 없이
ssh의 설정을 통해서 한다.
/etc/ssh/sshd_config 파일에서
AllowUsers, DenyUsers, AllowHosts, DenyHosts 를 이용해
적절히 설정하면 된다고 한다.
계정과 ip를 이용해 접근 제어 하려면,
- 허용하는 user
AllowUsers root@192.168.0.1 *@192.168.0.1
- 제외하는 user
DenyUsers root@192.168.0.2
이런 방식으로 하면 되고, 여러개일 경우 콤마나 공백을 띄워서 작성해주면 된다. IP로 접근 제어를 할때는 - 허용할때 AllowHosts 192.168.0.0/24 172.16.0.1 - 제외할때 DenyHosts 192.168.0.0/24 172.16.0.1
--> 이 설정 기능은 ssh 최신 버젼에서는 없어졌다고 합니다. AllowUsers, DenyUsers로 이용해야 한다고 합니다.
이렇게 입력하고, 저장 후 sshd를 재시작 해주면 된다.
systemctl sshd restart
centos 7까지의 설정에서는 hosts.deny, hosts.allow 에서
개별 데몬별로도 설정이 가능했지만,
현재 rokey linux 8 이상에서는 보안상 이전 방식이 사용되지 않고,
조금 번거롭지만, 개별 서비스별로 설정을 해야 할 거 같다.
[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에 설정한 접속정보를 백업할 수 있다.