CentOS7部署Django,nginx,uwsgi,redis
前期准备
把所有的软件都传到这个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的更多相关文章
- CentOS上部署Django+Nginx+Uwsgi环境
在CentOS上部署Django+Nginx+Uwsgi环境 奇谭 2016-09-01 评论 Linux python django nginx uwsgi VirtualEnv的作用:创建隔 ...
- centos 下部署django nginx+uwsgi
为了建立一个工作站,也是麻烦了.... 感谢该博主: https://www.cnblogs.com/levelksk/p/7921066.html 1.安装centos 后首先安装python,下载 ...
- ubuntu+Django + nginx + uwsgi 部署
ubuntu+Django + nginx + uwsgi 部署 0.前期准备 注意:以下几件事都必须在激活虚拟环境下完成 运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requireme ...
- CentOS7部署Django项目
1. 云服务器 这里使用的是腾讯云选择系统:CentOS7.3 记住云服务器登录密码 2. 配置Python3环境 默认Python环境为python2.7,yum安装是需要python2的环境的 安 ...
- Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器
Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器 闲着无聊的时候部署了一个Django项目玩,用vm虚拟机部署的. 准备工作 我使用的系统是Ubuntu16 ...
- Install Python+Django+Nginx+UWSGI
一.软件环境: CentOS6.6_64bit 需要用到的软件: [root@django tools]# ll 总用量 33336 -rw-r--r-- 1 root root 7497785 3月 ...
- Linux - 搭建Web项目(Django + nginx + uwsgi)
工作中碰到需要使用Django + nginx + uwsgi 搭建项目环境 1. 搭建基本环境 需要有python环境,不多做说明 需要安装nginx,不多做说明 需要安装uwsgi: yum in ...
- 吴裕雄--天生自然Django框架开发笔记:Django Nginx+uwsgi 安装配置
Django Nginx+uwsgi 安装配置 使用 python manage.py runserver 来运行服务器.这只适用测试环境中使用. 正式发布的服务,需要一个可以稳定而持续的服务器,比如 ...
- CentOS 6.5下安装Python+Django+Nginx+uWSGI
1.安装Python31.1先安装zlib库及其他三方库安装uWSGI时需要使用zlib,否则执行python uwsgiconfig.py --build时会报ImportError,就是因为在安装 ...
随机推荐
- 前端jquery 获取select多选的值
当select设置属性multiple='multiple'时, option就可以多选了 那么我们如何获取所有被选中的option的值呢? 首先说明: $('select[name="m ...
- Django组件之Form表单
一.Django中的Form表单介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入 ...
- vue1.0+vue2.0实现选项卡
通常我们写tab选项卡的时候,一般都是用jq等去操作dom,给同级元素移除active类,然后,给被点击元素添加active类,用vue实现也是同样的原理,都是操作active类. 我们都知道用vue ...
- Magento2 常见错误 ----- 定期更新
1.静态文件有版本号,静态文件不能读取,页面无法显示.如下图: 解决方案:其实URL里的版本号对于magento来说是合法的,这是因为我们缺少了一个文件\pub\static\.htaccess:导致 ...
- Codeforces 1037E Trips
原题 题目大意: 有\(n\)个人,起初他们都不是朋友.总共有\(m\)天,每天会有两个人成为朋友.他们计划在晚上出去旅游,对于一个人,有如下两种情况: 1.要么他不出去旅游 2.要么有至少\(k\) ...
- 浏览器开发者工具----F12 功能介绍
笔者技巧: 看了些其它回答,有些是用来扒图片的,有些是写爬虫的(这个不要看Elements,因为浏览器会对一些不符合规范的标签做补全或者其它处理,最好是Ctrl+U). 图片的话就不要看Network ...
- 简单的实现HTTP密码验证登陆
1.首先需要安装 httpd-tools yum install -y httpd-tools 2.安装完成后设置用户名密码,我这里用的是NGINX htpasswd -bc /mypath/ngin ...
- 速查mysql数据大小
速查mysql数据大小 # 1.查看所有数据库大小 mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data ...
- Sass学习第一天
Sass学习 网站学习地址: Sass中文网:https://www.sass.hk/docs/#t7-3 Airen的博客:https://www.w3cplus.com/preprocessor/ ...
- sprin源码解析之属性编辑器propertyEditor
目录 异常信息 造成此异常的原因 bean 配置文件 调用代码 特别说明: 异常解决 注册springt自带的属性编辑器 CustomDateEditor 控制台输出 属性编辑器是何时并如何被注册到s ...