MacOS 에 illegal hardware instruction 오류가 날 경우 대청 방법
Mac OS X 업데이트 이후 이전에 Brew에서 설치한 프로그램과 충돌이 날 경우 문제가 발생할 수 있음
해결 방법
brew install을 통해서 설치한 항목들을 다시 설치합니다.
$ brew list | xargs brew reinstall -v
Mac OS X 업데이트 이후 이전에 Brew에서 설치한 프로그램과 충돌이 날 경우 문제가 발생할 수 있음
brew install을 통해서 설치한 항목들을 다시 설치합니다.
$ brew list | xargs brew reinstall -v
가장 기초적인 아래의 방법으로 진행을 하게 되면 나처럼 오류가 발생해서 많이 헤매게 될 수 있다
$ sudo apt-get update
$ sudo apt-get install postgresql
RDS를 사용한다면 요즘 기본으로 제일 위에 올라와 있는 버전이 9.6.6일 것이다.
하지만 상기 명령어로 설치를 하게 되면 ubuntu에 설치되는 버전은 9.5.13가 되며 아래와 같은 오류가 발생을 하며 진행이 되지 않을 것이다
pg_dump: server version: 9.6.6; pg_dump version: 9.5.13
pg_dump: aborting because of server version mismatch
하기 명령어를 따라 친다 (ubuntu 16.04 기준)
$ touch /etc/apt/sources.list.d/pgdg.list
$ deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-9.6
자 다 끝났습니다. 아래의 명령어를 입력해 잘 되는지 확인합니다.
$ pg_dump -U 유저이름 -h 호스트주소 디비이름 > ~/원하는위치.sql
계속 상기와 같은 오류가 날 경우 아래의 명령어를 통해 9.5버전을 삭제합니다.
$ sudo apt-get remove postgresql-9.5
http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.upload_file
백업 파일의 경로를 지정해줍니다. (해당 블로그는 /home/ubuntu/db/sql_backup_data/를 경로로 합니다.)
import os
os.system('rm ~/db/sql_backup_data/dump_*sql')
import datetime
now = datetime.datetime.now()
date_str = '_'.join(map(str, [now.year, now.month, now.day]))
os.system('rm ~/db/sql_backup_data/dump_*sql')
backup_command = 'pg_dump -U %s -h %s %s > ~/db/sql_backup_data/dump_%s.sql' % (
유저이름, 호스트 주소, DB이름, date_str
)
os.system(backup_command)
impoty boto3
client = boto3.client(
's3', aws_access_key_id=S3엑세스키,
aws_secret_access_key=S3시크릿엑세스키,
)
client.upload_file(서버의 파일이름, 저장할 버킷이름, S3파일이름)
2번에서 작업 하였던것을 함수화 시킨다
# dbbackup.py
import datetime
import os
import boto3
def db_backup():
now = datetime.datetime.now()
date_str = '_'.join(map(str, [now.year, now.month, now.day]))
os.system('rm ~/db/sql_backup_data/dump_*sql')
backup_command = 'pg_dump -U %s -h %s %s > ~/db/sql_backup_data/dump_%s.sql' % (
유저이름, 호스트 주소, DB이름, date_str
)
file_name = "/home/ubuntu/db/sql_backup_data/dump_%s.sql" % date_str
s3_file_name = "dump_%s.sql" % date_str
os.system(backup_command)
client = boto3.client(
's3', aws_access_key_id=S3엑세스키,
aws_secret_access_key=S3시크릿엑세스키,
)
client.upload_file(서버의 파일이름, 저장할 버킷이름, S3파일이름)
크론탭을 실행한다 $ crontab -e
다음 항목을 추가한다.
0 18 * * * 파이썬경로 프로젝트경로/manage.py shell -c "from dbbackup import db_backup; db_backup()"
앞에는 원하는 날짜 혹은 시간대이며 ec2의 ubuntu의 경우 utc를 이용하기때문에 시간이 9시간 가량 늦다 주의하자!
나처럼 shell에 -c를 이용해 import후 사용을 해도 되며 dbbackup.py에 아래의 항목을 추가 해 해당 파일을 불러올 경우 실행이 되도록하는 것도 가능하다!
if __name__ == '__main__':
db_backup()
PostgreSQL을 백업할때 비밀번호가 필요하여 작업이 안되는 경우가 있다. 아래와 같이 처리를 하면 된다
$ sudo vi ~/.pgpass
# ~/.pgpass
hostaddress:5432:dbname:dbusername:password
$ sudo chown ubuntu ~/.pgpass
$ chmod 600 ~/.pgpass
호스트, DB이름, DB유저이름, 비밀번호를 가진 pgpass라는 파일을 생성 후 user에서 소유권을 준뒤 600권한을 준다음 실행하면 된다.
$ sudo vim /etc/pam.d/chsh auth required pam_shells.so 주석처리sudo chsh $USER -s $(which zsh)웹 서버의 SSL / TLS 인증서를 가져오고 배포하는 사용하기 쉬운 자동화 프로그램
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx
$ sudo certbot --nginx
#nginx
upstream django {
server unix:/home/ubuntu/dev/run/uwsgi.sock;
}
server {
listen 80;
server_name www.bythelaw.co.kr;
# $scheme will get the http protocol
# and 301 is best practice for tablet, phone, desktop and seo
return 301 $scheme://bythelaw.co.kr$request_uri;
}
server {
server_name bythelaw.co.kr;
charset utf-8;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass django;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/bythelaw.co.kr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/bythelaw.co.kr/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = bythelaw.co.kr) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
server_name bythelaw.co.kr;
return 404; # managed by Certbot
}
하기 블로그를 보고 따라서 자동화를 시켰으나 기존에 사용하던 python-certbot-nginx와는 조금 다른 버전인것 같아서 연구가 좀 필요하다
http://riseshia.github.io/2016/10/16/certbot-let-s-encrypt.html