centos7安装python,mariaDB,django,nginx
0,安装centos7
centos默认不开启网卡,需要在安装时将ens33设置为on,或者后续通过vi ifcfg-ens33,找到onboot,设置为yes
或者也可以改名:cd /etc/sysconfig/network-scripts/ mv ifcfg-ens33 ifcfg-eth0, vi ifcfg-eth0(将name改为eth0)
ssh登陆centos7时,如果提示WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!,可以用ssh-keygen -R [IP_ADDRESS]重置
1,安装python3
关闭yum(如果在运行):rm -f /var/run/yum.pid
安装gcc:yum install gcc
安装依赖包: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.7的pip需要):yum install libffi-devel -y
查看最新版本:https://www.python.org/ftp/python/
安装wget(如果没有安装):yum -y install wget
下载最新版本:wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
新建目录:mkdir /usr/local/python3
移动:mv Python-3.7.2.tgz /usr/local
进入/usr/local目录解压:tar -xvf Python-3.7.2.tgz
进入解压文件夹:cd /usr/local/Python-3.7.2
配置安装目录:./configure --prefix=/usr/local/python3(如果提示"make:*** No targets specified and no makefile found.Stop.",需要yum update , yum install gcc build-essential)
编译:make
安装:make install
删除安装包:rm Python-3.7.2.tgz
删除文件夹: rm -rf Python-3.7.2
配置python3软链接: ln -s /usr/local/python3/bin/python3 /usr/bin/python3
配置pip软链接:ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
2,安装mariaDB
安装mariaDB:yum install mariadb mariadb-server -y
安装MySQL-python:yum install MySQL-python -y
启动mariaDB:systemctl start mariadb
开机自启动:systemctl enable mariadb.service
初始化mariaDB:mysql_secure_installation
创建数据库:
mysql -uroot -ptest
create database mysite;
3,安装nginx
3.1,需要先安装(如果没安装):
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3.2,下载和安装nginx:
查看版本:https://nginx.org/en/download.html 查看版本
下载:wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
解压:tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure
make
mkdir /usr/local/nginx
make install
3.3,启动停止nginx
cd /usr/local/nginx/sbin/
nginx -c /usr/local/nginx/conf/nginx.conf # 开启
nginx -s stop # 停止
nginx -s quit
nginx -s reload # 重启
也可能是cd /etc/nginx,然后nginx -c /etc/nginx/nginx.conf
加环境变量:
vim /etc/profile,在文件最后加上:
PATH=$PATH:/usr/local/nginx/sbin
export PATH
4,创建django项目
cd /
mkdir data
cd /data/
find ./ -name django-admin # 找到django-admin所在目录
python3 /usr/local/python3/bin/django-admin.py startproject mysite # 创建mysite站点
修改配置文件,/data/mysite/mysite/settings.py
"""
Django settings for mysite project. Generated by 'django-admin startproject' using Django 1.11.7. For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm4@g1=hz^08y(9d)v5l!8^*0wbla=oe15s@u8@5^pw=llfz48%' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = ["*"] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'mysite.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'mysite.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysite',
'PASSWORD':'test',
'USER': 'root',
'HOST':'127.0.0.1',
'PORT':'3306',
}
} # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/'
安装pymysql:
pip install pymysql
修改data/mysite/mysite/__init__.py文件:
import pymysql
pymysql.install_as_MySQLdb()
创建django数据库
cd /data/mysite
python3 manage.py migrate
启动django
python3 manage.py runserver
5,FLASK
5.1,直接开启服务
app.run(host='0.0.0.0', port=5000)
python3 app01.py
备注:可能centos需要让防火墙放行端口,增加如下配置:
firewall-cmd --zone=public --add-port=5000/tcp --permanent
5.2,通过uwsgi启动flask服务
pip install uwsgi
find / -name uwsgi # /usr/local/python3/bin/uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi # 软链接
uwsgi --socket 0.0.0.0:5000 --protocol=http -p 3 -w run:app
socket 0.0.0.0:5000:暴露端口号5000
--protocol=http:http
-p 3 : 占3个进程
-w run:app:-w 指明了要启动的模块,run 就是项目启动文件 run.py 去掉扩展名,app 是 run.py 文件中的变量 app,即 Flask 实例
5.3,配置uwsgi文件,通过nginx起服务
必须先启动uwsgi,再启动nginx
配置uwsgi,可以放在项目目录下(部署时去掉#后面注释):
[uwsgi]
socket = 127.0.0.1:5000 # uWSGI 的监听端口
chdir = /home/bridge/flasksite # 项目根目录
wsgi-file = app01.py # Flask 项目的启动文件
callable = app # 程序内启用的application变量名
processes = 4 # 进程数量
vacuum = true
master = true
stats = %(chdir)/uwsgi/uwsgi.status # 记录uwsgi状态
pidfile = %(chdir)/uwsgi/uwsgi.pid # 记录uwsgi的pi
假设flask项目下的uwsgi结构如下:
flasksite/
|-- uwsgi.ini
|-- app01.py
|
|-- uwsgi/
| | -- uwsgi.pid
| | -- uwsgi.status
uwsgi命令:
cd flasksite
启动:uwsgi uwsgi.ini
重启:uwsgi --reload uwsgi/uwsgi.pid
关闭:uwsgi --stop uwsgi/uwsgi.pid
关闭所有uwsgi:pkill -f uwsgi -9
配置nginx,本例配置文件在/usr/local/nginx/conf/nginx.conf ,增加下面一段:
server {
listen 5050;
server_name data.migelab.com;
charset utf-8;
client_max_body_size 75M; location / {
include uwsgi_params; # 导入uwsgi配置
uwsgi_pass 127.0.0.1:5000; # 转发端口,需要和uwsgi配置当中的监听端口一致
uwsgi_param UWSGI_PYTHON /usr/bin/python3; # Python解释器所在的路径,如果有虚拟环境可将路径设置为虚拟环境
uwsgi_param UWSGI_CHDIR /home/bridge/flasksite; # 项目根目录
uwsgi_param UWSGI_SCRIPT app02:app; # 项目的主程序,比如你测试用run.py文件,文件中app = Flask(__name__),那么这里就填run:app
}
}
centos7安装python,mariaDB,django,nginx的更多相关文章
- CentOS7 安装Python
CentOS7 安装Python 1. 前置条件 centos7 安装时 勾选Development Tools,如果你centos7没有选,需要更多必要库 必要库 # yum -y install ...
- Centos7 安装 Python 的笔记
Centos7 安装 Python 的笔记 注意:系统自带的Python2.7不要改动,最好也不要出错,不然yum之类的工具可能会出错. 安装Python3.7.0 TensorFlow对Python ...
- CentOS7 安装python 3.5 及 pip安装
1.CentOS7 安装Python 的依赖包 # yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-d ...
- Linux 安装Python和Django
1.下载python源码包 网址: https://www.python.org/ 在Downloads中打开Source code 由于 Django1.11.15不兼容3.7版本的python 所 ...
- CentOS7安装配置MariaDB(mysql)数据主从同步
CentOS7安装MariaDB并配置主从同步 环境声明: 防火墙firewalld及SElinux均为关闭状态 主库节点:192.168.0.63 从库节点:192.168.0.64 配置主库节点: ...
- centos7 安装 Python netsnmp模块
由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间...),所以记下来备忘. 先装一下python-devel 模块,执行命令 yum install pytho ...
- CentOS7 安装LNMP(Linux+Nginx+MySQL+PHP)
由于工作须要,须要学习php,本来想安装lamp的可是考虑到如今nginxserver有良好的性能且应用广泛. 这里我决定搭建Linux(CentOS7+Nginx+MySQL+PHP)下的webse ...
- centos7 安装 iRedmail 后 给nginx添加虚拟主机
iRedmail安装参考官方文档和 https://ywnz.com/linuxyffq/4563.html 准备工作 更新操作系统 yum update -y 安装必要组件 yum install ...
- CentOS7安装Docker,运行Nginx镜像、Centos镜像
摘要 总体思路:yum命令直接安装Docker,下载想要的镜像并启动 1.环境,CentOS7 Minimal 64位,Docker必须要64位的系统 2.通过yum命令直接安装,yum instal ...
随机推荐
- myeclipse2017下载安装与破解详细教程
下载myeclipse2017百度云下载路径: 链接:https://pan.baidu.com/s/1wQYwO2zrUvbbUcjCB5B8IQ 密码:6igu myeclipse2017破解文件 ...
- Backup &recovery备份和还原
实践版本:MySQL5.7 备份类型(backup type)物理和逻辑备份(Physical Versus Logical Backup) 物理备份是指直接复制存储数据库内容的目录和文 ...
- PostMessage发送WM_CLOSE消息,实现关闭任意程序
#include <Windows.h> #include <tchar.h> int WINAPI _tWinMain(HINSTANCE hInstance, HINSTA ...
- 解决:启用多线程调用webBrowsers函数报错:指定的转换无效
这里就需要委托. 定义一个 委托.加载之后给他绑定一个方法Callback,也就是所说的回掉函数. 然后写一个线程,线程需要一个object 的参数.将你定义的委托当作参数传进线程中的方法. 在线程中 ...
- Jar包的手动导入
(1)打开项目的file 找到project structure (2)进行以下操作
- hibernate一级缓存及对象的状态
hibernate中实体类对象的状态 在hibernate中实体类对象有三种状态 (1)瞬时态(临时态) 瞬时态:即我们自己创建一个对象,还没有保存到数据库就叫临时态,其实也可以说是对像没有id值,跟 ...
- caffe-ssd需要安装opencv
https://blog.csdn.net/xiaxiazls/article/details/52039473
- spring源码解析1--spring整体架构
一.Spring整体架构图 关于Spring的基本介绍就不再赘述了,先展示Spring框架的整体架构图如下示: 二.Spring结构介绍 Spring主要分为Core Container.Test.D ...
- javascript 的线程问题
JavaScript的setTimeout与setInterval是两个很容易欺骗别人感情的方法,因为我们开始常常以为调用了就会按既定的方式执行, 我想不少人都深有同感, 例如 setTimeout( ...
- java面向对象总结(一)
1. 对象的概念及面向对象的三个基本特征 面向对象的三大核心特性 面向对象开发模式更有利于人们开拓思维,在具体的开发过程中便于程序的划分,方便程序员分工合作,提高开发效率.面向对象程序设计有以下优点. ...