使用 centerOS 7 部署 django 项目 python3.7.3

安装MariaDB

  • 安装命令

yum -y install mariadb mariadb-server

  • 安装完成MariaDB,首先启动MariaDB

$: systemctl start mariadb

  • 设置开机启动

systemctl enable mariadb

  • 设置密码

mysql_secure_installation

Enter current password for root:

  • 设置密码

Set root password? [Y/n]

New password:
Re-enter new password:

  • 其他配置

Remove anonymous users? [Y/n]

Disallow root login remotely? [Y/n]

Remove test database and access to it? [Y/n] 数据库,回车

Reload privilege tables now? [Y/n]

  • 初始化MariaDB完成
  • 开启数据库远程连接
  • 在mysql数据库中的user表中可以看到默认是只能本地连接的,所有可以添加一个新的用户,该用户可以远程访问
  • 创建用户
  • 先使用数据库
    use mysql;
  • 设置IP访问白名单:
    针对ip>>>> create user ‘root’@’192.168.10.10’ identified by ‘password’;
    全部 >>>>create user ‘root’@’%’ identified by ‘password’;
  • 授权
    给用户最大权限>>>> grant all privileges on . to ‘root’@’允许远程访问数据库的IP地址’ identified by ‘password’;
    给部分权限(test 数据库) >>>>grant all privileges on test.* to ‘root’@’%’ identified by ‘password’ with grant option;
  • 刷新权限表
    flush privileges;
  • 查看数据库使用端口
    ow global variables like 'port';
    接下来就可以在远程的数据库可视化工具中直接访问该服务器中的mysql了。

在数据库工具中输入数据库IP地址、端口,用户名root,密码就可以连接了。

安装python3.7

在centos中,系统默认只提供python2.7的版本,但是项目我们使用的python3.7的版本。所有我们自己安装python3

  • 安装Python3的方法
  • 首先安装依赖包

yum -y groupinstall “Development tools”

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

  • 然后根据自己需求下载不同版本的Python3,我下载的是Python3.7.3

wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

  • 然后解压压缩包,进入该目录,安装Python3

tar -xvJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure --prefix=/usr/local/python3
make && make install

在这里由于一般位于3.7以上版本编译安装时出错
是因为缺少依赖包libffi-devel
在安装3.7以上版本时,需要一个新的libffi-devel包做依赖
解决方法:yum -y install libffi-devel tk-devel

  • 最后创建软链接

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

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

由于centerOS自带的pipy版本比较低,为了预防下面使用pip3安装所需要的包,建议在这一步骤就使用升级命令讲pip更新到最新版本。
更新命令:pip3 install --upgrade pip

安装环境

  1. 安装virtualenv
    yum install python-virtualenv
  2. 创建虚拟环境
    virtualenv --no-site-packages env
  3. 进入虚拟环境所在文件夹
    cd env
  4. 激活虚拟环境
    source bin/activate

下班了,未完待续

未经允许不得转载:木盒主机 » 使用 centerOS 7 部署 django 项目 python3.7.3

赞 (0)

相关推荐

    暂无内容!