Jolly

Centos7 部署python应用相关配置
在centos上部署python环境需要的步骤很多,包括nginx,python版本安装,mysql的安装配置,虚...
扫描右侧二维码阅读全文
29
2018/07

Centos7 部署python应用相关配置

在centos上部署python环境需要的步骤很多,包括nginx,python版本安装,mysql的安装配置,虚拟环境的安装配置等,过程比较繁琐,有许多小细节要注意,以下是相关步骤。

1. 安装python3.6

编译环境准备:

 yum groupinstall 'Development Tools'
 yum install zlib-devel bzip2-devel openssl-devel ncurese-devel
 yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel

1 . 获取

wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar -xzvf Python-3.6.3.tgz -C  /tmp
cd  /tmp/Python-3.6.3/

2 . 把Python3.6安装到 /usr/local 目录

./configure --prefix=/usr/local
make
make altinstall

3 . 更改/usr/bin/python链接

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

替换旧Python,将默认安装的python2软链接指向python:

mv /usr/bin/python /usr/bin/old_python

再将/usr/bin/python指向python3:

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

这样输入/usr/bin/python出来的就是python3了。这也是后面安装virtualenvwrapper,配置路径不会出错的前提。
删除软连接:rm -rf /home/zhenwx/htccode(示例)

4 .使得输入python系统默认为python3

cd /usr/bin/
ls yum*
vim yum

修改第一行尾python2

vim yum-config-manager

修改第一行尾python2

vim yum-debug-restore
vim yum-groups-manager
vim yum-build-dep
vim yum-debug-dump
vim yumdownloader
vim /usr/libexec/urlgrabber-ext-down

修改第一行尾python2

此时输入python就是3.6的python了。

2. maridb

  1. 安装

  2. yum install mariadb-server

  3. 启动, 重启

  4. systemctl start mariadb
  5. systemctl restart mariadb

  6. 设置bind-ip
vim /etc/my.cnf

在 [mysqld]:下面加一行

bind-address = 0.0.0.0

4 . 设置外部ip可以访问

先进入mysql才能运行下面命令:mysql 直接进入就行

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

5 . 设置阿里云、腾讯云的对外端口
在对应服务器控制面板中,添加安全组规则,开放端口3306

6 . 安装mysqlclient出问题

centos 7:
    yum install python-devel mariadb-devel -y

ubuntu:
    sudo apt-get install libmysqlclient-dev

然后:
    pip install mysqlclient

3. 安装nginx

1、拷贝我们的nginx安装包到服务器
2、安装依赖包

yum -y install gcc gcc-c++ openssl-devel pcre-devel httpd-tools

3、编译安装

tar -zxf nginx.tar.gz
cd nginx/

useradd nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_mp4_module --with-http_flv_module

make && make install

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

4. 安装virtualenvwrapper

yum install python-setuptools python-devel
pip install virtualenvwrapper

编辑.bashrc文件

vim ~/.bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

重新加载.bashrc文件

source  ~/.bashrc

新建虚拟环境

mkvirtualenv mxonline

进入虚拟环境

workon mxonline

安装pip包
我们可以通过 pip freeze > requirements.txt 将本地的虚拟环境安装包相信信息导出来

然后将requirements.txt文件上传到服务器之后运行:

pip install -r requirements.txt

安装依赖包

Last modification:November 25th, 2019 at 09:20 pm
🌓