项目部署
程序员文章站
2022-06-11 10:06:03
...
1. 安装python(centos)
1.1 下载python包
官网下载地址,找到对应版本的tar包下载链接
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
1.2 解压
tar -xvf Python-3.6.5.tgz
1.3 指定安装路径
cd Python-3.6.5
./configure --prefix=/usr/local/python3
1.4 安装依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
1.5 安装
make && make install
1.6 创建软连接 或 加入环境变量
cd /usr/local/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
或
cd ~ vim .bash_profile
PATH=...:/usr/local/python3/bin
source .bash_profile // 重新加载一下
2. 安装配置mysql
2.1 安装
centos下
yum -y install mariadb mariadb-server
ubuntu下
apt install mysql-server mysql-client
2.2 配置mariadb
2.2.1 初次配置
mysql_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
mysql -u root -p
Enter password: // 输入密码,不显示
完成。
2.2.2 设置远程连接
ubuntu下
a. 查找配置文件 mysql.conf
find / -name mysql.cnf
b. 注释mysql.cof文件的bind_address
设置远程连接
mysql -u root -p password
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '[email protected]' WITH GRANT OPTION;
2.3 启动mysql
systemctl start mariadb
service start mysql
3. 部署
3.1 安装 UWSGI 和 NGINX
pip安装请使用对应python环境中的pip进行安装
ubuntu下
安装pip3
apt install python3-pip
sudo apt-get install nginx
pip3 install uwsgi
centos下
pip install uwsgi
yum install nginx
3.2 安装必备库
pip install django==1.11
pip install pymysql
pip install Pillow
3.3 配置nginx
a. 自定义配置文件
mkdir -p /home/app/conf/
touch /home/app/conf/axf_nginx.conf
b. 配置自定义的nginx配置文件
cd axf_nginx.conf
django配置
server {
listen 80;
server_name 118.25.211.249;
access_log /home/app/log/access.log;
error_log /home/app/log/error.log;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8890;
}
location /static/ {
alias /home/app/src/axf/static/;
expires 30d;
}
}
flask配置
server{
listen 80;
server_name 47.106.171.187 localhost;
access_log /home/app1/log/access.log;
error_log /home/app1/log/error.log;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_param UWSGI_CHDIR /home/app1/src/aj;
uwsgi_param UWSGI_SCRIPT manage:app;
}
}
c. nginx配置文件加载自定义配置文件
vim /etc/nginx/nginx.conf
在server中加入以下配置:
include /home/app/conf/*.conf;
centos中nginx配置文件有一个server,注释掉
3.4 配置uwsgi
touch /home/app/conf/uwsgi.ini
vim uwsgi.ini
django 配置
[uwsgi]
master = true
processes = 4
pythonpath = /home/app/src/axf
module = axf.wsgi
socket = 127.0.0.1:8001
logto = /home/app/log/uwsgi.log
flask 配置
[uwsgi]
pythonpath = /home/app1/src/aj;
callable = app;
socket = 127.0.0.1:8000
logto = /home/app1/log/uwsgi.log
3.5 启动uwsgi
uwsgi --ini uwsgi.ini
// 启动nginx
nginx