CentOS 7+python 3+django+nginx+uwsgi deployment

Now I want to deploy django on a centos7 to learn the django framework. I find that most of the data of django are Python 3, and python 2 is gradually transitioning to Python 3. After searching a lot of data, I have successfully built an environment to record, which is convenient for future searches.

 

The environment is the newly installed version of CentOS 7 1810 mini

The main steps are as follows.

1. Compile and install Python 3

2. Installing django and uwsgi

3. Installing nginx

4. Adjusting Details

 

Initial pre-installation environment

Before deployment, we need to pre-install some software. It is recommended that the source of yum be replaced by domestic source at the beginning, so that the download will be faster.

yum -y install vim rsync lrzsz openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ libxml* mlocate dos2unix

updatedb

 

Compile and install Python 3

Because of the network, downloading Python 3 installation packages may be slow, you can use software such as Thunderbolt to download well, and then upload back to the server, which will be a little more efficient.

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar -zxvf Python-3.6.3.tgz
cd Python-3.6.3
./configure --prefix=/usr/local/python3
make -j2
make install -j2


ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

Install django and uwsgi

pip3 install django uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3

Install nginx

wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -zxvf nginx-1.13.7.tar.gz
cd nginx-1.13.7
./configure
make
make install

Adjust details

Create django-admin soft chain

ln -s /usr/local/python3/bin/django-admin /usr/local/bin

 

Install and upgrade sqlite3

wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
tar -zxvf sqlite-autoconf-3270200.tar.gz
cd sqlite-autoconf-3270200
./configure --prefix=/usr/local
make && make install

mv /usr/bin/sqlite3  /usr/bin/sqlite3_old
ln -s /usr/local/bin/sqlite3   /usr/bin/sqlite3
echo "export LD_LIBRARY_PATH=\"/usr/local/lib\"" >> ~/.bashrc
source ~/.bashrc

 

So far, the whole deployment has been completed. In the whole process, the installation packages of those wget are downloaded very slowly. There are no other problems on the whole.

 

For the new initial environment, I also provide a one-click shell script, which can be deployed directly. In order to avoid the slow download of wget, you can download the installation package first, then create soft in the / root directory, drop the installation package into software, and sh executes the script.

#!/bin/bash

echo -e "\n Start configuring the environment\n"
echo -e "Start replacing yum Domestic sources\n"
if [[ $(rpm -qa | grep wget) ]]; then
    echo -e "wget Installed, proceed to the next step\n"
else
    yum -y install wget
fi

if [ ! -d "/root/soft" ]; then
    echo -e "soft Directory does not exist, create directory/root/soft \n"
    mkdir /root/soft
else
    echo -e "\n/root/soft The directory exists and executes the next step\n"
fi

# Compare yum sources to whether they have been replaced
yum1=$(md5sum /etc/yum.repos.d/CentOS-Base.repo | awk '{print $1}')
if [[ ! -f /root/soft/Centos-7.repo ]]; then
    wget -P /root/soft http://mirrors.aliyun.com/repo/Centos-7.repo
fi
echo -e "yum Domestic Source Downloaded, Matching Check......\n"
yum2=$(md5sum /root/soft/Centos-7.repo | awk '{print $1}')
if [[ $yum1==$yum2 ]]; then
    echo -e "Host yum Sources are domestic sources and need not be replaced\n"
else
    echo -e "Replacing yum Domestic sources\n"
    cp /root/soft/Centos-7.repo /etc/yum.repos.d/
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
    mv /etc/yum.repos.d/Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo
    yum clean all
    yum makecache
    yum -y update
    echo -e "\nyum Domestic Source Replacement Completion\n"
fi

echo -e "Start deployment django\n"
# Installation environment
yum -y install vim rsync lrzsz openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ libxml* mlocate dos2unix

updatedb

# Install Python 3
if [[ ! -f /root/soft/Python-3.6.3.tgz ]]; then
    wget -P /root/soft https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
fi
cd /root/soft
tar -zxvf Python-3.6.3.tgz
cd Python-3.6.3
./configure --prefix=/usr/local/python3
make -j2
make install -j2

# Creating a Soft Chain
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

# Replacement of pip's domestic sources
cd ~
mkdir .pip
cd .pip
cat>pip.conf<<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
EOF

cd ~

# Install django and uwsgi
pip3 install django uwsgi

# Creating a Soft Chain
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3

# Install nginx
cd ~/soft
if [[ ! -f /root/soft/nginx-1.13.7.tar.gz ]]; then
    wget http://nginx.org/download/nginx-1.13.7.tar.gz
fi

tar -zxvf nginx-1.13.7.tar.gz
cd nginx-1.13.7
./configure
make
make install

# Create django-admin soft chain
ln -s /usr/local/python3/bin/django-admin /usr/local/bin

# Install and upgrade sqlite3
cd ~/soft
if [[ ! -f /root/soft/sqlite-autoconf-3270200.tar.gz ]]; then
    wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
fi

tar -zxvf sqlite-autoconf-3270200.tar.gz
cd sqlite-autoconf-3270200
./configure --prefix=/usr/local
make && make install

mv /usr/bin/sqlite3  /usr/bin/sqlite3_old
ln -s /usr/local/bin/sqlite3   /usr/bin/sqlite3
echo "export LD_LIBRARY_PATH=\"/usr/local/lib\"" >> ~/.bashrc
source ~/.bashrc

echo "Deployment completed"

 

Keywords: Python yum Django Nginx

Added by terandle on Wed, 14 Aug 2019 10:07:48 +0300