### Copy Environment Example File (Windows) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Copies the example environment file (.env.example) to a development environment file (.env.development) on Windows systems. This file is used to store environment-specific configurations. ```bash copy .env.example .env.development ``` -------------------------------- ### Copy Environment Example File (Linux/macOS) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Copies the example environment file (.env.example) to a development environment file (.env.development) on Linux or macOS systems. This file is used to store environment-specific configurations. ```bash cp .env.example .env.development ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Installs all the necessary Node.js dependencies listed in the project's package.json file using npm. This command should be run after cloning the repository and navigating to the project directory. ```bash npm install ``` -------------------------------- ### Preview Build Output Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Starts a local development server to preview the production build output. This allows you to test the optimized application before deploying it. ```bash npm run preview ``` -------------------------------- ### Start Development Server Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Starts the development server for the project using npm. This command compiles the code, watches for changes, and provides a hot-reloading development environment. It typically runs on a default port like 3000. ```bash npm run dev ``` -------------------------------- ### Install Redis on macOS Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Installs Redis using Homebrew on macOS and starts the Redis service. This command ensures the caching and message broker service is running. ```bash brew install redis brew services start redis ``` -------------------------------- ### Install nvm on macOS/Linux Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Installs Node Version Manager (nvm) using a curl or wget script. This is the recommended method for managing Node.js versions. It downloads and executes an installation script from GitHub. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash # 或使用 wget wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash ``` -------------------------------- ### Install PostgreSQL on Linux (Ubuntu/Debian) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Installs PostgreSQL and its contrib package on Ubuntu/Debian systems, starts the service, and sets a password for the default 'postgres' user. This command sets up the necessary database server. ```bash # Install PostgreSQL sudo apt update sudo apt install -y postgresql postgresql-contrib # Start service sudo systemctl start postgresql sudo systemctl enable postgresql # Set password sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_secure_password';" ``` -------------------------------- ### Create .env File from Example Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Copies the example environment file (.env.example) to a new file named .env. This is the first step in configuring application-specific settings. ```bash cp .env.example .env ``` -------------------------------- ### Install Redis on Linux (Ubuntu/Debian) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Installs the Redis server on Ubuntu/Debian systems and starts the service, ensuring it's enabled to run on boot. This command sets up the required Redis instance. ```bash sudo apt update sudo apt install -y redis-server sudo systemctl start redis sudo systemctl enable redis ``` -------------------------------- ### Clone Project Repository Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Clones the frontend repository for the honeypot analysis system from a GitHub URL. It then navigates into the frontend directory. This assumes Git is installed and configured. ```bash git clone https://github.com/your-organization/honeypot-analytics-system.git cd honeypot-analytics-system/frontend ``` -------------------------------- ### Start Development Server on Specific Port Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Starts the development server and allows specifying a custom port number using the --port flag. This is useful if the default port is already in use. ```bash npm run dev -- --port 3001 ``` -------------------------------- ### Environment Variables Configuration Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Example content of a .env.development file, showing key-value pairs for configuring application settings like API base URL, WebSocket URL, Node environment, application title, and mock data usage. ```env # API 基础 URL VITE_API_BASE_URL=http://localhost:8000/api # WebSocket URL VITE_WS_BASE_URL=ws://localhost:8000/ws # 开发环境标志 NODE_ENV=development # 应用标题 VITE_APP_TITLE=蜜罐分析系统 # 是否使用模拟数据(开发时可设置为 true) VITE_USE_MOCK_DATA=false ``` -------------------------------- ### Install PostgreSQL 14 on macOS Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Installs PostgreSQL version 14 using Homebrew on macOS and starts the PostgreSQL service. This command ensures the database server is running and accessible. ```bash brew install postgresql@14 brew services start postgresql ``` -------------------------------- ### Install and Configure PostgreSQL (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md This section details the installation of PostgreSQL 15 on a Debian-based system. It includes adding the official PostgreSQL repository, installing the server and client packages, enabling and starting the PostgreSQL service, and finally, creating a database user, database, and granting privileges. This is crucial for the system's data storage. ```bash # 添加 PostgreSQL 官方仓库 curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list # 更新并安装 PostgreSQL sudo apt update sudo apt install -y postgresql-15 postgresql-client-15 # 启动 PostgreSQL 服务 sudo systemctl enable postgresql sudo systemctl start postgresql # 创建数据库和用户 sudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'password';" sudo -u postgres psql -c "CREATE DATABASE example_db OWNER admin;" sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE example_db TO admin;" ``` -------------------------------- ### Install Project Dependencies (Python) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Installs project dependencies from requirements.txt and optionally requirements-dev.txt after activating the virtual environment. This ensures all necessary libraries are installed for the backend. ```bash # Navigate to the backend directory cd /path/to/honeypot-analytics-system/backend # Upgrade pip pip install --upgrade pip # Install dependencies pip install -r requirements.txt # Install development dependencies (optional) pip install -r requirements-dev.txt ``` -------------------------------- ### Example .env Configuration Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md An example of the .env file content, showing key configurations for database connections (PostgreSQL and Redis), application secrets, token expiration, API prefix, CORS origins, logging, and environment settings. This file should be updated with actual values. ```env # Database connection DATABASE_URL="postgresql+asyncpg://admin:password@localhost:5432/honeypot_analytics" TEST_DATABASE_URL="postgresql+asyncpg://admin:password@localhost:5432/honeypot_analytics_test" # Redis connection REDIS_URL="redis://localhost:6379/0" # Application configuration SECRET_KEY="your-secret-key-here-change-in-production" ALGORITHM="HS256" ACCESS_TOKEN_EXPIRE_MINUTES=30 # API configuration API_PREFIX="/v1" # CORS configuration BACKEND_CORS_ORIGINS=["http://localhost:3000", "http://localhost:8080"] # Logging configuration LOG_LEVEL="INFO" # Environment configuration ENVIRONMENT="development" DEBUG=True ``` -------------------------------- ### Start Development Server via Python Module Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md An alternative method to start the FastAPI development server using Uvicorn as a Python module. This achieves the same result as the previous command and is useful if direct Uvicorn execution is not preferred. ```bash # Activate virtual environment (Linux/macOS) source venv/bin/activate # Or activate virtual environment (Windows) # venv\Scripts\activate # Start server python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload ``` -------------------------------- ### Curl Authentication Example Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/02_api_documentation/01_api_overview.md Provides command-line examples using `curl` to demonstrate the authentication process. It shows how to obtain an access token via POST and how to use it in subsequent GET requests. ```bash # 获取访问令牌 curl -X POST http://localhost:8000/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"username": "admin", "password": "password123"}' # 使用令牌访问API curl -X GET http://localhost:8000/v1/attacks \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Start Development Server with Uvicorn Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Starts the FastAPI development server using Uvicorn. This command reloads the server automatically on code changes, making development more efficient. Ensure the virtual environment is activated. ```bash # Activate virtual environment (Linux/macOS) source venv/bin/activate # Or activate virtual environment (Windows) # venv\Scripts\activate # Start server uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload ``` -------------------------------- ### Install Project Dependencies (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md This command installs all the Python packages required by the project from the `requirements.txt` file using pip within the activated virtual environment. It also shows a commented-out option for installing production-specific dependencies from `requirements-prod.txt`. ```bash # 安装依赖 pip install -r requirements.txt # 如果有生产环境特定的依赖文件 # pip install -r requirements-prod.txt ``` -------------------------------- ### Verify Python Installation (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Commands to verify the installation of Python and pip. This is a crucial step after installing Python to ensure it's correctly set up and accessible in the system's PATH. ```bash python --version pip --version ``` -------------------------------- ### GET /api/v1/development/environment/setup Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/03_api_modules/23_development_environment.md Retrieves the setup steps and guidelines for configuring the development environment. This endpoint is only accessible within the development environment. ```APIDOC ## GET /api/v1/development/environment/setup ### Description Get the setup steps and guidelines for the development environment. ### Method GET ### Endpoint /api/v1/development/environment/setup ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200 OK) (Response format not specified in the provided text, typically returns setup instructions or a status.) #### Response Example (Example response not provided.) ``` -------------------------------- ### Install Dependencies with Legacy Peer Deps Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Installs project dependencies using npm, with the `--legacy-peer-deps` flag enabled. This flag ignores peer dependency conflicts and can be useful for resolving installation issues. ```bash npm install --legacy-peer-deps ``` -------------------------------- ### Prepare Operating System for Deployment (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md This snippet shows how to prepare the Linux operating system for deployment by updating packages, installing essential system dependencies like build tools and Git, creating a dedicated user for the project, and switching to that user. It's a foundational step for setting up the environment. ```bash # 更新系统软件包 apt update && apt upgrade -y # 安装必要的系统依赖 apt install -y build-essential libpq-dev git curl wget software-properties-common # 创建项目用户 useradd -m -s /bin/bash honeypot # 切换到项目用户 su - honeypot ``` -------------------------------- ### Build for Production Environment Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Builds the project for production deployment. This build is typically optimized for performance and size, and the output is usually placed in a 'dist' directory. ```bash npm run build ``` -------------------------------- ### Troubleshoot Dependency Installation (NPM Registry) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Provides a command to set the npm registry to a mirror (npmmirror.com). This can help resolve dependency installation issues, especially if the default npm registry is slow or blocked. ```bash npm config set registry https://registry.npmmirror.com ``` -------------------------------- ### Install and Use Node.js with nvm Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Installs a specific Node.js version (v18 in this case) using nvm and then sets it as the active version for the current session. This command is applicable to both macOS/Linux and Windows after nvm is set up. ```bash nvm install 18 nvm use 18 ``` -------------------------------- ### Build for Development Environment Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Builds the project specifically for a development environment. This build may include debugging information or be optimized differently than a production build. ```bash npm run build:dev ``` -------------------------------- ### Install Redis (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md This snippet demonstrates how to install Redis on a Debian-based system using a PPA. It adds the Redis repository, updates the package list, installs the `redis-stack-server` package, and then enables and starts the Redis service. Redis is used for caching and as a message queue in the system. ```bash # 添加 Redis 官方仓库 sudo add-apt-repository ppa:redis/redis-stack-server -y # 更新并安装 Redis sudo apt update sudo apt install -y redis-stack-server # 启动 Redis 服务 sudo systemctl enable redis-stack-server sudo systemctl start redis-stack-server ``` -------------------------------- ### Initialize Database Migrations (Python) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/01_environment_setup.md Runs the database initialization script to set up the database schema. This command should be executed after activating the virtual environment and configuring the .env file. ```python # Activate virtual environment (Linux/macOS) source venv/bin/activate # Or activate virtual environment (Windows) # venv\Scripts\activate # Initialize database python -m app.core.db.init_db ``` -------------------------------- ### Troubleshooting Application Startup Failures Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md Offers steps to resolve application startup issues, including checking application logs (systemd or Docker Compose), verifying environment variables, identifying port conflicts, and ensuring all dependencies are installed. ```bash # 检查应用日志 sudo journalctl -u honeypot-analytics.service -f # 或 docker-compose logs -f backend # 检查端口占用 sudo lsof -i :8000 ``` -------------------------------- ### Load nvm in macOS/Linux Terminal Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Loads the nvm environment variables and completion script into the current terminal session on macOS and Linux. This command should be run after installing nvm. ```bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion ``` -------------------------------- ### Check Port Usage (Windows) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Checks which process is using a specific port (e.g., 3000) on Windows. This command is useful for diagnosing issues where a server cannot start because the port is already occupied. ```bash netstat -ano | findstr :3000 ``` -------------------------------- ### Initialize Database Migrations and Seed Data (Bash) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/06_deployment_guide.md This section provides commands to initialize the database. It includes running database migrations using Alembic to set up the schema, or alternatively, running an application-specific database initialization script. It also shows an optional command to load initial seed data into the database. ```bash # 运行数据库迁移(如果使用Alembic) alembic upgrade head # 或使用应用内置的初始化脚本 python -m app.scripts.init_db # 可选:加载初始数据 python -m app.scripts.seed ``` -------------------------------- ### Troubleshoot Dependency Installation (NPM Cache) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Clears the npm cache forcefully and then attempts to reinstall dependencies. This is a common step to resolve issues caused by corrupted or outdated cached packages. ```bash npm cache clean --force ``` -------------------------------- ### Example .env file for application configuration Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/backend/docs/04_development_guide/04_component_development.md A sample .env file demonstrating how to configure the application settings. It includes placeholders for database URL, Redis URL, and JWT secret key. ```dotenv # .env # 数据库连接信息 DATABASE_URL="postgresql://admin:password@localhost:5432/example_db" # Redis连接信息 REDIS_URL="redis://localhost:6379/0" # JWT密钥 SECRET_KEY="your-secret-key-here" ``` -------------------------------- ### Check Port Usage (Linux/macOS) Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/01_environment_setup.md Checks which process is using a specific port (e.g., 3000) on Linux or macOS. This command is useful for diagnosing issues where a server cannot start because the port is already occupied. ```bash lsof -i :3000 ``` -------------------------------- ### Install Project Dependencies using npm Source: https://github.com/sinaolow/honeypot-log-analysis-system/blob/main/honeypot-analytics-system/frontend/docs/04_development_guide/06_deployment_guide.md Installs project dependencies using npm. `npm ci --production` is used to install only production dependencies, ensuring a clean and optimized installation for deployment. `npm install` installs all dependencies, including development ones, typically used during development or CI/CD pipelines. ```bash # Install production dependencies npm ci --production # Or install all dependencies (including development dependencies) npm install ```