이를 방지 하기 위해서 Let’s Encrypt 3개월 무료 갱신 후크를 이용한 apache 중지, 실행, 재실행을 할 수 있습니다.
스크립트 안에는 딱히 명령어가 많지는 않고 https 를 start, stop 명령만 넣었습니다.
후킹에는 총 3개의 폴더로 구성되어 있습니다.
deploy 배포후에 동작하는 shell script (재시작을 보통 넣지만 저는 start 를 입력했습니다)
systemctl start httpd.service
post 인증명령어 동장 후 무조건 진행하는 shell script
systemctl start httpd.service
pre 인증 전 미리 동작하는 shell script
systemctl stop httpd.service
하나하나 직접 만들어도 되지만 Let’s Encrypt 폴더가 /etc/letsencrypt 로 시작한다면 아래 명령어로 일괄 다운받아 설치 할 수 있습니다. 제가 서버 추가할때마다 아래 명령어를 그대로 복사해서 붙여넣고 있습니다.
# 만약 다른 스크립트가 있다면 아래 명령어를 절대 실행해선 안됩니다. 모두 삭제됩니다.
cd /etc/letsencrypt
rm -rf /etc/letsencrypt/renewal-hooks/
wget https://vlog.tion.co.kr/app/renewal-hooks.tar
tar xvf renewal-hooks.tar
rm -rf renewal-hooks.tar
ll
cd /etc/letsencrypt/renewal-hooks/
du -ha
파일이 정상적으로 다운받고 압축이 잘 풀렸는지 확인까지 한눈에 파악되니 쉽게 자동 인증서 갱신이 될듯합니다.
그래서 관련 웹서버 모니터링 서비스를 찾아보았지만 제 맘에 드는게 없어서 직접 만들었습니다.
우선 파이썬3 버전이 설치가 되어져있어야 합니다.
파이썬3 설치에 관련해서는 아래 링크를 참고해주세요.
파이썬3 버전이 설치되었다면 아래 명령어를 그대로 복사 붙여넣기 하면됩니다.
mkdir /root/_TION
cd /root/_TION
wget https://vlog.tion.co.kr/python/tionServerMonitoring.tar
tar xvf tionServerMonitoring.tar
rm -rf tionServerMonitoring.tar
echo "python3 /root/_TION/tionServerMonitoring/memcheck_httpd_restart.py" > /tionServerMonitoring.sh
chmod 701 /tionServerMonitoring.sh
(crontab -l 2>/dev/null; echo "*/1 * * * * /tionServerMonitoring.sh") | crontab
/tionServerMonitoring.sh
ls -a
위의 명령어를 그대로 서버에 SSH 프로그램을 이용하여 복사붙여넣기를 하면 python/tionServerMonitoring.tar 파일을 다운받고 그 파일을 압축풀어서 python3 명령어로 실행을 하게됩니다.
python3: command not found
파이썬3를 설치했음에도 불구하고 위처럼 나타나면 심볼릭을 잡아주시기 바랍니다.
ln -s /usr/bin/python3.8 /usr/bin/python3
이제 python3 명령어로 잘 실행이 되는군요.
이제 다시 [ /tionServerMonitoring.sh ] 쉘스크립트를 실행해보겠습니다.
위에서 이미 설치를 하였기에 다시 또 설치할 필요는 없습니다.
괜히 crontab 항목에 1분마다 서버체크하는 항목만 더 추가되니 2번이상 설치하신분들은 꼭 crontab -e 항목을 확인하셔서 중복된 체킹을 제거해주세요.
[root@amzn2 _TION]# /tionServerMonitoring.sh Traceback (most recent call last): File “/root/_TION/tionServerMonitoring/memcheck_httpd_restart.py”, line 1, in import psutil ModuleNotFoundError: No module named ‘psutil’
이번에는 psutil 이라는 모듈이 없다고 나올겁니다.
pip 명령어를 이용하여 psutil, stdin모듈을 설치해주세요
pip install psutil stdin
만약 pip 명령어가 없다고 나올 경우
-bash: pip: command not found
pip를 설치해야합니다.
아래 링크에서 pip install 설치를 우선 확인하고 설치해주세요. (이 글 본문에도 링크 아랫쪽에 넣어두긴했습니다)
[root@localhost www]# clear
[root@localhost www]# python
Python 2.7.18 (default, May 25 2022, 14:30:51)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
우선 심볼릭 링크를 삭제하고 파이썬 3 폴더를 연결해야 하는데 파이썬 버전부터 확인해야합니다.
ls -l /usr/bin/python*
[root@localhost www]# ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 7 Dec 14 07:18 /usr/bin/python -> python2
lrwxrwxrwx 1 root root 9 Dec 14 07:18 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7048 May 25 2022 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1846 May 25 2022 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root 16 Dec 14 07:18 /usr/bin/python2-config -> python2.7-config
-rwxr-xr-x 1 root root 7048 Nov 17 08:41 /usr/bin/python3.8
lrwxrwxrwx 1 root root 14 Dec 14 07:18 /usr/bin/python-config -> python2-config
이렇게 나타날겁니다.
삭제하는 심볼은 /usr/bin/python 이고요
다시 연결해야하는 링크주소는 /use/bin/python3.8 입니다
파이썬 2 심볼 삭제 및 파이썬 3 링크 연결하기
1. 파이썬 실행파일 위치를 확인합니다. 기본 yum 으로 설치 했다면 /usr/bin/python 위치로 나타납니다.
which python
2. 파이썬 설치 위치를 모두 찾아냅니다. (저는 파이썬 3를 이미 설치한 상태입니다)
ls -l /usr/bin/python*
3. 기존 심볼릭 링크를 삭제합니다
rm -rf /usr/bin/python
4. 새로운 파이썬 3 폴더로 심볼릭을 생성합니다.
ln -s /usr/bin/python3.8 /usr/bin/python
버전에 따라 3.8이 아닐 수 있으니 꼭 확인하고 자신의 버전에 맞는 폴더로 연결하셔야하합니다.