Whakatōnga me te Whakatakoto
Ka whāki tēnei aratohu i ngā kōwhiringa whakatakoto mō ngā tauira whakatū-rānei Onetime Secret.
Ngā Kōwhiringa Whakatakoto
Section titled “Ngā Kōwhiringa Whakatakoto”Whakatakoto Docker
Section titled “Whakatakoto Docker”Ka whakarato a Docker i te tikanga whakatakoto pūmau, kaweake.
Mā te Whakamahi i Docker Compose
Section titled “Mā te Whakamahi i Docker Compose”Mō te whakahaere hanganga katoa, whakamahia te pūtahitanga Docker Compose tūmau:
Pūtahitanga: https://github.com/onetimesecret/docker-compose/
Whakatū tere:
git clone https://github.com/onetimesecret/docker-compose.gitcd docker-composedocker-compose up -dWhakatū Docker Compose ā-ringaringa:
version: '3.8'
services: onetime: image: onetimesecret/onetimesecret:latest ports: - "3000:3000" environment: - REDIS_URL=redis://redis:6379/0 - SECRET=${SECRET} - HOST=${HOST:-localhost:3000} - SSL=${SSL:-false} - RACK_ENV=production depends_on: - redis volumes: - ./etc:/app/etc - ./logs:/app/logs
redis: image: redis:bookworm volumes: - redis_data:/data command: redis-server --requirepass ${REDIS_PASSWORD}
volumes: redis_data:Kōnae taiao (.env):
SECRET=your-secure-32-character-hex-keyREDIS_PASSWORD=your-redis-passwordHOST=your-domain.comSSL=trueWhakatōnga ā-Ringaringa
Section titled “Whakatōnga ā-Ringaringa”Mō ngā taiao e hiahia ana i ngā whirihoranga ritenga, i ngā hanganga kei te mau.
Te Whakatō i ngā Taunga
Section titled “Te Whakatō i ngā Taunga”Ubuntu 22.04 LTS:
# Whakahōutia te pūnahasudo apt update && sudo apt upgrade -y
# Whakatōhia a Ruby me ngā taputapu hangasudo apt install -y ruby ruby-dev build-essential gitsudo gem install bundler
# Whakatōhia a Redissudo apt install -y redis-serversudo systemctl enable redis-serversudo systemctl start redis-server
# Whakatōhia a Node.js (mō te whanaketanga me te hanga rawa tukuatu)curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -sudo apt install -y nodejssudo npm install -g pnpm@latestCentOS/RHEL 8:
# Whakahohetia te pūtahitanga PowerTools/CodeReadysudo dnf install -y dnf-plugins-coresudo dnf config-manager --set-enabled powertools
# Whakatōhia a Ruby me ngā taputapu whanaketangasudo dnf groupinstall -y "Development Tools"sudo dnf install -y ruby ruby-devel gitsudo gem install bundler
# Whakatōhia a Redissudo dnf install -y redissudo systemctl enable redissudo systemctl start redisWhakatū Papatono
Section titled “Whakatū Papatono”# Waihangahia te kaiwhakamahi papatonosudo useradd -r -m -s /bin/bash onetime
# Huri ki te kaiwhakamahi papatonosudo su - onetime
# Tārua pūtahitangagit clone https://github.com/onetimesecret/onetimesecret.gitcd onetimesecret
# Whakatōhia ngā taungabundle install --deployment --without development test
# Tārua me te whirihora taiaocp .env.example .envcp ./etc/config.example.yaml ./etc/config.yaml
# Waihangahia te hash tāmua mō te aroturuki putangagit rev-parse --short HEAD > .commit_hash.txtWhirihoranga Tūmau Whakahoki
Section titled “Whirihoranga Tūmau Whakahoki”Ka taea e ēnei tauira whirihoranga te āwhina i a koe ki te tīmata, engari me whakarereke koe i aua mea kia hāngai ki ō hiahiatanga motuhake.
Whirihoranga Taketake:
server { listen 80; server_name your-domain.com; return 301 https://$server_name$request_uri;}
server { listen 443 ssl http2; server_name your-domain.com;
# Whirihoranga SSL ssl_certificate /path/to/your/cert.pem; ssl_certificate_key /path/to/your/key.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512;
# Ngā pane haumaru add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Frame-Options DENY always; add_header X-Content-Type-Options nosniff always;
# Ngā kōnae static mai i te tukuatu kua hangaia location /dist/ { root /app/public; expires 1y; add_header Cache-Control "public, immutable"; try_files $uri $uri/ =404; }
# Ngā tono API ki te kūwaha location /api/ { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
# Ngā tono katoa ki te kūwaha location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;
# Tautoko WebSocket proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }}Whakahohetia te pae:
sudo ln -s /etc/nginx/sites-available/onetime /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginxKa whakarato a Caddy i te HTTPS aunoa me te whirihoranga ngāwari ake:
your-domain.com { # Whakahaere i ngā kōnae static mai i te tukuatu kua hangaia handle /dist/* { root * /app/public file_server }
# Ngā tono API ki te kūwaha handle /api/* { reverse_proxy 127.0.0.1:3000 }
# Ngā tono katoa ki te kūwaha (mō ngā whārangi kua hangaia e te tūmau) handle { reverse_proxy 127.0.0.1:3000 }}Apache
Section titled “Apache”<VirtualHost *:80> ServerName your-domain.com Redirect permanent / https://your-domain.com/</VirtualHost>
<VirtualHost *:443> ServerName your-domain.com
# Whirihoranga SSL SSLEngine on SSLCertificateFile /path/to/your/cert.pem SSLCertificateKeyFile /path/to/your/key.pem
# Ngā pane haumaru Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff
# Ngā kōnae static mai i te tukuatu kua hangaia Alias /dist /app/public/dist <Directory /app/public/dist> Require all granted ExpiresActive On ExpiresDefault "access plus 1 year" </Directory>
# Ngā tono API me te papatono ki te kūwaha ProxyPreserveHost On ProxyPass /dist ! ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/</VirtualHost>Whirihoranga SSL/TLS
Section titled “Whirihoranga SSL/TLS”Let’s Encrypt (Certbot)
Section titled “Let’s Encrypt (Certbot)”Whakatōhia a Certbot:
# Ubuntu/Debiansudo apt install certbot python3-certbot-nginx
# CentOS/RHELsudo dnf install certbot python3-certbot-nginxWhakaputahia te Tiwhikete:
# Mō Nginxsudo certbot --nginx -d your-domain.com
# Mō Apachesudo certbot --apache -d your-domain.com
# Tiwhikete ā-ringaringa (mēnā e whakamahi ana i te whirihoranga tūmau ritenga)sudo certbot certonly --webroot -w /var/www/html -d your-domain.comWhakahōutanga-aunoa:
# Tāpirihia ki te crontabecho "0 12 * * * /usr/bin/certbot renew --quiet" | sudo tee -a /etc/crontabNgā Tiwhikete SSL Ritenga
Section titled “Ngā Tiwhikete SSL Ritenga”Whakawhiwhia ō tiwhikete me te whakahōu i ngā ara i roto i te whirihoranga tūmau:
# Ngā kōnae tiwhikete/etc/ssl/certs/your-domain.com.crt/etc/ssl/private/your-domain.com.key
# Whakatakotohia ngā whakaaetanga tikasudo chmod 600 /etc/ssl/private/your-domain.com.keysudo chmod 644 /etc/ssl/certs/your-domain.com.crtWhirihoranga Redis
Section titled “Whirihoranga Redis”Kōwhiringa 1: Mahara-anake (kaua e tiaki ki te kōpae mō te haumaru nui):
# Whakapai maharamaxmemory 1gbmaxmemory-policy allkeys-lru
# Haumaru - kāore ngā karere muna e tuhia ki te kōpaesave "" # Whakamutua ngā tiaki-aunoa katoaappendonly no # Whakamutua te rārangi AOF
# Haumarurequirepass your_redis_passwordbind 127.0.0.1
# Whakatutukitangatcp-keepalive 60timeout 300Kōwhiringa 2: Pumau kōpae (ka taea ngā tārua engari ka tuhia ngā karere muna ki te kōpae):
# Whakapai maharamaxmemory 1gbmaxmemory-policy allkeys-lru
# Ngā hopunga RDB - ka waihanga i ngā kōnae dump.rdbsave 900 1 # Tiaki mēnā kua huri te mīhini 1 i roto i ngā hēkona 900save 300 10 # Tiaki mēnā kua huri te mīhini 10 i roto i ngā hēkona 300save 60 10000 # Tiaki mēnā kua huri te mīhini 10000 i roto i ngā hēkona 60
# Rārangi AOF - ka waihanga i ngā kōnae appendonly.aof mō te whakahoki wā-tikaappendonly yesappendfsync everysec # Tukutahi ki te kōpae ia hēkona
# Haumarurequirepass your_redis_passwordbind 127.0.0.1
# Whakatutukitangatcp-keepalive 60timeout 300Nui te Tikanga: Mēnā kua whakahohetia te pumau kōpae, ka tuhia ngā karere muna ki:
- Ngā kōnae
dump.rdb(ngā hopunga i ngā wā) - Ngā kōnae
appendonly.aof(te rārangi tāpiri haere)
Kōwhiria i runga i ō hiahiatanga haumaru me te tārua.
Tīmata anō a Redis:
sudo systemctl restart redisNgā Tārua Redis
Section titled “Ngā Tārua Redis”Redis:
#!/bin/bash# Tuhinga tārua RedisBACKUP_DIR="/var/backups/onetime"DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Waihangahia te tāruaredis-cli -a "$REDIS_PASSWORD" --rdb $BACKUP_DIR/redis_$DATE.rdb
# Whakawātea i ngā tārua tawhitofind $BACKUP_DIR -name "redis_*.rdb" -mtime +7 -deleteNgā Mahi e Whai Ake Nei
Section titled “Ngā Mahi e Whai Ake Nei”I muri i te whakatakoto angitu:
- Whirihorahia tō tauira me ngā tautuhinga ritenga
- Whakatūhia te aroturuki me te whakamōhio mō ngā mahinga whakaputa
- Arotake i ngā tautuhinga haumaru me te whakahohe i ngā tiaki tāpiri
- Whirihorahia te tārua-aunoa me te whakamātau i ngā tikanga whakahoki
- Whakatūhia ngā rohe ritenga mō tō whakahaere
Kua rite tō tauira Onetime Secret mō te whakamahi whakaputa!