10秒内在Linux服务器上全自动完成DevOps基础设施搭建
这是一个DevOps领域的自动化工作流,包含 13 个节点。主要使用 Set, Ssh, Wait, ManualTrigger 等节点。 使用Docker、K8s、Jenkins和Grafana实现Linux服务器的DevOps基础设施自动化
- •无特殊前置要求,导入即可使用
使用的节点 (13)
分类
{
"id": "7p3d4ltVk0ICrNbX",
"meta": {
"instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
"templateCredsSetupCompleted": true
},
"name": "10秒内在 Linux 服务器上全自动完成 DevOps 基础设施搭建",
"tags": [],
"nodes": [
{
"id": "a0973093-3fba-485a-8100-ae3e54c9dc5f",
"name": "启动 DevOps 设置",
"type": "n8n-nodes-base.manualTrigger",
"position": [
0,
0
],
"parameters": {},
"typeVersion": 1
},
{
"id": "83e1e3a0-ef2f-45d7-bf73-a37f430ca622",
"name": "配置参数",
"type": "n8n-nodes-base.set",
"position": [
220,
0
],
"parameters": {
"values": {
"string": [
{
"name": "server_host",
"value": "={{ $json.server_host || '192.168.1.100' }}"
},
{
"name": "server_user",
"value": "{{ $json.server_user || 'root' }}"
},
{
"name": "server_password",
"value": "{{ $json.server_password || 'your_password' }}"
},
{
"name": "docker_version",
"value": "{{ $json.docker_version || 'latest' }}"
},
{
"name": "k8s_version",
"value": "{{ $json.k8s_version || '1.28' }}"
},
{
"name": "devops_user",
"value": "{{ $json.devops_user || 'devops' }}"
},
{
"name": "user_password",
"value": "{{ $json.user_password || 'devops123' }}"
},
{
"name": "cluster_name",
"value": "{{ $json.cluster_name || 'devops-cluster' }}"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "8f11ab98-149b-4192-8345-b278532d12ab",
"name": "系统准备",
"type": "n8n-nodes-base.ssh",
"position": [
660,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"🚀 DevOps Stack Setup - System Preparation\"\necho \"==========================================\"\n\n# Update system\napt update -y && apt upgrade -y\n\n# Install essential packages\napt install -y curl wget git vim nano build-essential software-properties-common \\\n apt-transport-https ca-certificates gnupg lsb-release jq unzip tree htop \\\n net-tools python3 python3-pip openssh-server ufw\n\n# Install Python packages for automation\npip3 install ansible boto3 kubernetes docker-compose\n\necho \"✅ System preparation completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "150157b9-6b02-4953-aa60-192f526d9f9a",
"name": "安装 Docker",
"type": "n8n-nodes-base.ssh",
"position": [
880,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"🐳 Installing Docker & Docker Compose\"\necho \"====================================\"\n\n# Add Docker GPG key\ncurl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg\n\n# Add Docker repository\necho \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\" | tee /etc/apt/sources.list.d/docker.list > /dev/null\n\n# Install Docker\napt update && apt install -y docker-ce docker-ce-cli containerd.io\n\n# Install Docker Compose\ncurl -L \"https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose\nchmod +x /usr/local/bin/docker-compose\n\n# Start Docker service\nsystemctl start docker && systemctl enable docker\n\necho \"Docker version: $(docker --version)\"\necho \"Docker Compose version: $(docker-compose --version)\"\necho \"✅ Docker installation completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "8e450cfb-3075-4d36-96bf-2a342e04dd87",
"name": "安装 Kubernetes",
"type": "n8n-nodes-base.ssh",
"position": [
1100,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"☸️ Installing Kubernetes (K3s)\"\necho \"==============================\"\n\n# Install K3s (lightweight Kubernetes)\ncurl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=\"v{{ $json.k8s_version }}.0+k3s1\" sh -\n\n# Install kubectl\ncurl -LO \"https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl\"\ninstall -o root -g root -m 0755 kubectl /usr/local/bin/kubectl\n\n# Install Helm\ncurl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash\n\n# Install k9s (Kubernetes CLI management tool)\ncurl -sS https://webinstall.dev/k9s | bash\n\n# Wait for K3s to be ready\nsleep 30\n\necho \"Kubernetes version: $(kubectl version --client --short)\"\necho \"Helm version: $(helm version --short)\"\necho \"✅ Kubernetes installation completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "8fccf05b-3eb2-401f-bbfb-96b3d1b9aa5f",
"name": "安装 Jenkins",
"type": "n8n-nodes-base.ssh",
"position": [
1320,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"🔧 Installing Jenkins\"\necho \"====================\"\n\n# Add Jenkins repository\nwget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | apt-key add -\necho \"deb https://pkg.jenkins.io/debian-stable binary/\" | tee /etc/apt/sources.list.d/jenkins.list\n\n# Install Java (required for Jenkins)\napt update && apt install -y openjdk-11-jdk\n\n# Install Jenkins\napt install -y jenkins\n\n# Start Jenkins\nsystemctl start jenkins && systemctl enable jenkins\n\n# Install Jenkins plugins via CLI (optional)\nwget http://localhost:8080/jnlpJars/jenkins-cli.jar\n\n# Create Jenkins Docker integration\nusermod -aG docker jenkins\n\necho \"Jenkins installed! Access at: http://$(hostname -I | awk '{print $1}'):8080\"\necho \"Initial admin password: $(cat /var/lib/jenkins/secrets/initialAdminPassword)\"\necho \"✅ Jenkins installation completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "668996d6-413b-4467-8ad0-600a5d3162cf",
"name": "安装监控工具",
"type": "n8n-nodes-base.ssh",
"position": [
1540,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"📊 Installing Prometheus & Grafana\"\necho \"==================================\"\n\n# Create monitoring namespace\nkubectl create namespace monitoring\n\n# Add Prometheus Helm repository\nhelm repo add prometheus-community https://prometheus-community.github.io/helm-charts\nhelm repo add grafana https://grafana.github.io/helm-charts\nhelm repo update\n\n# Install Prometheus using Helm\nhelm install prometheus prometheus-community/kube-prometheus-stack \\\n --namespace monitoring \\\n --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \\\n --set prometheus.prometheusSpec.retention=30d\n\n# Install Grafana using Helm\nhelm install grafana grafana/grafana \\\n --namespace monitoring \\\n --set persistence.enabled=true \\\n --set persistence.size=10Gi \\\n --set adminPassword=admin123\n\n# Expose services\nkubectl patch svc prometheus-kube-prometheus-prometheus -n monitoring -p '{\"spec\":{\"type\":\"NodePort\"}}'\nkubectl patch svc grafana -n monitoring -p '{\"spec\":{\"type\":\"NodePort\"}}'\n\necho \"Prometheus & Grafana installed!\"\necho \"Prometheus: http://$(hostname -I | awk '{print $1}'):$(kubectl get svc prometheus-kube-prometheus-prometheus -n monitoring -o jsonpath='{.spec.ports[0].nodePort}')\"\necho \"Grafana: http://$(hostname -I | awk '{print $1}'):$(kubectl get svc grafana -n monitoring -o jsonpath='{.spec.ports[0].nodePort}')\"\necho \"Grafana admin password: admin123\"\necho \"✅ Monitoring stack installation completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "7d88a242-654b-4dee-8642-84366b4eacb9",
"name": "创建 DevOps 用户",
"type": "n8n-nodes-base.ssh",
"position": [
1760,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"👤 Creating DevOps User & Configuration\"\necho \"======================================\"\n\n# Create DevOps user\nuseradd -m -s /bin/bash {{ $json.devops_user }}\necho \"{{ $json.devops_user }}:{{ $json.user_password }}\" | chpasswd\n\n# Add to groups\nusermod -aG sudo,docker {{ $json.devops_user }}\n\n# Create directories\nsu - {{ $json.devops_user }} -c \"mkdir -p ~/projects/{docker-files,k8s-manifests,jenkins-pipelines,monitoring,scripts}\"\n\n# Copy kubeconfig\ncp /etc/rancher/k3s/k3s.yaml /home/{{ $json.devops_user }}/.kube/config\nchown -R {{ $json.devops_user }}:{{ $json.devops_user }} /home/{{ $json.devops_user }}/.kube\n\n# Generate SSH key\nsu - {{ $json.devops_user }} -c \"ssh-keygen -t rsa -b 4096 -C '{{ $json.devops_user }}@devops-server' -N '' -f ~/.ssh/id_rsa\"\n\n# Configure Git\nsu - {{ $json.devops_user }} -c \"git config --global user.name '{{ $json.devops_user }}'\"\nsu - {{ $json.devops_user }} -c \"git config --global user.email '{{ $json.devops_user }}@devops.local'\"\n\necho \"✅ DevOps user created successfully!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "fcb8d5c7-c333-4bbc-ac49-3fc3e782bd46",
"name": "安全配置",
"type": "n8n-nodes-base.ssh",
"position": [
1980,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"🔒 Security & Firewall Configuration\"\necho \"===================================\"\n\n# Configure UFW firewall\nufw --force enable\nufw allow 22/tcp # SSH\nufw allow 80/tcp # HTTP\nufw allow 443/tcp # HTTPS\nufw allow 8080/tcp # Jenkins\nufw allow 9090/tcp # Prometheus\nufw allow 3000/tcp # Grafana\nufw allow 6443/tcp # Kubernetes API\n\n# Install additional DevOps tools\nsnap install code --classic\nsnap install helm --classic\nsnap install terraform --classic\n\n# Install AWS CLI\ncurl \"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip\" -o \"awscliv2.zip\"\nunzip awscliv2.zip && ./aws/install\n\n# Install Azure CLI\ncurl -sL https://aka.ms/InstallAzureCLIDeb | bash\n\n# Install Google Cloud SDK\necho \"deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main\" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list\ncurl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -\napt update && apt install -y google-cloud-cli\n\necho \"✅ Security configuration completed!\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "b2c7b3cc-d9fd-4931-9c1a-9c2168eef699",
"name": "最终配置",
"type": "n8n-nodes-base.ssh",
"position": [
2200,
0
],
"parameters": {
"command": "#!/bin/bash\n\necho \"🎯 Final DevOps Stack Configuration\"\necho \"===================================\"\n\n# Create sample DevOps project structure\ncat > /home/{{ $json.devops_user }}/projects/docker-compose.yml << 'EOF'\nversion: '3.8'\nservices:\n app:\n build: .\n ports:\n - \"3000:3000\"\n environment:\n - NODE_ENV=production\n \n redis:\n image: redis:alpine\n ports:\n - \"6379:6379\"\n \n postgres:\n image: postgres:13\n environment:\n - POSTGRES_DB=myapp\n - POSTGRES_USER=user\n - POSTGRES_PASSWORD=password\n volumes:\n - postgres_data:/var/lib/postgresql/data\n \nvolumes:\n postgres_data:\nEOF\n\n# Create sample Kubernetes deployment\ncat > /home/{{ $json.devops_user }}/projects/k8s-manifests/deployment.yaml << 'EOF'\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: sample-app\n namespace: default\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: sample-app\n template:\n metadata:\n labels:\n app: sample-app\n spec:\n containers:\n - name: app\n image: nginx:alpine\n ports:\n - containerPort: 80\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: sample-app-service\nspec:\n selector:\n app: sample-app\n ports:\n - protocol: TCP\n port: 80\n targetPort: 80\n type: LoadBalancer\nEOF\n\n# Create sample Jenkins pipeline\ncat > /home/{{ $json.devops_user }}/projects/jenkins-pipelines/Jenkinsfile << 'EOF'\npipeline {\n agent any\n \n stages {\n stage('Build') {\n steps {\n echo 'Building application...'\n sh 'docker build -t myapp:${BUILD_NUMBER} .'\n }\n }\n \n stage('Test') {\n steps {\n echo 'Running tests...'\n sh 'docker run --rm myapp:${BUILD_NUMBER} npm test'\n }\n }\n \n stage('Deploy') {\n steps {\n echo 'Deploying to Kubernetes...'\n sh 'kubectl apply -f k8s-manifests/'\n }\n }\n }\n}\nEOF\n\n# Set proper ownership\nchown -R {{ $json.devops_user }}:{{ $json.devops_user }} /home/{{ $json.devops_user }}/projects/\n\n# Display summary\necho \"🎉 DevOps Stack Setup Complete!\"\necho \"==============================\"\necho \"📊 Installation Summary:\"\necho \"• Docker: $(docker --version)\"\necho \"• Kubernetes: $(kubectl version --client --short)\"\necho \"• Helm: $(helm version --short)\"\necho \"• Jenkins: http://$(hostname -I | awk '{print $1}'):8080\"\necho \"• Prometheus: http://$(hostname -I | awk '{print $1}'):9090\"\necho \"• Grafana: http://$(hostname -I | awk '{print $1}'):3000\"\necho \"• DevOps User: {{ $json.devops_user }}\"\necho \"• Password: {{ $json.user_password }}\"\necho \"• Project Directory: /home/{{ $json.devops_user }}/projects/\"\necho \"\"\necho \"🚀 Your DevOps environment is ready for CI/CD!\"\necho \"Happy DevOps! 🎯\"",
"authentication": "privateKey"
},
"credentials": {
"sshPrivateKey": {
"id": "ilPh8oO4GfSlc0Qy",
"name": "SSH Password account - test "
}
},
"typeVersion": 1
},
{
"id": "3f1ef253-89df-4073-9295-0698b0f347cd",
"name": "设置完成",
"type": "n8n-nodes-base.set",
"position": [
2420,
0
],
"parameters": {
"values": {
"string": [
{
"name": "setup_status",
"value": "✅ DevOps Stack Setup Complete!"
},
{
"name": "server_info",
"value": "Host: {{ $('Configure Parameters').item.json.server_host }}"
},
{
"name": "devops_user",
"value": "Username: {{ $('Configure Parameters').item.json.devops_user }}"
},
{
"name": "user_password",
"value": "Password: {{ $('Configure Parameters').item.json.user_password }}"
},
{
"name": "tools_installed",
"value": "Docker, Kubernetes, Jenkins, Prometheus, Grafana, Helm, Terraform"
},
{
"name": "jenkins_url",
"value": "http://{{ $('Configure Parameters').item.json.server_host }}:8080"
},
{
"name": "grafana_url",
"value": "http://{{ $('Configure Parameters').item.json.server_host }}:3000"
},
{
"name": "prometheus_url",
"value": "http://{{ $('Configure Parameters').item.json.server_host }}:9090"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "e8c31a96-3853-4ee6-9870-b73d0ba528e1",
"name": "等待",
"type": "n8n-nodes-base.wait",
"position": [
440,
0
],
"webhookId": "4c6684a7-dc07-4a55-bb17-832802b06d9a",
"parameters": {},
"typeVersion": 1.1
},
{
"id": "9e38d276-b2e5-4a4b-8038-209a5dcbccf3",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
780,
-500
],
"parameters": {
"color": 4,
"width": 620,
"height": 280,
"content": "## 主要组件"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "f83e2551-7393-4aec-aba1-d43449ed9961",
"connections": {
"Wait": {
"main": [
[
{
"node": "System Preparation",
"type": "main",
"index": 0
}
]
]
},
"Install Docker": {
"main": [
[
{
"node": "Install Kubernetes",
"type": "main",
"index": 0
}
]
]
},
"Install Jenkins": {
"main": [
[
{
"node": "Install Monitoring",
"type": "main",
"index": 0
}
]
]
},
"Create DevOps User": {
"main": [
[
{
"node": "Security Configuration",
"type": "main",
"index": 0
}
]
]
},
"Install Kubernetes": {
"main": [
[
{
"node": "Install Jenkins",
"type": "main",
"index": 0
}
]
]
},
"Install Monitoring": {
"main": [
[
{
"node": "Create DevOps User",
"type": "main",
"index": 0
}
]
]
},
"Start DevOps Setup": {
"main": [
[
{
"node": "Configure Parameters",
"type": "main",
"index": 0
}
]
]
},
"System Preparation": {
"main": [
[
{
"node": "Install Docker",
"type": "main",
"index": 0
}
]
]
},
"Final Configuration": {
"main": [
[
{
"node": "Setup Complete",
"type": "main",
"index": 0
}
]
]
},
"Configure Parameters": {
"main": [
[
{
"node": "Wait",
"type": "main",
"index": 0
}
]
]
},
"Security Configuration": {
"main": [
[
{
"node": "Final Configuration",
"type": "main",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 开发运维
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Oneclick AI Squad
@oneclick-aiThe AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.
分享此工作流