1. pip freeze 로 개발환경 추출
(BlogVenv) C:\Work\Software\eclipse-jee-2019-12-R-win32-x86_64\workspace\Blog>pip freeze > pkg_list.txt
2. CentOS의 임의 폴더에 소스를 ftp로 올린후 virtual environment은 새로 설정한다.
[root@localhost blog.daonelab.com]# virtualenv BlogVenv
[root@localhost blog.daonelab.com]# source BlogVenv/bin/activate
(BlogVenv) [root@localhost blog.daonelab.com]# pip install -r pkg_list.txt
3. 설치중 postgreSQL 설치 오류발생시 pkg_list.txt에서 psycopg2관련 제거 하고 binary버전으로 설치한다.
(BlogVenv) [root@localhost blog.daonelab.com]# pip install psycopg2-binary
4. 설치중 python.h pyconfig.h 없다는 에러 발생은
python3설치시 header(/usr/include/)파일이 저장되지 않았기 때문으로 python3(./configure --includedir=/usr/include) 재설치하고, pip install uwsgi 까지 설치한다.
(BlogVenv) [root@localhost blog.daonelab.com]# pip install uwsgi
4-1. disqus 관련 파일 오류수정 (이전 게시물 참조), 관리자 페이지의 인증(Auth) 관련 post참조하여 수정
https://blog.daonelab.com/post/12/1638/
5. runserver로 일단 시작되는지 테스트 해본다.
(BlogVenv) [root@localhost blog.daonelab.com]# python manage.py runserver 0.0.0.0:8000 --settings=Blog.settings.settings_prd
6. runserver 정상작동한다면 uwsgi로 가동한다. (blog.daonelab.com/Blog/wsgi/wsgi_prd.py)
(BlogVenv) [root@linux blog.daonelab.com]# uwsgi --http :8000 --module Blog.wsgi.wsgi_prd
7. uwsgi를 설정파일로 실행
# vi /home/webapp/blog.daonelab.com/.security/uwsgi.ini
------------------------------------------------------------
[uwsgi]
# Start
# /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
# Stop
# /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --stop /var/run/uwsgi_blog.daonelab.com.pid
# the virtualenv
home = /home/webapp/blog.daonelab.com/BlogVenv
# base directory
chdir = /home/webapp/blog.daonelab.com
# wsgi.py path
module = Blog.wsgi.wsgi_prd
# process-related settings
uid = root
gid = root
master = true
processes = 5
enable-threads = true
pidfile = /var/run/uwsgi_blog.daonelab.com.pid
socket = /tmp/uwsgi_blog.daonelab.com.sock
chmod-socket = 666
chown-socket = root:root
# when stopped uwsgi, auto clean
vacuum = true
# https://uwsgi-docs.readthedocs.io/en/latest/Logging.html#logging-to-files
# 20MB
logger=file:logfile=/home/webapp/blog.daonelab.com/logs/uwsgi.log,maxsize=20971520
log-reopen = true
# By default it is 4k. If you receive a bigger request (for example with big cookies or query string) you may need to increase
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html#buffer-size
buffer-size = 65535 # 16k
------------------------------------------------------------
-- start uwsgi
# /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
-- 브라우저로 확인하고 싶다면.
# /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --http :8000 --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
8. uwsgi service 등록
# vi /usr/lib/systemd/system/blog.daonelab.com.service
------------------------------------------------------------
[Unit]
Description=blog.daonelab.com`s uWSGI Service
After=postgresql-12.service
[Service]
ExecStart=/home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
------------------------------------------------------------
[root@linux ~]# ln -s /usr/lib/systemd/system/blog.daonelab.com.service /etc/systemd/system/multi-user.target.wants/blog.daonelab.com.service
[root@linux ~]# systemctl daemon-reload
[root@linux ~]# systemctl enable blog.daonelab.com.service <-- .service 는 생략해도 된다.
[root@linux ~]# systemctl start blog.daonelab.com.service
[root@linux ~]# systemctl status blog.daonelab.com.service
[0m blog.daonelab.com.service - blog.daonelab.com's uWSGI Service
Loaded: loaded (/usr/lib/systemd/system/blog.daonelab.com.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-05-21 00:50:30 KST; 7min ago
Main PID: 1464 (uwsgi)
Status: "uWSGI is ready"
CGroup: /system.slice/blog.daonelab.com.service
쒋1464 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
쒋2659 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
쒋2660 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
쒋2662 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
쒋2665 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
붴2666 /home/webapp/blog.daonelab.com/BlogVenv/bin/uwsgi --ini /home/webapp/blog.daonelab.com/.security/uwsgi.ini
9. Nginx 설치
https://blog.daonelab.com/post/35/1640/
10. uWSGI와 연동하기 위한 conf 파일 작성 (/etc/nginx/nginx.conf 파일에서 include한다.)
[root@linux conf.d]# pwd
/etc/nginx/conf.d
[root@linux conf.d]# cp default.conf default.conf.bak
[root@linux conf.d]# mv default.conf /home/webapp/blog.daonelab.com/.security/nginx_default.conf
[root@linux conf.d]# ln -s /home/webapp/blog.daonelab.com/.security/nginx_default.conf default.conf
[root@linux conf.d]# vi /home/webapp/blog.daonelab.com/.security/nginx_default.conf
------------------------------------------------------------
# https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html?highlight=charset#configure-nginx-for-your-site
# https://docs.nginx.com/nginx/admin-guide/web-server/app-gateway-uwsgi-django/
upstream django {
server unix:/tmp/uwsgi_blog.daonelab.com.sock;
}
server {
listen 8000;
server_name localhost;
charset utf-8;
root /home/webapp/blog.daonelab.com;
# max upload size
client_max_body_size 100M;
#access_log /var/log/nginx/blog.daonelab.com_access.log;
#error_log /var/log/nginx/blog.daonelab.com_error.log;
location = favicon.ico {access_log off; log_not_found off;}
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
location /static {
alias /home/webapp/blog.daonelab.com_static;
access_log off;
expires 1M;
add_header Cache-Control "public";
}
}
------------------------------------------------------------
11. Collect Static file
(BlogVenv) [root@linux blog.daonelab.com]# python manage.py collectstatic --settings=Blog.settings.settings_prd
12. restart uWSGI & nginx service
[root@linux ~]# systemctl restart blog.daonelab.com.service
[root@linux ~]# systemctl restart nginx
13.
[root@linux conf.d]# netstat -anp | grep 8000
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 38445/nginx: master