Selaa lähdekoodia

:wrench: add minio nginx & redis setting scripts

Jeremy Zheng 3 vuotta sitten
vanhempi
sitoutus
0857297528

+ 5 - 0
scripts/ops/minio/README.md

@@ -0,0 +1,5 @@
+# USAGE
+
+```bash
+sudo ./setup.sh change-me.com
+```

+ 98 - 0
scripts/ops/minio/setup.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+
+set -e
+
+if [ "$#" -ne 1 ]
+then
+    echo "USAGE: $0 DOMAIN"
+    exit 1
+fi
+
+echo "check /var/lib/minio"
+if [ ! -d /var/lib/minio ]
+then
+    mkdir /var/lib/minio
+    chown www-data:www-data /var/lib/minio
+    chmod 700 /var/lib/minio
+fi
+
+echo "check /lib/systemd/system/minio.service"
+if [ ! -f /lib/systemd/system/minio.service ]
+then
+    cat > /lib/systemd/system/minio.service <<EOF
+[Unit]
+Description=MinIO offers high-performance, S3 compatible object storage.
+After=network.target
+
+[Service]
+Type=simple
+User=www-data
+Group=www-data
+WorkingDirectory=/var/lib/minio
+ExecStart=/usr/bin/minio server data
+Restart=always
+RestartSec=10s
+
+Environment="MINIO_ADDRESS=127.0.0.1:9000"
+Environment="MINIO_CONSOLE_ADDRESS=127.0.0.1:9001"
+Environment="MINIO_ROOT_USER=www"
+Environment="MINIO_ROOT_PASSWORD=$(pwgen 32 1)"
+
+[Install]
+WantedBy=multi-user.target
+EOF
+    chmod 444 /lib/systemd/system/minio.service
+    systemctl daemon-reload
+    systemctl enable minio
+fi
+
+
+echo "check /etc/nginx/sites-enabled/s3.$1.conf"
+if [ ! -f /etc/nginx/sites-enabled/s3.$1.conf ]
+then
+
+    cat > /etc/nginx/sites-enabled/s3.$1.conf <<EOF
+server {
+  server_name assets.$1;
+  access_log /var/log/nginx/assets.$1.access.log;
+  error_log  /var/log/nginx/assets.$1.error.log;
+
+  location / {
+    proxy_set_header X-Forwarded-Proto http;
+    proxy_set_header X-Real-IP \$remote_addr;
+    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;    
+    proxy_set_header Host \$http_host;
+    proxy_redirect off;
+    proxy_pass http://127.0.0.1:9000;
+    proxy_set_header Upgrade \$http_upgrade;
+    proxy_set_header Connection "upgrade";
+  }
+}
+
+server {
+
+  server_name s3.$1;
+  access_log /var/log/nginx/s3.$1.access.log;
+  error_log  /var/log/nginx/s3.$1.error.log;
+
+  location / {
+    proxy_set_header X-Forwarded-Proto http;
+    proxy_set_header X-Real-IP \$remote_addr;
+    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;    
+    proxy_set_header Host \$http_host;
+    proxy_redirect off;
+    proxy_pass http://127.0.0.1:9001;
+    proxy_set_header Upgrade \$http_upgrade;
+    proxy_set_header Connection "upgrade";
+  }
+}
+
+EOF
+    chmod 644 /etc/nginx/sites-enabled/s3.$1.conf
+fi
+
+echo "done($1)."
+exit 0
+
+
+

+ 5 - 0
scripts/ops/nginx/README.md

@@ -0,0 +1,5 @@
+# USAGE
+
+```bash
+sudo ./react.sh change-me.com 8080
+```

+ 58 - 0
scripts/ops/nginx/react.sh

@@ -0,0 +1,58 @@
+#!/bin/bash
+
+set -e
+
+
+if [ "$#" -ne 2 ]
+then
+    echo "USAGE: $0 DOMAIN PORT"
+    exit 1
+fi
+
+echo "check /etc/nginx/sites-enabled/$1.conf"
+if [ ! -f /etc/nginx/sites-enabled/$1.conf ]
+then
+    cat > aaa.confg <<EOF
+server {
+
+  server_name $1;
+  access_log /var/log/nginx/$1.access.log;
+  error_log  /var/log/nginx/$1.error.log;
+
+  gzip on;
+  gzip_comp_level 9;
+  gzip_min_length 1k;
+  gzip_types text/plain text/css application/xml application/javascript;
+  gzip_vary on;
+  client_max_body_size 128M;
+  
+
+  location /my/ {
+    alias /var/www/$1/current/dashboard/;
+    try_files \$uri \$uri/ /my/index.html;
+    
+    location ~* \\.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)\$ {
+      access_log off;
+      expires max;
+    }
+  }
+  
+  location / {
+    proxy_set_header X-Forwarded-Proto http;
+    proxy_set_header X-Real-IP \$remote_addr;
+    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;    
+    proxy_set_header Host \$http_host;
+    proxy_redirect off;
+    proxy_pass http://127.0.0.1:$2;
+    proxy_set_header Upgrade \$http_upgrade;
+    proxy_set_header Connection "upgrade";
+  }
+
+}
+EOF
+
+    chmod 644 /etc/nginx/sites-enabled/$1.conf
+fi
+
+echo "done($1)."
+exit 0

+ 16 - 0
scripts/ops/redis/README.md

@@ -0,0 +1,16 @@
+# Redis
+
+## Cluster init
+
+- create node 1
+
+```bash
+sudo ./setup.sh 1
+sudo systemctl start redis-node-1
+```
+
+- create cluster
+
+```bash
+sudo redis-cli --cluster create 127.0.0.1:6371 127.0.0.1:6372 127.0.0.1:6373 127.0.0.1:6374 127.0.0.1:6375 127.0.0.1:6376
+```

+ 74 - 0
scripts/ops/redis/setup.sh

@@ -0,0 +1,74 @@
+#!/bin/bash
+
+set -e
+
+
+if [ "$#" -ne 1 ]
+then
+    echo "USAGE: $0 NODE_ID"
+    exit 1
+fi
+
+echo "check /etc/redis/node-$1.conf"
+if [ ! -d /etc/redis ]
+then
+    mkdir -p /etc/redis
+fi
+
+if [ ! -f /etc/redis/node-$1.conf ]
+then
+    cat > /etc/redis/node-$1.conf <<EOF
+bind 0.0.0.0
+port 637${1}
+daemonize no
+dir /var/lib/redis-node-$1
+
+cluster-enabled yes
+cluster-config-file /tmp/redis-node-$1.conf
+cluster-node-timeout 5000
+
+appendonly yes
+appendfsync everysec
+EOF
+    chown redis:redis /etc/redis/node-$1.conf
+    chmod 400 /etc/redis/node-$1.conf
+fi
+
+echo "create /var/lib/redis-node-$1"
+if [ ! -d /var/lib/redis-node-$1 ]
+then
+    mkdir -p /var/lib/redis-node-$1
+    chown redis:redis /var/lib/redis-node-$1
+    chmod 700 /var/lib/redis-node-$1
+fi
+
+echo "create /lib/systemd/system/redis-node-$1.service"
+if [ ! -f /lib/systemd/system/redis-node-$1.service ]
+then
+
+    cat > /lib/systemd/system/redis-node-$1.service <<EOF
+[Unit]
+Description=Redis cluster node-$1
+After=network.target
+
+[Service]
+Type=simple
+User=redis
+Group=redis
+WorkingDirectory=/var/lib/redis-node-$1
+ExecStart=/usr/bin/redis-server /etc/redis/node-$1.conf
+# or always, on-abort, on-failure, etc
+Restart=always 
+RestartSec=10s
+
+[Install]
+WantedBy=multi-user.target
+EOF
+    chmod 444 /lib/systemd/system/redis-node-$1.service
+    systemctl daemon-reload
+    systemctl enable redis-node-$1
+fi
+
+echo "done."
+
+exit 0