前期准备

把所有的软件都传到这个tools文件夹

cd ~

mkdir tools

cd tools/

mkdir /application

安装nginx

yum install pcre pcre-devel

yum install -y openssl openssl-devel

tar xf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.2/ --with-http_stub_status_module —with-http_ssl_module

make && make install

ln -s /application/nginx-1.12.2 /application/nginx

检查语法

/application/nginx/sbin/nginx -t

启动nginx

/application/nginx/sbin/nginx

curl 127.0.0.1

如果看到welcome to nginx说明nginx安装成功

修改nginx配置文件

cd /application/nginx/conf

vi nginx.conf

修改配置文件内容如下:

worker_processes 4;

#pid /run/nginx.pid;

events {

        worker_connections 768;

        # multi_accept on;

}

http {

        ##

        # Basic Settings

        ##

        sendfile on;

        tcp_nopush on;

        tcp_nodelay on;

        keepalive_timeout 65;

        types_hash_max_size 2048;

        # server_tokens off;

        # server_names_hash_bucket_size 64;

        # server_name_in_redirect off;

        include mime.types;

        default_type application/octet-stream;

        ##

        # SSL Settings

        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE

        ssl_prefer_server_ciphers on;

        ##

        # Logging Settings

        ##

        access_log /var/log/nginx/access.log;

        error_log /var/log/nginx/error.log;

        ##

        # Gzip Settings

        ##

        gzip on;

        gzip_disable "msie6";

        # gzip_vary on;

        # gzip_proxied any;

        # gzip_comp_level 6;

        # gzip_buffers 16 8k;

        # gzip_http_version 1.1;

        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##

        # Virtual Host Configs

        ##

        #include /etc/nginx/conf.d/*.conf;

        include /application/nginx/extra/*;

}

#mail {

#       # See sample authentication script at:

#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

#

#       # auth_http localhost/auth.php;

#       # pop3_capabilities "TOP" "USER";

#       # imap_capabilities "IMAP4rev1" "UIDPLUS";

#

#       server {

#               listen     localhost:110;

#               protocol   pop3;

#               proxy      on;

#       }

#

#       server {

#               listen     localhost:143;

#               protocol   imap;

#               proxy      on;

#       }

#}

接着:

cd /application/nginx

mkdir extra

cd extra/

vi default

##

# You should look at the following URL's in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# http://wiki.nginx.org/Pitfalls

# http://wiki.nginx.org/QuickStart

# http://wiki.nginx.org/Configuration

#

# Generally, you will want to move this file somewhere, and start with a clean

# file but keep this around for reference. Or just disable in sites-enabled.

#

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##

# Default server configuration

#

server {

        listen 80 default_server;

        listen [::]:80 default_server;

        # SSL configuration

        #

        # listen 443 ssl default_server;

        # listen [::]:443 ssl default_server;

        #

        # Self signed certs generated by the ssl-cert package

        # Don't use them in a production server!

        #

        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {

                # First attempt to serve request as file, then

                # as directory, then fall back to displaying a 404.

                try_files $uri $uri/ =404;

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #       include snippets/fastcgi-php.conf;

        #

        #       # With php5-cgi alone:

        #       fastcgi_pass 127.0.0.1:9000;

        #       # With php5-fpm:

        #       fastcgi_pass unix:/var/run/php5-fpm.sock;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #       deny all;

        #}

}

# Virtual Host configuration for example.com

#

# You can move that to a different file under sites-available/ and symlink that

# to sites-enabled/ to enable it.

#

#server {

#       listen 80;

#       listen [::]:80;

#

#       server_name example.com;

#

#       root /var/www/example.com;

#       index index.html;

#

#       location / {

#               try_files $uri $uri/ =404;

#       }

#}

接着:

vi court

内容如下:

erver {

        listen          80;

        server_name    172.16.146.135;

        client_max_body_size    10m;

        gzip_vary on;

        gzip_proxied any;

        gzip_comp_level 6;

        gzip_buffers 16 8k;

        gzip_http_version 1.1;

        gzip_types text/plain text/css application/json application/x-javascript;

        location / {

                uwsgi_pass      unix:///var/run/my_project.sock;

                include         uwsgi_params;

                uwsgi_param     UWSGI_SCHEME $scheme;

                uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;

        }

        location /static/ {

                alias           /root/my_project/static/;

                index           index.html index.htm;

        }

       location /static/admin/ {

                alias           /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin/;

                index           index.html index.htm;

        }

         charset  utf-8;

    }

接着:

检查语法

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

安装mysql数据库

yum install -y libaio-devel

cd /root/tools/

tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz

mv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32

ln -s /application/mysql-5.5.32 /application/mysql

cd /application/mysql

\cp support-files/my-small.cnf /etc/my.cnf

mkdir -p /application/mysql/data

groupadd mysql

useradd -s /sbin/nologin -g mysql -M mysql

chown -R mysql.mysql /application/mysql

vi /etc/hosts

在localdomain4后面添加你的主机名

不会?hostname

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 Aaron

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data —user=mysql

\cp support-files/mysql.server  /etc/init.d/mysqld

sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe  /etc/init.d/mysqld

/etc/init.d/mysqld start(这个是个人习惯,我习惯了centOS6.x,你也可以配置成用systemctl来启动)

/etc/init.d/mysqld stop

vi /etc/my.cnf

在[client]下面加上:

default-character-set=utf8

在[mysqld]下面加上:

character-set-server=utf8

在[mysql]下面加上:

default-character-set=utf8

有问题看日志 tail -50 Aaron.err

/etc/init.d/mysqld start

接着:

/application/mysql/bin/mysql -uroot

create database my_project;

create user 'my_project'@'localhost' identified by 'my_project';

grant all privileges on my_project.* to 'my_project'@'localhost';

flush privileges;

exit;

配置celery

cd  /usr/lib/systemd/system/

vi celery.service

内容如下:

[Unit]

Description=Celery Service

After=network.target

[Service]

Type=forking

#User=celery

#Group=celery

EnvironmentFile=-/etc/conf.d/celery

WorkingDirectory=/root/my_project

ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \

  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \

  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \

  --pidfile=${CELERYD_PID_FILE}'

ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \

  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \

  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

[Install]

WantedBy=multi-user.target

接着:

mkdir -p /etc/conf.d

cd /etc/conf.d

vi celery

内容如下:

CELERYD_NODES="w1 w2 w3"

CELERY_BIN="/usr/bin/celery"

CELERY_APP="my_project"

CELERYD_MULTI="multi"

CELERYD_PID_FILE="/etc/celery/%n.pid"

CELERYD_LOG_FILE="/etc/celery/%n%I.log"

CELERYD_LOG_LEVEL=“INFO"

接着:

其中CELERY_BIN=“/usr/bin/celery"这个路径要以which celery这个路径为准

systemctl start celery

systemctl stop celery

有报错,看systemctl status celery.service -l和日志

安装各种奇奇怪怪的东西

yum install pip -y

yum install python-pip -y

yum -y install epel-release

yum install python-pip -y(依赖于epel-release)

yum install -y python-devel(pip安装uwsgi需要这个)

pip install --upgrade pip

yum install mysql-devel(EnvironmentError: mysql_config not found)

把my_project项目拖进来到/root/下

cd my_project

vi settings

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.mysql',

        'OPTIONS': {

            'read_default_file': os.path.join(BASE_DIR, 'mysql.conf'),

            'unix_socket': '/tmp/mysql.sock',

        },

    }

}

添加

'unix_socket': ‘/tmp/mysql.sock',

如上所示

接着:

pip install requirements.txt  -r

安装uwsgi

vi /root/my_project.ini

内容如下:

[uwsgi]

chdir=/root/my_project

socket=/var/run/my_project.sock

chmod-socket=666

module=my_project.wsgi:application

master=True

pidfile=/tmp/my_project.pid

vacuum=True

max-requests=5000

processes = 4

daemonize=/var/log/uwsgi/my_project.log

接着:

mkdir /var/log/uwsgi/ -p

touch my_project.log

uwsgi -i /root/my_project.ini

ps -ef|grep uwsgi

pkill -9 uwsgi

安装redis

cd tools/

tar xf redis-4.0.2.tar.gz

cd redis-4.0.2

make MALLOC=jemallocmake PREFIX=/application/redis-4.0.2 install

ln -s /application/redis-4.0.2/ /application/redis

/application/redis/bin/redis-server

启动项目

cd my_project

python manage.py makemigrations

python manage.py migrate

/application/mysql/bin/mysql -uroot

python manage.py createsuperuser

getenforce

setenforce 0

systemctl stop firewalld.service

CentOS7部署Django,nginx,uwsgi,redis的更多相关文章

  1. CentOS上部署Django+Nginx+Uwsgi环境

    在CentOS上部署Django+Nginx+Uwsgi环境 奇谭  2016-09-01 评论  Linux  python django nginx uwsgi VirtualEnv的作用:创建隔 ...

  2. centos 下部署django nginx+uwsgi

    为了建立一个工作站,也是麻烦了.... 感谢该博主: https://www.cnblogs.com/levelksk/p/7921066.html 1.安装centos 后首先安装python,下载 ...

  3. ubuntu+Django + nginx + uwsgi 部署

    ubuntu+Django + nginx + uwsgi 部署 0.前期准备 注意:以下几件事都必须在激活虚拟环境下完成 运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requireme ...

  4. CentOS7部署Django项目

    1. 云服务器 这里使用的是腾讯云选择系统:CentOS7.3 记住云服务器登录密码 2. 配置Python3环境 默认Python环境为python2.7,yum安装是需要python2的环境的 安 ...

  5. Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器

    Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器 闲着无聊的时候部署了一个Django项目玩,用vm虚拟机部署的. 准备工作 我使用的系统是Ubuntu16 ...

  6. Install Python+Django+Nginx+UWSGI

    一.软件环境: CentOS6.6_64bit 需要用到的软件: [root@django tools]# ll 总用量 33336 -rw-r--r-- 1 root root 7497785 3月 ...

  7. Linux - 搭建Web项目(Django + nginx + uwsgi)

    工作中碰到需要使用Django + nginx + uwsgi 搭建项目环境 1. 搭建基本环境 需要有python环境,不多做说明 需要安装nginx,不多做说明 需要安装uwsgi: yum in ...

  8. 吴裕雄--天生自然Django框架开发笔记:Django Nginx+uwsgi 安装配置

    Django Nginx+uwsgi 安装配置 使用 python manage.py runserver 来运行服务器.这只适用测试环境中使用. 正式发布的服务,需要一个可以稳定而持续的服务器,比如 ...

  9. CentOS 6.5下安装Python+Django+Nginx+uWSGI

    1.安装Python31.1先安装zlib库及其他三方库安装uWSGI时需要使用zlib,否则执行python uwsgiconfig.py --build时会报ImportError,就是因为在安装 ...

随机推荐

  1. 返回通知 对方法返回的结果可以进行加工 例如请求接口后 返回的json参数可以加工成对象返回给调用者

  2. Django之缓存、信号和图片验证码

    一. 缓存 1. 介绍 缓存通俗来说:就是把数据先保存在某个地方,下次再读取的时候不用再去原位置读取,让访问速度更快. 缓存机制图解 2.Django中提供了6种缓存方式 1. 开发调试 2. 内存 ...

  3. [BZOJ 2285] [SDOI 2011] 保密

    Description 传送门 Solution 这道题的最大难点在于读懂题意(雾 分数规划求出 \(n\) 到 \(1\cdots n_1\) 每个点的最小 \(\sum\frac{t_i}{s_i ...

  4. centos7.5误删python2.7之后,导致yum和Pythonm命令无法使用

    问题描述 最近想要将服务器上的Python2.7升级成3.x的版本时.使用了如下命令: (1)强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev ...

  5. CQOI2018异或序列 [莫队]

    莫队板子 用于复习 #include <cstdio> #include <cstdlib> #include <algorithm> #include <c ...

  6. 深入理解JVM(3)——类加载机制

    1.类加载时机 类的整个生命周期包括了:加载( Loading ).验证( Verification ).准备( Preparation ).解析( Resolution ).初始化( Initial ...

  7. 苹果手机iOS11中fixed弹出框中input光标错位问题

    最近遇到了一个移动前端的BUG:手机弹出框中的输入框focus时光标可能会错位. 刚开始时我完全不知道错误原因是什么,在电脑上调试时完全没有问题,手机上出现问题时也没有找到规律.后来在网上搜索了大量的 ...

  8. JProfiler性能分析工具

    1.简介 JProfiler是一个商业授权的Java剖析工具,用于分析Java EE和Java SE应用程序. 2.JVMTI JDK本身定义了目标明确并功能完善的JNI(Java Native In ...

  9. 使用IntelliJ IDEA 配置Maven(转)

    1. 下载Maven 官方地址:http://maven.apache.org/download.cgi 解压并新建一个本地仓库文件夹 2.配置本地仓库路径 3.配置maven环境变量 4.在Inte ...

  10. Centos 05 系统目录讲解

    本节内容 1.linux目录结构 2.主目录功能简介 3.重要子目录 linux目录结构 在linux里面,逻辑上所有目录只有一个顶点,根是所有目录的起点. 根下面是类似一个倒挂的树一样的层次结构 可 ...