@ranger-01
2018-01-02T16:42:01.000000Z
字数 5993
阅读 999
deploy
django
Uninstall yum
rpm -qa | grep yum | xargs rpm -e --nodeps
Download yum repo
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm
# python-urlgrabber-3.9.1-11.el6.noarch.rpm is needed, and we need to uninstall the older one first
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
Install the rpm package
rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
rpm -ivh yum-3.2.29-73.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
Modify yum repo
cd /etc/yum.repos.d/
mv rhel-source.repo rhel-source.repo_bak
# download repos according the redhat version in http://mirrors.163.com/.help/centos.html
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
# modify the repo file: replace $releasever to 6, open the file using vim first
:%s/$releasever/6/g
Import the key
rpm --import http://mirrors.163.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6
clearn yum cache
# yum clean all #清除原有缓存
# yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
# yum install screen #测试域名是否可用
Install
yum install screen
caption always "%{= kw}%-w%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+w %=%d %M %0c %{g}%H%{-}"
vbell off
下载mysql的yum源
wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
安装这个rpm包
rpm -ivh mysql57-community-release-el6-9.noarch.rpm
安装mysql相关包
yum install mysql-server
启动并查看mysql服务
service mysqld start
service mysqld status
修改root默认密码
Puyacn#1..
(contains at least one uppercase letter, one lowercase letter, one number and one special character. Re-enter it when prompted.) 安装mysql头文件
yum -y install mysql-community-devel
连接mysql
mysql -uroot -p
数据库支持中文,创建 dtrade时,用下面命令;
CREATE DATABASE dtrade DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci
;
Get epel repo from aliyun mirror
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum clean all
yum makecache
setting the erlang-solutions[3] repo
# create a repo file, and copy the following content into it
[erlang-solutions]
name=Centos 6 - $basearch - Erlang Solutions
baseurl=https://packages.erlang-solutions.com/rpm/centos/6/$basearch
gpgcheck=1
gpgkey=https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
enabled=1
Install rabbitmq and start it
wgt https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el6.noarch.rpm
# it will auto install the dependency erlang from the repo setted in step 2
yum install rabbitmq-server-3.6.8-1.el6.noarch.rpm
servie rabbitmq-server start
service rabbitmq-server status
# enable rabbitmq plugins
rabbitmq-plugins enable rabbitmq_management
# Config rabbitmq-server
# Pre-steps:
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
# Steps:
rabbitmqctl add_vhost vhost_dtrade
rabbitmqctl add_user dtrade dtradepwd
rabbitmqctl set_permissions -p vhost_dtrade dtrade ".*" ".*" ".*"
rabbitmqctl set_user_tags dtrade administrator
rabbitmqctl stop_app
chkconfig rabbitmq-server on
# Start rabbitmq error, try the following steps
# Change hostname
1. /etc/sysconfig/network
2. /etc/hosts
3. hostname "yourhostname"
4. restart right now or then
yum install nginx
Install pip
yum install python-pip
pip install --upgrade pip
Install supervisor
pip install --upgrade --force-reinstall setuptools supervisor
# to check the supervisor is ok or not, run the following command, and there should be just the help info, and no error message
supervisord -h
copy py36 and env
# directory tree like this
/opt
├── dtrade
│ ├── conf
│ ├── env # virtual environment
│ ├── log
│ ├── operation
│ ├── portal
│ ├── run
│ ├── server
│ └── tmp
├── py36 # python 3.6
│ ├── bin
│ ├── include
│ ├── lib
│ └── share
modify the targethost, database and rabbitmq setting in dtrade.conf
"TargetHost": {
"host": "192.168.1.64" # modify to your target ip, it will be used in allowed_hosts
},
"Database": {
"engine": "django.db.backends.mysql",
"host": "dt_mysql", # 127.0.0.1
"password": "puyacn#1..", # Puyacn#1..
"name": "dtrade", # create this database first
"user": "root"
},
"RabbitMQ": {
"serverIP": "dt_rabbitmq", # 127.0.0.1
"sericePort": "5672",
"user": "dtrade",
"password": "dtradepwd",
"vhost": "vhost_dtrade",
"smsQueue": "smsqueue"
},
Of course, you need build the rpm first using the latest code.
cd /root/Projects/dtrade/build
./build.sh All
# or
./build.sh NoNpmInstall
Copy and install rpm package
# Copy the rpm package to the target server first
rpm -ivh dtrade-1.0.0000-1.x86_64.rpm --force
Run the django script
# active the virtual env
source /opt/dtrade/env/bin/activate
# Database schema initialization
cd /opt/dtrade/server
python manage.py runscript droptable
python manage.py migrate
# collect static
python manage.py collectstatic --noinput
# Data initialization
python manage.py runscript testdata
python manage.py runscript setOauthApp
You can use this way if just test in our environment, because 知交所 need vpn to cnnnect
# Rember that we have modified the dtrade.conf and copied env, py36 in step 6
# modify the deploy.py: dt_server = [dtrade_conf['TargetHost']['host'] + ':22']
fab -f deploy.py install_rpm
fab -f deploy.py init_service