Manual Deployment

Manual Deployment - 图1warning

We recommend that you use Docker installation to ensure the consistency of the experience.

Requirements Environment

  • Python 3.6 and above
  • Mysql 5.6 and above
  • Modern browser
  • From v2.3.9 , Git version needs 2.17.0+ (affects new regular release application)

Installation Steps

The following installation steps assume that the project is installed in the /data/spug directory of a Centos7 system.

1. Clone project code

  1. git clone https://github.com/openspug/spug /data/spug
  2. cd /data/spug
  3. git checkout x.x.x # x.x.x is the specified release version, for example git checkout v2.2.2

2. Download the compiled and packaged front-end project

Extract the downloaded front-end package to the specified directory, assuming web_x.y.z.tar.gz is the compressed package you downloaded.

  1. tar xf web_x.y.z.tar.gz -C /data/spug/spug_web/;

3. Create running environment

If you need to use the regular release function, you need to install git v2.17.0+.

  1. # Install dependencies
  2. yum install mariadb-devel python3-devel gcc openldap-devel redis nginx supervisor rsync sshfs
  3. # Create virtual environment
  4. cd /data/spug/spug_api
  5. python3 -m venv venv
  6. source venv/bin/activate
  7. # Install python packages
  8. pip install -U pip setuptools
  9. pip install -r requirements.txt
  10. pip install gunicorn mysqlclient

4. Modify backend configuration

The backend uses the Sqlite database by default. Modify the configuration to use MYSQL as the backend database. How to use SqlServer database?

Manual Deployment - 图2warning

Create a overrides.py file in the spug_api/spug/ directory. The backend service will automatically overwrite the default configuration after startup, avoiding direct modification of settings.py to facilitate the acquisition of new versions in the future.

spug_api/spug/overrides.py

  1. DEBUG = False
  2. DATABASES = {
  3. 'default': {
  4. 'ATOMIC_REQUESTS': True,
  5. 'ENGINE': 'django.db.backends.mysql',
  6. 'Name': 'spug', # Replace with your own database name, please create a database with the encoding of utf8mb4 in advance
  7. 'USER': 'spug_user', # Database user name
  8. 'PASSWORD': 'spug_passwd', # Database password
  9. 'HOST': '127.0.0.1', # Database host
  10. 'OPTIONS': {
  11. 'charset': 'utf8mb4',
  12. 'sql_mode': 'STRICT_TRANS_TABLES',
  13. #'unix_socket': '/opt/mysql/mysql.sock' # if the database is on the local machine and is not installed by default, you need to specify the socket file path of Mysql
  14. }
  15. }
  16. }

5. Initialize the database

  1. cd /data/spug/spug_api
  2. python manage.py updatedb

6. Create default administrator account

  1. python manage.py user add -u admin -p spug.dev -s -n admin
  2. # -u username
  3. # -p password
  4. # -s superuser
  5. # -n nickname

7. Create startup service script

/etc/supervisord.d/spug.ini

  1. [program:spug-api]
  2. command = bash /data/spug/spug_api/tools/start-api.sh
  3. autostart = true
  4. stdout_logfile = /data/spug/spug_api/logs/api.log
  5. redirect_stderr = true
  6. [program:spug-ws]
  7. command = bash /data/spug/spug_api/tools/start-ws.sh
  8. autostart = true
  9. stdout_logfile = /data/spug/spug_api/logs/ws.log
  10. redirect_stderr = true
  11. [program:spug-worker]
  12. command = bash /data/spug/spug_api/tools/start-worker.sh
  13. autostart = true
  14. stdout_logfile = /data/spug/spug_api/logs/worker.log
  15. redirect_stderr = true
  16. [program:spug-monitor]
  17. command = bash /data/spug/spug_api/tools/start-monitor.sh
  18. autostart = true
  19. stdout_logfile = /data/spug/spug_api/logs/monitor.log
  20. redirect_stderr = true
  21. [program:spug-scheduler]
  22. command = bash /data/spug/spug_api/tools/start-scheduler.sh
  23. autostart = true
  24. stdout_logfile = /data/spug/spug_api/logs/scheduler.log
  25. redirect_stderr = true

8. 创建前端nginx配置文件

8. Create front-end nginx configuration file

/etc/nginx/conf.d/spug.conf

  1. server {
  2. listen 80;
  3. server_name _; # Modify to custom access domain name
  4. root /data/spug/spug_web/build/;
  5. client_max_body_size 20m; # This value will affect the size limit of the file that can be uploaded by the file manager. Please adjust it reasonably
  6. gzip on;
  7. gzip_min_length 1k;
  8. gzip_buffers 4 16k;
  9. gzip_http_version 1.1;
  10. gzip_comp_level 7;
  11. gzip_types text/plain text/css text/javascript application/javascript application/json;
  12. gzip_vary on;
  13. location ^~ /api/ {
  14. rewrite ^/api(.*) $1 break;
  15. proxy_pass http://127.0.0.1:9001;
  16. proxy_read_timeout 180s;
  17. proxy_redirect off;
  18. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  19. }
  20. location ^~ /api/ws/ {
  21. rewrite ^/api(.*) $1 break;
  22. proxy_pass http://127.0.0.1:9002;
  23. proxy_http_version 1.1;
  24. proxy_set_header Upgrade $http_upgrade;
  25. proxy_set_header Connection "Upgrade";
  26. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  27. }
  28. location / {
  29. try_files $uri /index.html;
  30. }
  31. }

Manual Deployment - 图3warning

Warning: If you do not specify server_name in spug.conf, you need to comment or delete the default server block in /etc/nginx/nginx.conf to access normally, otherwise you will open the Nginx default page.

9. Start service

  1. # Set boot startup
  2. systemctl enable nginx
  3. systemctl enable redis
  4. systemctl enable supervisord
  5. # Start service
  6. systemctl restart nginx
  7. systemctl restart redis
  8. systemctl restart supervisord

10. Access test

By accessing the browser for testing.

11. Security Suggestions

  • Please make sure that the installed Redis only listens on 127.0.0.1. if you need to use a Redis service with password authentication, please refer to How to configure and use a Redis service with a password?

  • Please make sure that the X-Real-IP in the HTTP Header of the request received by the server is the real client address. Spug will use this IP to improve security (when the IP of the logged-in user changes, the Token will automatically expire). Reference document.