堡壘機的登入,用于排查問題
登入已有的穩定的堡壘機
再輸入遺下指令:
ssh [email protected]*****
一、代碼結構https://coding.jd.com/lmmlmm/lowwifitest/tree/master
Dockerfile檔案
FROM is.jd.com/jdos_base/jd-centos7.2v190125-python3.7:latest
MAINTAINER cdrd-im-lmmlmm
ADD . /export/servers/
RUN chown -R admin:admin /export && \
# chmod +x /export/servers/start.sh && \
pip install --upgrade pip -i https://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple && \
wget http://storage.jd.local/im-tools/gevent-1.4.0-cp37-cp37m-manylinux1_x86_64.whl && \
wget http://storage.jd.local/im-tools/greenlet-0.4.15-cp37-cp37m-manylinux1_x86_64.whl && \
pip install -U --force-reinstall --no-binary :all: greenlet-0.4.15-cp37-cp37m-manylinux1_x86_64.whl gevent-1.4.0-cp37-cp37m-manylinux1_x86_64.whl && \
pip install -r /export/servers/requirements.txt -i https://pypi.douban.com/simple/ --trusted-host=pypi.douban.com/simple && \
mv /export /export_bak && \
echo '4d65a6e1c91245c0af92d2ce0a5197d5' |passwd root --stdin
ENTRYPOINT /usr/sbin/sshd && cp -a /export_bak/* /export/ && source ~/.bashrc && su -c "nohup python3 /export/servers/run_server.py >/dev/null 2>&1 &" && sleep 9999999d
日志檔案
import logging
import os
# from configgg.conf import LOG_PATH
# print(LOG_PATH)
# log_path = os.path.dirname(getcwd.get_cwd())
# print(log_path)
class Logger:
def __init__(self, loggername,log_path="."):
# 建立一個logger
self.logger = logging.getLogger(loggername)
self.logger.setLevel(logging.DEBUG)
self.log_path=log_path
# 建立一個handler,用于寫入日志檔案
# log_path = os.path.dirname(getcwd.get_cwd())+"/logs/" # 指定檔案輸出路徑,注意logs是個檔案夾,一定要加上/,不然會導緻輸出路徑錯誤,把logs變成檔案名的一部分了
#log_path = "./logs/" # 指定檔案輸出路徑,注意logs是個檔案夾,一定要加上/,不然會導緻輸出路徑錯誤,把logs變成檔案名的一部分了
logname = os.path.join(self.log_path,'lowwifitest.log') # 指定輸出的日志檔案名
fh = logging.FileHandler(logname, encoding='utf-8') # 指定utf-8格式編碼,避免輸出的日志文本亂碼
fh.setLevel(logging.DEBUG)
# 建立一個handler,用于将日志輸出到控制台
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# 定義handler的輸出格式
formatter = logging.Formatter('%(asctime)s-%(name)s-%(levelname)s-%(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# 給logger添加handler
self.logger.addHandler(fh)
self.logger.addHandler(ch)
def get_log(self) -> object:
"""定義一個函數,回調logger執行個體"""
return self.logger
if __name__ == '__main__':
# t = Logger("hmk").get_log().debug("User %s is loging" % 'jeck')
log=Logger("udp").get_log()
log.info("xxx")
log.debug("XXX")
在其他地方需要調用日志的話 需要
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
print(BASE_PATH)
LOG_PATH = os.path.join(BASE_PATH, "log")
print(LOG_PATH)
log=Logger("run_server",LOG_PATH).get_log()
eg: