瀏覽代碼

调整项目正测服务器部署简易读取配置

yf_fyh 3 年之前
父節點
當前提交
596a1fbc2b
共有 8 個文件被更改,包括 80 次插入50 次删除
  1. 2 2
      bigdataAPI.ini
  2. 24 44
      bigdataAPI/settings.py
  3. 26 0
      formal.json
  4. 二進制
      requirements.txt
  5. 26 0
      test.json
  6. 0 1
      utils/JWTAuthentication_diy.py
  7. 2 2
      utils/db_utils.py
  8. 0 1
      utils/permissions.py

+ 2 - 2
bigdataAPI.ini

@@ -25,7 +25,7 @@ daemonize=/data/pycharm/bigdataAPI/bigdataAPI.log
 # 服务停止时,自动移除unix socket和pid文件
 vacuum=True
 # 为每个工作进程设置请求数的上限。当处理的请求总数超过这个量,进程回收重启。
-max-requests=10000
+max-requests=5000
 # 当一个请求花费的时间超过这个时间,那么这个请求都会被丢弃。
 harakiri=3600
 #当一个请求被harakiri杀掉会输出一条日志
@@ -35,7 +35,7 @@ buffer-size=655360
 # 如果http请求体的大小超过指定的限制,打开http body缓冲,这里为64k
 post-buffering=655360
 #开启内存使用情况报告
-memory-report=true
+# memory-report=true
 #设置平滑的重启(直到处理完接收到的请求)的长等待时间(秒)
 reload-mercy=10
 #设置工作进程使用虚拟内存超过多少MB就回收重启

+ 24 - 44
bigdataAPI/settings.py

@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
 
 import os
 import datetime
+import json
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -23,7 +24,15 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 SECRET_KEY = '$rs)*w)9gh)nkf1=@r$2xguf1b(qz8ba!%hm8lwt54ti3_da^b'
 
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = False
+DEBUG = True
+
+if DEBUG == True:
+    config_path = "test.json"
+else:
+    config_path = "formal.json"
+with open(config_path,"r") as f:
+    config_data = f.read()
+config = json.loads(config_data)
 
 ALLOWED_HOSTS = ['*']
 
@@ -78,50 +87,28 @@ WSGI_APPLICATION = 'bigdataAPI.wsgi.application'
 # Database
 # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
 
-
-# USER_CONFIG = {
-#     'mysql': {
-#         'host': 'localhost',
-#         'user': 'root',
-#         'pwd': 'yfkj@6020',
-#         'port': 3306
-#     },
-#     'mongodb': {
-#         'host': 'localhost',
-#         'user': 'root',
-#         'pwd': 'yfkj@6020',
-#         'port': 27017
-#     }
-# }
-USER_CONFIG = {
-    'mysql': {
-        'host': 'localhost',
-        'user': 'root',
-        'pwd': 'yfkj@6020',
-        'port': 61882
-    },
-    'mongodb': {
-        'host': 'localhost',
-        'user': 'root',
-        'pwd': 'yfkj@6020',
-        'port': 57017
-    }
-}
-
-
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'bigdata_api',
-        'USER': 'api',
-        'PASSWORD': 'yfkj@6020',
-        'HOST': '127.0.0.1',
-        'PORT': 61882,
-        # 'PORT': 3306,
+        'USER': config["mysql"]["user"],
+        'PASSWORD': config["mysql"]["pwd"],
+        'HOST': config["mysql"]["host"],
+        'PORT': config["mysql"]["port"],
         'OPTIONS': {'charset': 'utf8mb4'}
     }
 }
 
+CACHES = {
+    'default': {
+        'BACKEND': 'django_redis.cache.RedisCache',
+        "LOCATION": config["redis"]["url"],
+        "OPTIONS": {
+            "CLIENT_CLASS": "django_redis.client.DefaultClient",
+        }
+    }
+}
+
 # Password validation
 # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
 
@@ -175,11 +162,4 @@ REST_FRAMEWORK = {
 
 JWT_AUTH = {
     'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
-}
-
-
-CACHES = {
-    'default': {
-        'BACKEND': 'uwsgicache.UWSGICache',
-    }
 }

+ 26 - 0
formal.json

@@ -0,0 +1,26 @@
+{
+	"mysql": {
+		"host": "localhost",
+		"port": 61882,
+		"user": "api",
+		"pwd": "yfkj@6020"
+	},
+	"redis": {
+		"host": "localhost",
+		"port": "61881",
+		"password": "yf6021",
+        "url": "redis://yf6021@127.0.0.1:61881/12"
+	},
+	"bigdatamysql": {
+		"host": "localhost",
+		"port": 61882,
+		"user": "root",
+		"pwd": "yfkj@6020"
+	},
+	"bigdatamongo": {
+		"host": "localhost",
+		"port": 57017,
+		"user": "root",
+		"pwd": "yfkj@6020"
+	}
+}

二進制
requirements.txt


+ 26 - 0
test.json

@@ -0,0 +1,26 @@
+{
+	"mysql": {
+		"host": "localhost",
+		"port": 3306,
+		"user": "api",
+		"pwd": "yfkj@6020"
+	},
+	"redis": {
+		"host": "localhost",
+		"port": "56379",
+		"password": "yf6021",
+        "url": "redis://yf6021@127.0.0.1:56379/12"
+	},
+	"bigdatamysql": {
+		"host": "localhost",
+		"port": 3306,
+		"user": "root",
+		"pwd": "yfkj@6020"
+	},
+	"bigdatamongo": {
+		"host": "localhost",
+		"port": 27017,
+		"user": "root",
+		"pwd": "yfkj@6020"
+	}
+}

+ 0 - 1
utils/JWTAuthentication_diy.py

@@ -63,7 +63,6 @@ class APIAuthentication(BaseAuthentication):
     def authenticate(self, request):
         token = request.META.get('HTTP_AUTHORIZATION')
         if token:
-            # uid_sql = 896
             uid_cache = self.cache.get(token)
             if uid_cache:
                 return (uid_cache,token)

+ 2 - 2
utils/db_utils.py

@@ -7,7 +7,7 @@ from django.conf import settings
 
 class MySQLTool:
     def __init__(self):
-        config = settings.USER_CONFIG['mysql']
+        config = settings.config["bigdatamysql"]
         self.conn = pymysql.connect(
             host=config['host'], user=config['user'],
             password=config['pwd'], port=config['port'],
@@ -27,7 +27,7 @@ class MySQLTool:
 
 class MongoDBTools:
     def __init__(self, db_name, table_name):
-        config = settings.USER_CONFIG['mongodb']
+        config = settings.config["bigdatamongo"]
         host, port = config['host'], config['port']
         user, password = config['user'], config['pwd']
         self.client = pymongo.MongoClient(host=host, port=port, username=user, password=password)

+ 0 - 1
utils/permissions.py

@@ -34,7 +34,6 @@ class QXZDeviceDetailPermission(BasePermission):
     
     def has_permission(self, request, view):
         uid = request.user
-        # uid = 896
         device_id = request.query_params.get("device_id")
         if device_id is None:
             return True