vue + django before and after the end of the project deployment

The installation of a .python3

1. Installation database environment before Python: 
yum the install Python devel-GCC-Patch libffi devel zlib bzip2-devel-devel-devel OpenSSL the ncurses-devel SQLite the readline-devel devel-TK-gdbm-devel devel devel-DB4 the libpcap an xz-devel -Y -devel 

2. download, extract the installation source package 
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tar.xz 
an xz -d-3.6.9.tar the Python .xz 
the tar-3.6.9.tar -xf the python 

3. compiled and installed into the python source package directory 
./configure --prefix = / opt / python3 / 
the make the make the install && 

4. configuration python3 environment variables 
in the / etc / profile The last line add 
export PATH = / opt / python3 / bin: $ PATH 
and 
source / etc / profile

 

Two: to create a virtual environment management and installation of virtualenvwrapper

1. Specify watercress accelerator installation virtualenvwrapper, of course, also be mounted directly 
PIP3 the install -i https://pypi.douban.com/simple virtualenvwrapper 

2. Modify ~ / .bashrc, each boot loading virtualevnwrapper, of course, arranged in / etc / profile no problem 
writing variable 
export WORKON_HOME = ~ / Envs # set virtualenv unified management directory 
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS = '- no-site -packages' # virtualenvwrapper add parameters to generate a clean environment isolated 
export VIRTUALENVWRAPPER_PYTHON = / opt / python3 / bin / python3.6 # Specifies the python interpreter 
source /opt/python3/bin/virtualenvwrapper.sh # virtualenvwrapper execute the installation script 

3. create a virtual environment my_django_first_project (which creates my_django_first_project folders in ~ / Envs in) 
mkvirtualenv my_django_first_project 

NOTES virtualenv related commands (no need to perform below): 
delete the virtual environment 
rmvirtualenv my_django_first_project 
activates the virtual environment
workon my_django_first_project 
can also stop a virtual environment manually 
deactivate my_django_first_project 
enumerate all the environmental 
lsvirtualenv


Three: Vue deployment (deployed on my_django_first_project virtual environment)

Front and rear 1.xftp uploaded to the server-side code 

2. Prepare node pack environment, download node binary package, this package already contains node, do not need to compile 
wget https://nodejs.org/download/release/v8.6.0/node- x64.tar.gz-Linux-V8.6.0 

3. decompressor node packages 
the tar-V8.6.0 -zxvf-node Linux-x64.tar.gz 

4. configure the environment variables, modify the / etc / profile, and can be used directly npm node command to 
the PATH the PATH = $: /opt/node-v8.6.0-linux-x64/bin 

5. the node detection and NPM 
node -v 
NPM -v 

package mounting vue desired item 6. 
cd / opt / software / vue_project 
input npm install, and then followed after completion of the input 

7. prepare vue compiler package item, all addresses replace the configuration file, the address to the server 
sed -i 's / 127.0.0.1 / xxx.xxx.xxx.xxx / g' / opt / software /vue_project/src/restful/api.js 

8. the vue ensure that the route model is history 
/opt/software/vue_project/src/router/index.js the mode: 'history', // change history pattern

9.npm run build a dist package generated static file directory, the front end of the project content and index.html are here 


5. Wait nginx load the dist folder

 

Four: the deployment environment required for back-end code

1. Activate the virtual environment 
workon my_django_first_project 

2. one command, all packages dependent on the export of local 
PIP3 Freeze> requirements.txt 
	
3. This requirements.txt will spread to the server, the new server in a virtual environment, install this file, You will be able to install all the packages 
PIP3 install -r requirements.txt   	 
		
4. uwsgi ready to support high concurrent start python project (note uwsgi Unable to parse static files, have to deal with static files nginx) 
	1. installation uwsgi 
	PIP3 install https://pypi.douban.com/simple uwsgi -i 

	2. uwsgi learn to use (Note: you can use the following simple start, the project started with a general profile start) 
		by uwsgi start a python web file 
		uwsgi --http : 8000 --wsgi-file testuwsgi.py 
				--http specify the http protocol 
				--wsgi-file specifies a python file 
			
		to start django project by uwsgi, and supports thermal loads project, the project does not restart automatically take effect the new back-end code 
			
		uwsgi - -http: 8000 --module django_project.wsgi --py-autoreload = 1
		
				--module find the specified file django project wsgi.py 
				--py-autoreload = 1 heat load 
					
					
	3. uwsgi configuration file, start the project 
		1. Create a uwsgi.ini configuration file, write parameter information 
			Touch uwsgi.ini 
									
			[ uwsgi] 
			# Django-Related Settings 
			# at the Base Directory (Full path) 
			of the first layer path absolute path # specified item (very important) 
			chdir = / opt / python_project / qkyAdmin 

			# Django's WSGI file 
			wsgi.py file specified item # 
			# write to a relative path, this parameter is the parameter is a relative path chdir 
			Module = qkyAdmin.wsgi 

			# at the virtualenv (Full path) 
			# write the absolute path to the virtual environment interpreter (cdvirtualenv can jump directly enter, then you can pwd See absolute path) 
			Home = / the root / Envs that / my_django_first_project 

			# Process-Related Settings 
			# Master 
			Master to true =

			Number of maximum worker Processes # 
			# uwsgi process started a specified number (it may be configured to write the machine multipoint)			 
			Processes. 5 = 

			# The socket (The Full path to use BE Safe 
			#socket refers to: start a uwsgi socket connection, when you use nginx + uwsgi, the use of socket parameters 
			socket = 0.0.0.0:9000 

			# this parameter is uwsgi start an http connection, when you do not just use nginx uwsgi when using this parameter 
			#http = 0.0.0.0:9000 

			Appropriate with the Permissions ... # - May BE needed 
			# chmod-socket = 664 
			# Environment ON Exit the Clear 
			Vacuum = to true 
			
			# backstage start 
			daemonize = yes 
					
		2. use uwsgi configuration file to start the project 
		uwsgi --ini uwsgi.ini


Five .supervisor process management tools to install and use

Introduction: The linux process runs in the background of what method (extended knowledge) 
			first, followed by the ampersand command 
			python manage.py runserver & 
			
			second use nohup command 
			nohup python test.py 

			third use process management tools 
	
	Note: As the supervisor is not available in python3, and therefore can only be used to download python2 
	2. installation supervisor, use python2 package management tool easy_install (note, this time to exit the virtual environment) 

	if there is no command, use the following command to install 
	yum install setuptools-Python 
	easy_install Supervisor 

	3. command, generate a configuration file that is written to the task you want to manage the process 
	echo_supervisord_conf> /etc/supervisor.conf 

	4. edit the configuration file, writes django project command 
	vim / etc / supervisor.conf   
	directly to the bottom line, is written as follows 
	5. the start supervisord server, designated profile start 
	[program: django_project] # is configured parameter management process, django_project is the name of the process
	= Command / the root / Envs that / my_django_first_project / bin / /opt/python_project/qkyAdmin/qkyAdmin/uwsgi.ini to uwsgi --ini

	-c /etc/supervisor.conf supervisord 

	6. By supervisorctl management tasks 
	/etc/supervisor.conf supervisorctl -c 

	7.supervisor management process django command as follows 
	supervisorctl direct input into the interactive command interface 
	> STOP django_project 
	> Start django_project 
	> Status django_projecty 
	> # stop all all Status 
	

	rear luffy 8. start Code (here, the following settings need to be modified aLLOWED_HOSTS = [ '*'], allow everyone access) 
	start django_project

 

VI. Nginx configuration steps

1. compiler installation Nginx 
	2.nginx.conf arranged as 

	# a first virtual server host is to find the vue dist file index.html found in dist 
	server { 
			the listen 80; 
			server_name 192.168.0.104; 
			
			# when a request comes from 192.168 .0.104 / time, go directly to the following location, and then find vue of dist / index.html 
			LOCATION / { 
				root / opt / python_project / lf_project / dist; 
				index index.html; 
				# this is a parameter to ensure vue page refreshes, does not page 404 appears 
	      	try_files $ $ URI URI / /index.html; 
			} 
			
		} 
		
	# because the data address of the interface is sent vue 192.168.0.104:8000 we have prepared a further inlet Server 
	Server { 
		the listen 8000; 
		server_name 192.168.0.104; 
		
		# when upon receiving the interface data, the request proceeds as follows url is 192.168.0.104:8000 LOCATION 
		LOCATION / { 
			# here nginx port 9000 to forward the request to start uwsgi
			192.168.0.104:9000 uwsgi_pass; 
			# is the include a "into the role", the parameter is outside of a file, into the nginx.conf takes effect in 
			the include / opt / nginx1-12 / the conf / uwsgi_params; 
		} 
	} 




	. 3. start nginx 
	./sbin/nginx direct start 
	can now access the 192.168.0.104 view the page results 




indicate: mysql and redis modify settings inside according to their own addresses can be configured

 

Guess you like

Origin www.cnblogs.com/leixiaobai/p/11309601.html