目录

SSH Key

ssh-keygen -t ed25519 -C "your_email@example.com"

安装Nginx

sudo apt install nginx

nginx 配置模板

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl_certificate /usr/local/nginx/ssl/cert.pem;
  ssl_certificate_key /usr/local/nginx/ssl/key.pem;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name blog.68hub.com;
  access_log off;
  index index.html index.htm index.php;
  root /data/go/manfei_front;
  if ($host != 68hub.com) {  return 301 $scheme://68hub.com$request_uri;  }
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

  location / {
    proxy_pass http://127.0.0.1:7180;
    proxy_redirect             off;
    proxy_set_header           Host             $host;
    proxy_set_header           X-Real-IP        $remote_addr;
    proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
  }
    location /api {
    proxy_pass http://127.0.0.1:7888;
    proxy_redirect             off;
    proxy_set_header           Host             $host;
    proxy_set_header           X-Real-IP        $remote_addr;
    proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
  }

    location /pc {
    proxy_pass http://127.0.0.1:7888;
    proxy_redirect             off;
    proxy_set_header           Host             $host;
    proxy_set_header           X-Real-IP        $remote_addr;
    proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
  }
     location /web {
    proxy_pass http://127.0.0.1:7888;
    proxy_redirect             off;
    proxy_set_header           Host             $host;
    proxy_set_header           X-Real-IP        $remote_addr;
    proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
  }
  location ~ .*\.(gif|jpg|jpeg|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    proxy_pass http://127.0.0.1:7180;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    proxy_pass http://127.0.0.1:7180;
    access_log off;
  }
  location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    deny all;
  }
}

安装Golang

  • 下载Golang
wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
  • 安装Golang
sudo rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz
  • 配置Go环境
sudo vim /etc/profile
##将以下添加至/etc/profile
export GOPROXY=https://mirrors.aliyun.com/goproxy/
export PATH=$PATH:/usr/local/go/bin
export GOPRIVATE="*.68hub.com" #go 私有库
export GOINSECURE="*.68hub.com"
vim ~/.gitconfig
[url "web@gitea.68hub.com:"]
        insteadOf = https://gitea.68hub.com/

安装Redis

  • 安装
sudo apt install redis-server
  • 配置

修改redis.conf文件,更新systemd

sudo vim /etc/redis/redis.conf
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

sudo systemctl restart redis.service

安装PostgreSql

  • 下载
wget https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.bz2
tar xjvf postgresql-15.1.tar.bz2
  • 添加postgres用户
sudo adduser postgres
  • 添加postgres数据文件夹
mkdir  /data/pgData
chown -R postgres:postgres /data/pgData
  • 编译安装
apt-get install libreadline-dev
cd postgresql-15.1
./configure --prefix=/usr/local/pg15
make && make install
  • 配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin:/usr/local/pg15/bin
export LD_LIBRARY_PATH=/usr/local/pg15/lib/:$LD_LIBRARY_PATH
su - postgres
vim ~/.bashrc
export PGDATA=/data/pgData
export PGPORT=5432
  • 添加启动文件 touch postgres.service
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target

[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=5432
Environment=PGDATA=/data/pgData
OOMScoreAdjust=-1000
ExecStart=/usr/local/pg15/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 -l /home/postgres/pg.log
ExecStop=/usr/local/pg15/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pg15/bin/pg_ctl reload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

#添加至systemctl
cp postgres.service /lib/systemd/system/.
systemctl enable postgres.service
systemctl daemon-reload

安装Node LTS

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

sudo npm install -g pnpm

配置防火墙端口

sudo ufw app list
sudo ufw allow "OpenSSH"
sudo ufw allow "Nginx Full"
sudo ufw enable

安装acme.sh

# curl https://get.acme.sh | sh -s email=my@example.com
wget -O -  https://get.acme.sh | sh -s email=my@example.com
echo alias acme.sh=~/.acme.sh/acme.sh >> ~/.bashrc

自动脚本

todo