34tg 发表于 2015-8-17 09:39:23

python自动化运维——OMserver平台Web服务端部署过程

1.下载源代码(简单不讲述)
2.安装pcre,pcre是一个轻量级的正则表达式函数库,nginx的HTTP Rewrite模块会用到。
1
2
3
4
5
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make && make install




3.安装nginx.

1
2
3
4
5
wget http://nginx.org/download/nginx-1.5.9.tar.gz
tar -zxvf nginx-1.5.9.tar.gz
cd nginx-1.5.9
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-cc-opt='-O3' --with-cpu-opt=opteron
make && make install




4.安装MySQL-python.
1
2
3
4
5
yum install MySQL-python -y   #yum安装方式
wget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz
tar -zxvf MySQL-python-1.2.2.tar.gz
cd MySQL-python-1.2.2
python setup.py install




5.安装uwsgi.
1
2
3
4
5
wget http://projects.unbit.it/downloads/uwsgi-2.0.4.tar.gz
tar -zxvf uwsgi-2.0.4.tar.gz
cd uwsgi-2.0.4
make
cp uwsgi /usr/bin




6.安装Django.
1
2
3
4
wget htpp://www.djangoproject.com/m/releases/1.4/Django-1.4.9.tar.gz
tar -zxvf Django-1.4.9.tar.gz
cd Django-1.4.9
python setup.py install




7.配置nginx。修改/usr/local/nginx/conf/nginx.conf,添加以下server域配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    server {
      listen       80;
      server_namewww.omserver.com;

      location / {
            uwsgi_pass 192.168.202.128:9000;
            include uwsgi_params;
            uwsgi_param UWSGI_CHDIR /data/www/OMserverweb;#项目主目录
            uwsgi_param UWSGI_SCRIPT django_wsgi;    #此处应与项目目录中的wsgi文件同名
            access_log off;
      }
      location ^~ /static {
            root /data/www/OMserverweb;
      }
      location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
            root /data/www/OMserverweb/static;
            access_log off;
      }
    }




8.配置uwsgi。创建uwsgi配置文件/usr/local/nginx/conf/uwsgi.ini
1
2
3
4
5
6
7
8
9
10
11
12
13

socket = 0.0.0.0:9000
master = true
pidfile = /usr/local/nginx/uwsgi.pid
processes = 8    #指定进程数
chdir = /data/www/OMserverweb    #项目主目录
pythonpath = /data/www
profiler = true
memory-report=true
enable-threads=true
logdate=true
limit-as=6048
daemonize=/data/logs/django.log




注:如果这里需要配置多个django站点,需要创建多个.ini文件分别配置uwsgi,并且需要监听不同端口。9.启动uwsgi和nginx服务。
1
2
/usr/bin/uwsgi --ini /usr/local/nginx/conf/uwsgi.ini
/usr/local/nginx/sbin/nginx




10.项目源码配置
1).将下载的源码放于/data/www/目录下
2).导入数据库结构
1
2
3
mysql> grant all privileges on OMServer.* to omserver_user@'%' identified by 'J8w3jZXSG#y34'   
mysql> create OMServer
# mysql -u omserver_user -p < OMServer.sql




注:此处需在mysql配置文件he段中添加default_character_set=utf8,并重启mysql,否则,插入中文数据时会乱码。
3).修改settings.py


1
2
3
4
5
6
7
8
9
10
DATABASES = {
    'default': {
      'ENGINE': 'django.db.backends.mysql',
      'NAME': 'OMServer',
      'USER': 'omserver_user',
      'PASSWORD': 'J8w3jZXSG#y34',
      'HOST': 'localhost',
      'PORT': '3306',
    }
}




4).修改主控端rpyc主机IP,autoadmin/views.py

1
2
3
4
5
6
try:
      conn=rpyc.connect('192.168.202.132',11511)
      conn.root.login('OMuser','KJS23o4ij09gHF734iuhsdfhkGYSihoiwhj38u4h')
    except Exception,e:
      logger.error('connect rpyc server error:'+str(e))
      return HttpResponse('connect rpyc server error:'+str(e))




5).重启uwsgi和nginx
注:由于nginx子进程默认由nobody启动,访问静态文件是可能出现权限禁止错误,需在nginx配置文件中添加userroot;项。

页: [1]
查看完整版本: python自动化运维——OMserver平台Web服务端部署过程