Library management system deployment, installation configuration redis database, uWSGI order to learn and use, installation and use of supervisor tools

Familiar with the linux operating

cat / etc / redhat-release version of the system to see 
CAT / etc / os-view system version Release

 

2. Configure source cloud Ali

All repo Backup 2.1

cd /etc/yum.repos.d
mkdir repobak
mv * repobak/

2.2 Download Ali cloud sources and epel extended source

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.3 yum empty cache buffer and generates a new yum

3. Upload library management system project

4. Installation interpreter python3

##### Note 1: You must install the database environment 
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4 libpcap-devel the xz--devel devel ##### Note 2: configuration environment variable / etc / profile, python3 variables must be top priority

5. Install a virtual environment virtualenv

5.1 Installing the Virtual Environment

pip3 install -i https://pypi.douban.com/simple virtualenv

6. Install virtualenvwrapper tool

6.1 Download and install virtualenvwrapper

pip3 install -i https://pypi.douban.com/simple virtualenvwrapper

6.2 Configure user environment variable configuration file

vim ~/.bashrc

Add the following at the end:

export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
export VIRTUALENVWRAPPER_PYTHON=/opt/python36/bin/python3
source /opt/python36/bin/virtualenvwrapper.sh

6.3 Overload user environment variable configuration file

source ~/.bashrc

6.4 library management system to create a virtual environment

mkvirtualenv book_manage

 

7. Install the database and import data

Under centos7 complete installation configuration mariadb database, and create database data, migrate data import knight
In centos7, mariadb is mysql database, just a different package name

7.1 download mariadb

yum install -y mariadb-server mariadb

7.2 initialization mysql

# First start MariaDB 
systemctl MariaDB Start # is initialized again mysql_secure_installation # set the root password using the set directive: MariaDB [(none)]> the SET password for 'root' @ 'localhost' = password ( 'NewPassword');   MariaDB [( none)]> exit;






7.3 Configuring Chinese support

/Etc/my.cnf modify the configuration file, add the following configuration

Modify /etc/my.cnf.d the server and client configuration

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
log-error=/var/log/mysqld.log
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

Mariadb need to restart the service after the 7.4 configuration

systemctl restart mariadb

Log on linux 7.5 mariadb

mysql -uroot -p

7.6 connected to the rear end root user program django

# If you are using django other users to connect back-end program, you will need to re-create user and authorization # 1. Create user create user 'tiger' @ '% ' identified by '123456'; #% represent all hosts # 2. Authorizes users Grant All privileges ON * * to Tiger @ '%' IDENTIFIED by '123456';. # 3. refresh the grant tables flush privileges






7.7 Refresh Authorization Form

7.7.1 Export library management system project database
mysqldump -u root -p --all-databases > /opt/book_manage.sql
7.7.2 linux upload the data files to the database
7.7.3 In the linux mysql, import the data file
source /opt/book_manage.sql

Note 1, linux database, you need to set up a remote link to the root user's permissions, the password is redhat

Note, SELinux and linux firewall to give closed, otherwise windows to linux link port 3306 may be denied !!!!!

Note, SELinux and linux firewall to give closed, otherwise windows to linux link port 3306 may be denied !!!!!

Note, SELinux and linux firewall to give closed, otherwise windows to linux link port 3306 may be denied !!!!!

 

8. Installation Configuration Database redis

8.1 Download and install redis

wget http://download.redis.io/releases/redis-5.0.2.tar.gz
tar -zxvf redis-5.0.2.tar.gz
cd redis-5.0.2
make && make install

8.2 Preparation redis profile

mkdir -p /opt/redis_conf
touch /opt/redis_conf/redis-6379.conf
vim /opt/redis_conf/redis-6379.conf

8.3 redis add the following configuration in the configuration file

port 6379
daemonize yes
pidfile /data/6379/redis.pid
loglevel notice
logfile "/data/6379/redis.log"
dir /data/6379
protected-mode yes

8.4 Create a data file

mkdir -p /data/6379

8.5 start redis

redis-server /opt/redis_conf/redis-6379.conf

 

9. solve several problems of project start

python manage.py runserver 0.0.0.0:8000
The test uses linux python interpreter to run the project to switch to the project running (Note To solve the problem interpreter module to the normal operation of the project), when you start django experience the following problems:

9.1 Import error configuration error

File "/opt/Envs/book_manage/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
  raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
Solution:
# Modify the file if the judge sentences 36 rows, you can direct comments

9.2 error coding errors

File "/opt/Envs/book_manage/lib/python3.6/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
  query = query.decode(errors='replace')
Solution:
The document was changed to encode 146 to decode the original line

9.3 SQLite error error

File "/root/Envs/book_manage/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 65, in check_sqlite_version
  raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

Solution

Comment out this given file function block, and add to pass

9.4 configuration settings files, such as configuration ALLOW_HOSTS

ALLOW_HOSTS = ["*"]

9.5 modify the settings file, modify the cross-domain configuration

CORS_ORIGIN_WHITELIST = (
  'http://10.0.0.5',
)

 

10. Complete uWSGI order to learn and use

10.1 uWSGI start using the library management system project, supports multi-process

10.2 pip module mounting uwsgi

pip3 install uwsgi

Hello world test of 10.3 uwsgi

Referring to blog https://www.cnblogs.com/tiger666/articles/10313069.html installed inside uwsgi forum

Create a test file testuwsgi.py, run a simple uWSGI site

10.3.1 Create a file vim /opt/testuwsgi.py writes the following
def application(env, start_response):
  start_response('200 OK', [('Content-Type','text/html')])
  return [b"Hello World"]
10.3.2 Use this command to start the file uwsgi
uwsgi --http :9000 --file testuwsgi.py
10.3.3 browser access through IP and Port
http://10.0.0.5:9000

10.4 uwsgi.ini configuration file

(Manage.py same level directory) to create this file in the root directory of the project django

[uwsgi] 
# use Connect using nginx, Django server address where the program
# socket = 0.0.0.0: 9000
# directly do use the web server, Django server address where the program
HTTP = 0.0.0.0: 9000
# project directory
chdir = / opt / book_manage
# project directory wsgi.py file, relative to the project directory
WSGI-file = LIB / wsgi.py
# number of processes
processes = 1
# number of threads
threads = 2
role # uwsgi server
Master = True
# number of files stored process
= uwsgi.pid the PidFile
# log file because uwsgi from the terminal can run in the background, invisible to the log. Our previous runserver is dependent on terminal
# If the supervisor tools enabled, this line comments
daemonize = uwsgi.log
# specified dependency virtual environment
virtualenv = / root / Envs / book_manage_env
Note: Currently being first with http, if using nginx, then you need to comment http, enabled socket

10.5 uwsgi command to start the program django

--This uwsgi /opt/book_manage/uwsgi.ini

Problem started after 10.6 uwsgi inaccessible solve

Modify the project inside wsgi.py files, configuration settings point to dev.py

vim /opt/book_manage/book_manage/wsgi.py

Modify the configuration file

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'book_manage.settings')

10.7 uwsgi not static files

uwsgi itself support high-concurrency, multi-process, which is its advantage

Disadvantages: can not handle static files

11 django collection of static files

Since uwsgi poor treatment of static files, static files nginx however, it is the number one, so we also need to deploy the project to use in conjunction with nginx

11.1 django set of static files directory and collect, open mysite / settings.py, join this one configuration:

STATIC_ROOT = '/ opt / book_manage / static' # in STATIC_URL = '/ static /' arranged above this line plus 
STATIC_URL = '/ static /'
STATICFILES_DIRS = [
  the os.path.join (base_dir, "static"),
]

So, with the above-mentioned parameters STATIC_ROOT Where? look down

11.2 save all the static files you use to collect STATIC_ROOT by python3 manage.py collectstatic

manage.py collectstatic python3 # STATIC_ROOT folder is used for all STATICFILES_DIRS all files in the folder, as well as the static app files are copied # put these documents in order to put together when deployed with nginx, etc. more convenient


11.3 Viewing django collection of static files directory

ls /opt/book_manage/static

 

12. Complete the installation and configuration nginx nginx

Nginx complete library management system project handling static files, and back-end interface configuration

12.1 nginx.conf profile details

server {
  listen       80;
  server_name 10.0.0.5;
  #charset koi8-r;
  #access_log logs/host.access.log main;

  location / {
      include uwsgi_params;
      uwsgi_pass 0.0.0.0:9000;
  }
  location /static {
      root   /opt/book_manage;
  }
  error_page   500 502 503 504 /50x.html;
  location = /50x.html {
      root   html;
  }
}

Web Hosting: 80 port for accepting a request initiated by the user, the reverse proxy forwards the application to the uwsgi 9000, while the back-end processing of static static files

After 12.2 nginx configuration and start good, and then enable uwsgi.ini profile inside the socket and disable http configuration

[uwsgi] 
# use Connect using nginx, Django server address where the program
socket = 0.0.0.0: 9000
# directly do use the web server, Django server address where the program
# HTTP = 0.0.0.0: 9000
# project directory
chdir = / opt / book_manage
# project directory wsgi.py file, relative to the project directory
WSGI-file = book_manage / wsgi.py
# number of processes
processes = 2
# number of threads
threads = 2
role # uwsgi server
Master = True
# number of files stored process
= uwsgi.pid the PidFile
# log file because uwsgi from the terminal can run in the background, invisible to the log. Our previous runserver is dependent on terminal
# If the supervisor tools enabled, this line comments
daemonize = uwsgi.log
# specified dependency virtual environment
virtualenv = / root / Envs / book_manage

13. Test with nginx uwsgi

Test started manually uwsgi with nginx, to ensure access to normal

13.1 Start uwsgi

/root/Envs/book_manage/bin/uwsgi /opt/book_manage/uwsgi.ini

13.2 Graceful Restart nginx

/opt/nginx116/sbin/nginx -s reload

Solutions 13.3 project can not be accessed (important index ** ** ** ** ** ** ** ** )

1 Turn off nginx, then close uwsgi, direct use python manage.py runserver command starts django project 
2 closed just started django, using uwsgi the project up and running, using the 9000 port access, verify normal
3 commented uwsgi profile http, enable the socket, and then start uwsgi, then start nginx, then visit
http://10.0.3.156

14 Installation and use supervisor tools

The concept of 14.1 supervisor

supervisor is a python-based task management tool used to automatically run a variety of background tasks, of course, you can directly use the nohup command makes the task automatically run in the background, but if you want to restart the task, each task to manually kill off the process, so it is cumbersome, but once the program error caused the process to exit, the system can not automatically reload task.

14.2 Installation

As the supervisor is not available in python3, and therefore can only be used python2 to download! ! ! ! ! !

As the supervisor is not available in python3, and therefore can only be used python2 to download! ! ! ! ! !

As the supervisor is not available in python3, and therefore can only be used python2 to download! ! ! ! ! !

easy_install supervisor # This is python2 the following command to install modules, equivalent to python3 following pip if easy_install command is not available, then it is about to install python-setuptools tools to yum install python-setuptools


14.3 Use command to generate supervisor profile

echo_supervisord_conf > /etc/supervisord.conf

14.4. Modify Profile /etc/supervisord.conf

Add the following configuration at the end of the file:

[Program: book_manage] 
the Command = / root / Envs / book_manage / bin / uwsgi /opt/book_manage/uwsgi.ini
stopasgroup = to true
killasgroup = to true
# If you find that after closing supervisor process, the end of the invalid uwsgi process, you need to add two parameters

14.5. Start supervisor tool

supervisord -c /etc/supervisord.conf

14.6 Check the status of supervisor

supervisorctl

supervisor interactive mode basic operation commands

start the process name # boot process 
stop process name # to stop the process
start all # start all processes
stop all # start all processes

14.7 supervisor startup command parameters

# Task Management command as follows: There are two, one is the argument in the form of an interactive 
# parametric form  
supervisord -c /etc/supervisor.conf STOP / Start / restart All
supervisord -c /etc/supervisor.conf Start qishi8 # interactive forms supervisord -c /etc/supervisor.conf


14.8 reload supervisor (to understand)

First, after adding a good profile Second, update the new configuration to supervisord     supervisorctl Update Third, restart all program configuration supervisorctl reload four starts a process (program_name = you write the configuration program name) supervisorctl start program_name five are waiting to see the process of supervisorctl six or stop a process (program_name = you write the configuration program name) supervisorctl sTOP program_name seven reboot (you write the configuration program name program_name =) a process supervisorctl restart program_name eight, stop all processes supervisorctl stop all Note: stop off the display stop the process will not automatically restart with reload or update.






















 

Guess you like

Origin www.cnblogs.com/youhongliang/p/12130797.html