티스토리 뷰

INTRO

OS, python, django, nginx, MariaDB 환경

[Raspberry Pi : server]

Raspbian : GNU/Linux 10 (buster)

python 3.7.3

django 2.2.6

nginx 1.14.2

mysql V15.1 Distrib 10.3.17-MariaDB

## Version 확인 방법

## Raspberry Pi : server
# Raspbian console에서 확인

## python 3.7.3
$ python3 -V

## nginx 1.14.2
$ nginx -v

## mysql V15.1 Distrib 10.3.17-MariaDB
$ mysql -V

 

1. DB/USER 생성 및 권한 부여 in MariaDB : NewDB -> yourID/yourPASS -> DB 권한 부여

## Raspberry Pi console ##

$ sudo mysql -u root
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

MariaDB [(none)]> create database NewDB;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| NewDB              |
| mysql              |
| performance_schema |
+--------------------+

MariaDB [(none)]> create user 'yourID'@'%' identified by 'yourPASS';
Query OK, 0 rows affected (0.009 sec)

MariaDB [(none)]> grant all privileges on NewDB.* to yourID@'%';
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit
Bye

## NewDB 접속 및 확인
$ sudo mysql -u yourID -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| NewDB              |
+--------------------+


## 생성된 user는 mysql DB의 host table에서 확인할 수 있다.
MariaDB [(none)]> use mysql
MariaDB [mysql]> select host, user from mysql.user;
+-----------+-------------------+
| host      | user              |
+-----------+-------------------+
| %         | yourID            |
| localhost | root              |
+-----------+-------------------+

 

2. virtualenvwrapper를 이용한 가상환경 설정

Raspberry Pi Raspbian 최신 상태로 만들기 : apt(Advanced Packaging Tool) update/upgrade

*apt는 apt-get, apt-cache를 대체하는 high-level 고급 package 관리도구

## Raspberry Pi console ##

## package & version list update
$ sudo apt update
## package upgrade from update-list
$ sudo apt upgrade
## Raspberry Pi console ##

$ sudo apt install python3-pip
$ sudo pip3 install virtualenv
$ sudo pip3 install virtualenvwrapper


## virtualenvwrapper 환경변수 설정 : ~/.bashrc 끝단에 다음 설정을 추가한다.
--nanoEditor ~/.bashrc
....
# python virtualenv settings
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh


$ mkvirtualenv jbe
(jbe)$ cd ~/.virtualenvs/jbe

 

3. django 설치, jinozpiblog project 생성 및 settings.py 수정

## Raspberry Pi console ##

(jbe)$ python3 -m pip install --upgrade pip
(jbe)$ pip install django==2.2.6
(jbe)$ django-admin.py startproject jinozpiblog
(jbe)$ sudo apt install tree
(jbe)$ cd jinozpiblog
(jbe)$ tree
.
├── jinozpiblog
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py
--nanoEditor : jinozpiblog/setting.py
....
DEBUG = True

ALLOWED_HOSTS = ['외부접속 공인 IP']
....

DATABASES = {
    'default': {
        #'ENGINE': 'django.db.backends.sqlite3',
        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'NewDB',
        'USER': 'yourID',
        'PASSWORD': 'yourPASS',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}
....
LANGUAGE_CODE = 'ko' #default 'us-en'
TIME_ZONE = 'Asia/Seoul' #default ' UTC'
....

# webserver staticfiles
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# runserver staticfiles
STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static'),
]

# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
MEDIA_URL = '/media/'
## Raspberry Pi console ##
## staticfile 모으기 실행

(jbe)$ mkdir static
(jbe)$ mkdir media
(jbe)$ python3 manage.py collectstatic

.
├── jinozpiblog
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── static
├── staticfiles
│   └── admin
├── media
└── mediafiles

 

 

4. django project migrate 및 django-congraturation page 확인

## Raspberry Pi console ##

(jbe)$ pip install mysqlclient
(jbe)$ python3 manage.py showmigrations
admin
 [ ] 0001_initial
 [ ] 0002_logentry_remove_auto_add
 [ ] 0003_logentry_add_action_flag_choices
auth
 [ ] 0001_initial
 [ ] 0002_alter_permission_name_max_length
 [ ] 0003_alter_user_email_max_length
 [ ] 0004_alter_user_username_opts
 [ ] 0005_alter_user_last_login_null
 [ ] 0006_require_contenttypes_0002
 [ ] 0007_alter_validators_add_error_messages
 [ ] 0008_alter_user_username_max_length
 [ ] 0009_alter_user_last_name_max_length
 [ ] 0010_alter_group_name_max_length
 [ ] 0011_update_proxy_permissions
contenttypes
 [ ] 0001_initial
 [ ] 0002_remove_content_type_name
sessions
 [ ] 0001_initial


(jbe)$ python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK
## Raspberry Pi console ##
## uwsgi를 이용한 port 연결

(jbe)$ pip3 install uwsgi

(jbe)$ uwsgi --http 외부접속고정IP:9800 --home /home/jinozraspi/.virtualenvs/jbe/ --chdir /home/jinozraspi/.virtualenvs/jbe/jinozpiblog --module jinozpiblog.wsgi

*** Starting uWSGI 2.0.18 (64bit) on [Fri Dec  6 14:58:48 2019] ***
compiled with version: 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.12) on 06 December 2019 04:09:01
os: Darwin-19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64

 

- browser : 외부접속 공인아이피:9800

 

-----------이하 참고-----------

(참고) mysql vs MariaDB Raspberry Pi 설치 상태 확인

## Raspberry Pi console ##

$ apt-cache show mysql-server mysql-client

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  mariadb-server-10.0


Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mysql-client is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  mariadb-client-10.0


$ apt-cache show mariadb-server mariadb-client
Package: mariadb-server
Source: mariadb-10.3
Version: 1:10.3.17-0+deb10u1
....
Package: mariadb-client
Source: mariadb-10.3
Version: 1:10.3.17-0+deb10u1
....

$ sudo apt build-essential checkinstall

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함