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 ...
随机推荐
- 关于element-ui表格table设置header-cell-class-name样式不起作用的原因分析
在编写表格的时候想给表头添加样式,使用 header-cell-class-name怎么都添加不上样式,检查元素发现连class都没添加上,查了很多资料有人说element之前版本不支持这属性,但我使 ...
- nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)
在window服务器上部署nuget服务器时,发布包时出现请求报错 406 (Not Acceptable) 验证用户名.密码正确的情况下,还是出现上面错误.后面跟踪服务器日志,发现window\te ...
- synchronized锁级别的一个坑
在实现一次对限流接口访问时,我错误的使用了单例+synchronized修饰方法的形式实现,这样在限流方规则为不同接口不同限制,单独限制时,同一个实例中的所有被synchronized修饰的方法竞争同 ...
- 解决c# progressBar更新出现界面假死
最近一个项目需求中的一个功能是需要用progressBar反映处理文件的进度. 研究了Invoke和BeginInvoke方法. Control.Invoke 方法 (Delegate) :在拥有此控 ...
- android 开发设计模式---Strategy模式
假设我们要出去旅游,而去旅游出行的方式有很多,有步行,有坐火车,有坐飞机等等.而如果不使用任何模式,我们的代码可能就是这样子的. 12345678910111213141516171819202122 ...
- Android-Gradle(五)
Android studio不仅允许你为你的app和依赖库创建模块,同时也可为Android wear,Android TV,Google App Engine等创建模块,而这些单独的模块又可以在一个 ...
- 【转载】pycharm破解,可使用到2099年.pycharm版本 pycharm-professional-2016.3.1
1. Pycharm的安装方法,论坛很多,这里就不赘述了.参照:http://blog.csdn.net/qq_29883591/article/details/52664478 2. 下载Pycha ...
- SlidingMenu第一篇 --- 导入SlidingMenu库
1. 下载地址:https://github.com/jfeinstein10/SlidingMenu 2. 找到下载好的SlidingMeun的library目录 3. 导入库(将上述地址复制到 ...
- C++隐藏任务栏图标
在VC编程中,有时候我们需要将我们的程序在任务栏上的显示隐藏起来,我试过几种方法,下面我介绍一下我知道的三种方法. 第一种方法是设置窗口WS_EX_TOOLWINDOW扩展样式,通过在OnInitDi ...
- html5中视频播放问题总结
html5中视频播放问题总结 文章 1.问题一 框架? 加个标签就OK! <video id="video1" src="/video1.mp4" con ...