Search

EC2

sudo yum install python3 python3-pip -y pip3 install flask
Shell
복사
mkdir log touch log/app.log
Shell
복사
cat << EOF > app.py #!/usr/bin/python3 from flask import Flask, abort, request, jsonify import logging from datetime import datetime import os os.makedirs("log", exist_ok=True) # Configure custom logging logging.basicConfig( format='%(message)s', filename="log/app.log", level=logging.INFO ) # Disable Flask/Werkzeug default logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app = Flask(__name__) @app.after_request def log_request(response): timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # Format time without milliseconds log_message = f"[{timestamp}] {request.remote_addr} - - {request.method} {request.full_path.rstrip('?')} {request.environ.get('SERVER_PROTOCOL')} {response.status_code}" logging.info(log_message) return response @app.route('/v1/color', methods=['GET']) def get_color(): try: color_name = request.args['name'] color_hash = request.args['hash'] ret = {'code': '', 'name': ''} if color_name == 'red': ret['code'] = 'f34a07' ret['name'] = 'orange' elif color_name == 'blue': ret['code'] = '71f0f9' ret['name'] = 'sky' else: ret['code'] = 'ff00ff' ret['name'] = 'pink' return jsonify(ret), 200 except Exception as e: logging.error(str(e)) abort(500) @app.route('/health', methods=['GET']) def get_health(): try: ret = {'status': 'ok'} return jsonify(ret), 200 except Exception as e: logging.error(str(e)) abort(500) if __name__ == "__main__": app.run(host='0.0.0.0', port=8080) EOF
Shell
복사
nohup python3 app.py 2>&1 &
Shell
복사
curl https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh | sh sudo systemctl start fluent-bit sudo systemctl enable fluent-bit sudo ln -s /opt/fluent-bit/bin/fluent-bit /usr/local/bin/fluent-bit sudo systemctl status fluent-bit
Shell
복사
cd /etc/fluent-bit
Shell
복사
fluent-bit.conf
sudo vim fluent-bit.conf
Shell
복사
parsers.conf
sudo vim parsers.conf
Shell
복사
sudo systemctl restart fluent-bit
Shell
복사