[关闭]
@ranger-01 2018-01-02T16:42:01.000000Z 字数 5993 阅读 999

Linux environment setup (Redhat 6.5)

deploy django


1. Redhat yum reinstall

  1. Uninstall yum

    1. rpm -qa | grep yum | xargs rpm -e --nodeps
  2. Download yum repo

    1. wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
    2. wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    3. wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
    4. wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-73.el6.centos.noarch.rpm
    5. # python-urlgrabber-3.9.1-11.el6.noarch.rpm is needed, and we need to uninstall the older one first
    6. wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
  3. Install the rpm package

    1. rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
    2. rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    3. rpm -ivh yum-3.2.29-73.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-37.el6.noarch.rpm
  4. Modify yum repo

    1. cd /etc/yum.repos.d/
    2. mv rhel-source.repo rhel-source.repo_bak
    3. # download repos according the redhat version in http://mirrors.163.com/.help/centos.html
    4. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
    5. # modify the repo file: replace $releasever to 6, open the file using vim first
    6. :%s/$releasever/6/g
  5. Import the key

    1. rpm --import http://mirrors.163.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6
  6. clearn yum cache

    1. # yum clean all #清除原有缓存
    2. # yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
    3. # yum install screen #测试域名是否可用

2. Install and config sceen

  1. Install

    1. yum install screen
  2. config screen
    1. edit /etc/screenrc
    2. add or uncomment this line:
      caption always "%{= kw}%-w%{= kG}%{+b}[%n %t]%{-b}%{= kw}%+w %=%d %M %0c %{g}%H%{-}"
    3. disable vbell: vbell off

3. Install Mysql 5.7[1]

  1. 下载mysql的yum源
    wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

  2. 安装这个rpm包
    rpm -ivh mysql57-community-release-el6-9.noarch.rpm

  3. 安装mysql相关包
    yum install mysql-server

  4. 启动并查看mysql服务
    service mysqld start
    service mysqld status

  5. 修改root默认密码

    1. 查看默认密码
      grep 'temporary password' /var/log/mysqld.log
    2. 修改默认密码为Puyacn#1..(contains at least one uppercase letter, one lowercase letter, one number and one special character. Re-enter it when prompted.)
      mysql_secure_installation
    3. 运行上述命令后,修改了默认密码,还有以下配置需要确认,直接YES就行(we'll press Y and then ENTER to all the subsequent questions in order to remove anonymous users, disallow remote root login, remove the test database and access to it, and reload the privilege tables.)
  6. 安装mysql头文件
    yum -y install mysql-community-devel

  7. 连接mysql
    mysql -uroot -p

  8. 数据库支持中文,创建 dtrade时,用下面命令;
    CREATE DATABASE dtrade DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

4. Install RabbitMQ[2]

  1. Get epel repo from aliyun mirror

    1. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
    2. yum clean all
    3. yum makecache
  2. setting the erlang-solutions[3] repo

    1. # create a repo file, and copy the following content into it
    2. [erlang-solutions]
    3. name=Centos 6 - $basearch - Erlang Solutions
    4. baseurl=https://packages.erlang-solutions.com/rpm/centos/6/$basearch
    5. gpgcheck=1
    6. gpgkey=https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
    7. enabled=1
  3. Install rabbitmq and start it

    1. wgt https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el6.noarch.rpm
    2. # it will auto install the dependency erlang from the repo setted in step 2
    3. yum install rabbitmq-server-3.6.8-1.el6.noarch.rpm
    4. servie rabbitmq-server start
    5. service rabbitmq-server status
    6. # enable rabbitmq plugins
    7. rabbitmq-plugins enable rabbitmq_management
    8. # Config rabbitmq-server
    9. # Pre-steps:
    10. rabbitmqctl stop_app
    11. rabbitmqctl reset
    12. rabbitmqctl start_app
    13. # Steps:
    14. rabbitmqctl add_vhost vhost_dtrade
    15. rabbitmqctl add_user dtrade dtradepwd
    16. rabbitmqctl set_permissions -p vhost_dtrade dtrade ".*" ".*" ".*"
    17. rabbitmqctl set_user_tags dtrade administrator
    18. rabbitmqctl stop_app
    19. chkconfig rabbitmq-server on
    20. # Start rabbitmq error, try the following steps
    21. # Change hostname
    22. 1. /etc/sysconfig/network
    23. 2. /etc/hosts
    24. 3. hostname "yourhostname"
    25. 4. restart right now or then

5. Install Nginx, pip, supervisor

  1. yum install nginx
  2. Install pip

    1. yum install python-pip
    2. pip install --upgrade pip
  3. Install supervisor

    1. pip install --upgrade --force-reinstall setuptools supervisor
    2. # to check the supervisor is ok or not, run the following command, and there should be just the help info, and no error message
    3. supervisord -h

6. Setup running environment

  1. copy py36 and env

    1. # directory tree like this
    2. /opt
    3. ├── dtrade
    4.    ├── conf
    5.    ├── env # virtual environment
    6.    ├── log
    7.    ├── operation
    8.    ├── portal
    9.    ├── run
    10.    ├── server
    11.    └── tmp
    12. ├── py36 # python 3.6
    13.    ├── bin
    14.    ├── include
    15.    ├── lib
    16.    └── share
  2. modify the targethost, database and rabbitmq setting in dtrade.conf

    1. "TargetHost": {
    2. "host": "192.168.1.64" # modify to your target ip, it will be used in allowed_hosts
    3. },
    4. "Database": {
    5. "engine": "django.db.backends.mysql",
    6. "host": "dt_mysql", # 127.0.0.1
    7. "password": "puyacn#1..", # Puyacn#1..
    8. "name": "dtrade", # create this database first
    9. "user": "root"
    10. },
    11. "RabbitMQ": {
    12. "serverIP": "dt_rabbitmq", # 127.0.0.1
    13. "sericePort": "5672",
    14. "user": "dtrade",
    15. "password": "dtradepwd",
    16. "vhost": "vhost_dtrade",
    17. "smsQueue": "smsqueue"
    18. },

7. Install the dtrade rpm package

Of course, you need build the rpm first using the latest code.

  1. cd /root/Projects/dtrade/build
  2. ./build.sh All
  3. # or
  4. ./build.sh NoNpmInstall

Manual

  1. Copy and install rpm package

    1. # Copy the rpm package to the target server first
    2. rpm -ivh dtrade-1.0.0000-1.x86_64.rpm --force
  2. Run the django script

    1. # active the virtual env
    2. source /opt/dtrade/env/bin/activate
    3. # Database schema initialization
    4. cd /opt/dtrade/server
    5. python manage.py runscript droptable
    6. python manage.py migrate
    7. # collect static
    8. python manage.py collectstatic --noinput
    9. # Data initialization
    10. python manage.py runscript testdata
    11. python manage.py runscript setOauthApp

Using fabric

You can use this way if just test in our environment, because 知交所 need vpn to cnnnect

  1. # Rember that we have modified the dtrade.conf and copied env, py36 in step 6
  2. # modify the deploy.py: dt_server = [dtrade_conf['TargetHost']['host'] + ':22']
  3. fab -f deploy.py install_rpm
  4. fab -f deploy.py init_service

Reference

  1. http://mirrors.163.com/centos/6/os/x86_64/Packages/
  2. http://mirrors.163.com/.help/centos.html
  3. http://blog.csdn.net/hqs2212586/article/details/53959498?winzoom=1
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注