数据库管理平台archery搭建

#######################################

archery是一款Django+Python+Bootstrap的Web应用

搭建archery并不是一件简单的事,要想搭建一个高可用,需要做更多

MySQL

Redis

Golang

Python

keepalived

 

 

 

 

root@a8-cloud-apple-db08 Archery]# virtualenv-3.9.10 venv --python=python3-3.9.10
created virtual environment CPython3.9.10.final.0-64 in 816ms creator CPython3Posix(dest=/root/scripts/Archery/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==23.0.1, setuptools==67.4.0, wheel==0.38.4 activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

 

 

(venv) [root@a8-cloud-apple-db08 Archery]# pip3-3.9.10 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

 

 

 

 

 

 

libmysqlclient.so.20找不到的问题:

 

 

 

 

 

(venv) [root@a8-cloud-apple-db08 Archery]# find / -name "libmysqlclient.so.20"
/home/work/mysql_3306/lib/libmysqlclient.so.20
/root/scripts/mysql-5.7.40-linux-glibc2.12-x86_64/lib/libmysqlclient.so.20
(venv) [root@a8-cloud-apple-db08 Archery]# ln -s /home/work/mysql_3306/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20

 

 

 

 执行./venv/bin/python3-3.9.10 manage.py migrate,说明需要先在mysql中创建archery库即可

(venv) [root@a8-cloud-apple-db08 Archery]# ./venv/bin/python3-3.9.10  manage.py migrate
import local settings failed, ignored
Traceback (most recent call last):
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 247, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1049, "Unknown database 'archery'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/scripts/Archery/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 97, in handle
    self.check(databases=[database])
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/management/base.py", line 475, in check
    all_issues = checks.run_checks(
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/core/checks/database.py", line 13, in check_database_backends
    issues.extend(conn.validation.check(**kwargs))
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/validation.py", line 9, in check
    issues.extend(self._check_sql_mode(**kwargs))
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/validation.py", line 14, in _check_sql_mode
    self.connection.sql_mode & {"STRICT_TRANS_TABLES", "STRICT_ALL_TABLES"}
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 443, in sql_mode
    sql_mode = self.mysql_server_data["sql_mode"]
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 399, in mysql_server_data
    with self.temporary_connection() as cursor:
  File "/usr/local/python-3.9.10/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 694, in temporary_connection
    with self.cursor() as cursor:
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 323, in cursor
    return self._cursor()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 299, in _cursor
    self.ensure_connection()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 247, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/MySQLdb/__init__.py", line 130, in Connect
    return Connection(*args, **kwargs)
  File "/root/scripts/Archery/venv/lib/python3.9/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1049, "Unknown database 'archery'")

 

创建archery库即可

mysql> CREATE DATABASE `archery` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| archery            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql>

 

 

 

(venv) [root@a8-cloud-apple-db08 Archery]# ./venv/bin/python3-3.9.10  manage.py dbshell<sql/fixtures/auth_group.sql
import local settings failed, ignored
(venv) [root@a8-cloud-apple-db08 Archery]# ./venv/bin/python3-3.9.10  manage.py dbshell<src/init_sql/mysql_slow_query_review.sql
import local settings failed, ignored
(venv) [root@a8-cloud-apple-db08 Archery]# ./venv/bin/python3-3.9.10  manage.py createsuperuser
import local settings failed, ignored
用户名: work
电子邮件地址: igoodful@qq.com
Password:
Password (again):
密码跟 用户名 太相似了。
密码长度太短。密码必须包含至少 9 个字符。
这个密码太常见了。
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
(venv) [root@a8-cloud-apple-db08 Archery]# 

 

 

1)安装nginx

yum -y install nginx

2)配置nginx

 [root@xxx nginx]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

# nginx配置示例
server{
listen 9123; # 监听的端口
server_name archery;
client_max_body_size 20M; # 处理Request Entity Too Large
proxy_read_timeout 600s; # 超时时间与Gunicorn超时时间设置一致,主要用于在线查询

location / {
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host:9123; # 解决重定向404的问题,和listen端口保持一致,如果是docker则和宿主机映射端口保持一

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /static {
alias /opt/archery/static; # 此处指向settings.py配置项STATIC_ROOT目录的绝对路径,用于nginx收集静态资源
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}

 

 

3)启动nginx

systemctl start nginx

 

 

 

 

 

 

 

 

 

 

 

问题在这里:需要

 

 

 启动:需要在虚拟环境下启动

 

 

 

 

 

 

 

 

 

 

##############################

posted @ 2023-04-11 20:23  igoodful  阅读(646)  评论(0编辑  收藏  举报