博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS6+nginx+uwsgi+mysql+django1.6.6+python2.6.6
阅读量:4549 次
发布时间:2019-06-08

本文共 4867 字,大约阅读时间需要 16 分钟。

1.配置网关

#vi /etc/sysconfig/networkNETWORKING=yes(表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络,而且很多系统服务程序将无法启动)HOSTNAME=centos(设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应)GATEWAY=192.168.1.1(设置本机连接的网关的IP地址。例如,网关为10.0.0.2)

2.配置DNS

#vi /etc/resolv.confnameserver: 114.114.114.114 # IBM哥们讲的国内比较快的一个DNS

3.CentOS 修改IP地址

修改对应网卡的IP地址的配置文件# vi /etc/sysconfig/network-scripts/ifcfg-eth0修改以下内容DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0BOOTPROTO=static #设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的 ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址BROADCAST=192.168.0.255 #对应的子网广播地址HWADDR=00:07:E9:05:E8:B4 #对应的网卡物理地址IPADDR=12.168.1.2 #如果设置网卡获得 ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址IPV6INIT=noIPV6_AUTOCONF=noNETMASK=255.255.255.0 #网卡对应的网络掩码NETWORK=192.168.1.0 #网卡对应的网络地址ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备

4.重新启动网络配置

# service network restart 或# /etc/init.d/network restart

5.配置epal源(别的源没有的它也有,比如saltstack)

wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm# 下载chmod +x epel-release-6-8.noarch.rpm# 权限rpm -ivh epel-release-6-8.noarch.rpm# 安装yum update

6.安装pip

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.pywget https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.pypython get-pip.py# 没有install

https://bootstrap.pypa.io/get-pip.py

变成这个了,2016年04月11日22:08:44更新

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py

2016年06月12日11:32:45 更新

7.pip安装django

pip install django==1.6.6

8.pip安装mysqldb

yum install mysql-devel mysql mysql-server python-develpip install MySQL-python

9.修改mysql的root密码

mysql -urootuse mysql;#有的版本默认管理数据库不是这个名字(*注意)MySQL> update user set password=PASSWORD('newpassword') where User='root';MySQL> flush privileges; //刷新权限,重启mysql也可以MySQL> quit

或者:

/usr/bin/mysqladmin -u root password 'passw0rd'

10.mysql创建schema

CREATE SCHEMA `xtyw` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;# 这样创建的表不会出现admin中表更新中文内容的时候乱码

11.安装nginx

yum -y install nginx

12.配置nginx

http {    include       /etc/nginx/mime.types;    default_type  application/octet-stream;    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log  /var/log/nginx/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    # Load config files from the /etc/nginx/conf.d directory    # The default server is in conf.d/default.conf    include /etc/nginx/conf.d/*.conf;#-----------------------------------------------------    client_max_body_size 1024m;    server {        listen 80;        server_name 192.168.46.5;        location / {            uwsgi_pass 127.0.0.1:9000;            include uwsgi_params;            uwsgi_param UWSGI_CHDIR /data/www/helloworld;            uwsgi_param UWSGI_SCRIPT django_wsgi;            access_log off;        }        location ^~ /static {            root /data/www/xtyw/;        }        location ~* ^.+\.(png|mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|docx|xls|exe|ppt|t|tar|mid|midi|wav|rtf|,peg)$ {            root /data/medias;            access_log off;        }    }

#---------------------------------以下是我添加的内容

then

/etc/init.d/nginx start

13.安装uwsgi

pip install uwsgi

14.开始用uwsgi部署django应用到nginx上

进入项目主目录,即settings.py所在目录,创建uwsgi.ini配置文件

内容如下

[uwsgi]socket = 0.0.0.0:9000master = truepidfile = /etc/nginx/uwsgi.pidprocesses = 4chdir = /data/www/xtyw/wsgi-file = /data/www/xtyw/xtyw/wsgi.pyprofiler = truememory-report = trueenable-threads = truelogdate = truelimit-as = 6048daemnize = /data/logs/django.log

执行:

#uwsgi uwsgi.ini如果是xml文件#uwsgi -x uwsgi.xml

15.最后附上自动django源码自动重载方法

1.安装工具
yum -y install inotify-tools
2.编写一个监视脚本autoreload.sh
#!/bin/shobjectdir="/data/www/xtyw"# 启动inotify监视项目目录, 参数"--exclude" 为忽略的文件或目录正则/usr/bin/inotifywait -mrq --exclude "(static|logs|shell|\.swap|\.pyc|\.swx|\.py\~)" --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' --event modify,delete,move,create,attrib ${objectdir} | while read filesdo/bin/touch /data/www/xtyw/shell/reload.set    continuedone &
3.编写监视文件reload.set(内容即是uwsgi启动脚本)
#!/bin/bashif [ ! -n "$1" ]then    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"    exit 0fiif [ $1 = start ]then    psid=`ps aux | grep "uwsgi" | grep -v "grep" | wc -l`    if [ $psid -gt 4 ]    then        echo "uwsgi is running!"        exit 0    else        uwsgi /data/www/xtyw/xtyw/uwsgi.ini        echo "Start uwsgi service [OK]"    fielif [ $1 = stop ];then    killall -9 uwsgi    echo "Stop uwsgi service [OK]"elif [ $1 = restart ];then    killall -9 uwsgi    /usr/bin/uwsgi --ini /data/www/xtyw/xtyw/uwsgi.ini --touch-reload "/data/www/xtyw/shell/reload.set"    echo "Restart uwsgi service [OK]"else    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"fi

上线:

./autoreload.sh

all done

转载于:https://www.cnblogs.com/clarke/p/5670785.html

你可能感兴趣的文章
linux下搭建DHCP服务
查看>>
双曲函数与反双曲函数
查看>>
EF中的Select * From T Where id In(xxx,xxx)子查询
查看>>
自己写的一个校验IP、IP掩码、IP段的方法
查看>>
Node.js:模块系统
查看>>
jQuery.Data源码
查看>>
将博客搬至CSDN
查看>>
layui问题之模拟select点击事件
查看>>
ckplayer-超酷网页视频播放器的使用
查看>>
35+多用途WordPress主题
查看>>
KVO实现原理
查看>>
a:link,a:visited,a:hover,a:active
查看>>
DTD与XML的关系
查看>>
ASP.NET Development Server使用方法
查看>>
服务器运维基础指南
查看>>
读后感
查看>>
使用Crypto对数据进行加密解密
查看>>
CSS五類常用選擇器(收藏)
查看>>
have a thing用法
查看>>
为什么 远程钩子 必须使用动态链接库dll(而且是.data? 段共享的动态链接库)...
查看>>