- Manual Deployment
- Requirements Environment
- Installation Steps
- 1. Clone project code
- 2. Download the compiled and packaged front-end project
- 3. Create running environment
- 4. Modify backend configuration
- 5. Initialize the database
- 6. Create default administrator account
- 7. Create startup service script
- 8. 创建前端nginx配置文件
- 8. Create front-end nginx configuration file
- 9. Start service
- 10. Access test
- 11. Security Suggestions
Manual Deployment
warning
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 needs2.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
git clone https://github.com/openspug/spug /data/spug
cd /data/spug
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.
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+.
# Install dependencies
yum install mariadb-devel python3-devel gcc openldap-devel redis nginx supervisor rsync sshfs
# Create virtual environment
cd /data/spug/spug_api
python3 -m venv venv
source venv/bin/activate
# Install python packages
pip install -U pip setuptools
pip install -r requirements.txt
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?
warning
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
DEBUG = False
DATABASES = {
'default': {
'ATOMIC_REQUESTS': True,
'ENGINE': 'django.db.backends.mysql',
'Name': 'spug', # Replace with your own database name, please create a database with the encoding of utf8mb4 in advance
'USER': 'spug_user', # Database user name
'PASSWORD': 'spug_passwd', # Database password
'HOST': '127.0.0.1', # Database host
'OPTIONS': {
'charset': 'utf8mb4',
'sql_mode': 'STRICT_TRANS_TABLES',
#'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
}
}
}
5. Initialize the database
cd /data/spug/spug_api
python manage.py updatedb
6. Create default administrator account
python manage.py user add -u admin -p spug.dev -s -n admin
# -u username
# -p password
# -s superuser
# -n nickname
7. Create startup service script
/etc/supervisord.d/spug.ini
[program:spug-api]
command = bash /data/spug/spug_api/tools/start-api.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/api.log
redirect_stderr = true
[program:spug-ws]
command = bash /data/spug/spug_api/tools/start-ws.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/ws.log
redirect_stderr = true
[program:spug-worker]
command = bash /data/spug/spug_api/tools/start-worker.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/worker.log
redirect_stderr = true
[program:spug-monitor]
command = bash /data/spug/spug_api/tools/start-monitor.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/monitor.log
redirect_stderr = true
[program:spug-scheduler]
command = bash /data/spug/spug_api/tools/start-scheduler.sh
autostart = true
stdout_logfile = /data/spug/spug_api/logs/scheduler.log
redirect_stderr = true
8. 创建前端nginx配置文件
8. Create front-end nginx configuration file
/etc/nginx/conf.d/spug.conf
server {
listen 80;
server_name _; # Modify to custom access domain name
root /data/spug/spug_web/build/;
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
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 7;
gzip_types text/plain text/css text/javascript application/javascript application/json;
gzip_vary on;
location ^~ /api/ {
rewrite ^/api(.*) $1 break;
proxy_pass http://127.0.0.1:9001;
proxy_read_timeout 180s;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^~ /api/ws/ {
rewrite ^/api(.*) $1 break;
proxy_pass http://127.0.0.1:9002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
try_files $uri /index.html;
}
}
warning
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
# Set boot startup
systemctl enable nginx
systemctl enable redis
systemctl enable supervisord
# Start service
systemctl restart nginx
systemctl restart redis
systemctl restart supervisord
10. Access test
By accessing the browser for testing.
11. Security Suggestions
Please make sure that the installed
Redis
only listens on127.0.0.1
. if you need to use aRedis
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 theHTTP 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.