make_swap.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

# 判断是否为root用户
if [ `id -u` -ne 0 ]; then
echo "请使用sudo或作为root用户运行此脚本以执行必要的操作。"
#在这里1是状态码,表示脚本执行出现了某种问题或错误。通常,成功的执行返回状态码为0,而非零的状态码通常表示错误或异常情况。
exit 1
fi

# 提示用户输入交换文件大小
read -p "请输入交换文件大小(例如16G): " swap_size

# 验证输入是否符合格式,以G结尾表示
if [[ ! $swap_size =~ ^[0-9]+[Gg]$ ]]; then
echo "无效的输入格式,请使用格式如'16G'表示大小。"
exit 1
fi

# 提示用户确认操作
read -p "将创建大小为 $swap_size 的交换文件,是否继续?(y/n): " confirm

if [[ ! $confirm =~ ^[Yy]$ ]]; then
echo "操作已取消."
exit 1
fi

# 计算交换文件大小(这里把上面获取到大小系数和1024相乘,例如,如果swap_size的值是"16G",那么${swap_size%G}将会得到"16",去掉了末尾的 "G"。)
swap_size=$(( ${swap_size%G} * 1024 ))

# 创建交换文件
dd if=/dev/zero of=/swapfile bs=1M count=${swap_size} status=progress

# 设置正确的权限
chmod 600 /swapfile

# 格式化交换文件
mkswap /swapfile

# 启用交换文件
swapon /swapfile

# 将/swapfile追加到/etc/fstab文件内
echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab

echo "交换文件创建成功并已启用,而且追加到/etc/fstab内。"

gitlab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cat > /root/docker-compose/gitlab/docker-compose.yml << EOF
version: '3'
services:
gitlab:
image: yrzr/gitlab-ce-arm64v8:latest
container_name: gitlab
restart: always
privileged: true
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url = "http://gitlab.fastjrun.com"
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_ssh_host'] = 'gitlab.fastjrun.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22
ports:
- '8080:80'
- '443:443'
- '222:22'
volumes:
- './gitlab/config:/etc/gitlab'
- './gitlab/logs:/var/log/gitlab'
- './gitlab/data:/var/opt/gitlab'
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"
EOF

mariadb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat > /root/docker-compose/mariadb/docker-compose.yml << EOF
version: '3.1'
services:
db:
image: mariadb
restart: always
environment:
MARIADB_ROOT_PASSWORD:#自己喜欢
ports:
- 3306:3306
volumes:
- './mysql.conf.d/mysql.cnf:/etc/mysql/mysql.conf.d/mysql.cnf'
- './data:/var/lib/mysql'
adminer:
image: adminer
restart: always
ports:
- 8888:8080
EOF

pixapop

这个没办法分文件夹看图,可惜了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cat > /root/docker-compose/pixapop/docker-compose.yml << EOF
version: "2.1"
services:
pixapop:
image: lscr.io/linuxserver/pixapop:latest
container_name: pixapop
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
- APP_USERNAME=#自己喜欢
- APP_PASSWORD=#自己喜欢
volumes:
- /root/docker-compose/pixapop/config:/config
- /root/docker-compose/pixapop/photos:/photos
ports:
- 5555:80
EOF

nextcloud

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cat > /root/docker-compose/nextcloud/docker-compose.yml << EOF
version: '2'

volumes:
nextcloud:
db:

services:
db:
image: mariadb:10.6
restart: always
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=#自己喜欢
- MYSQL_PASSWORD=#自己喜欢
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud

app:
image: nextcloud
restart: always
ports:
- 9999:80
links:
- db
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=#自己喜欢
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
EOF

[toc]

默认在root用户下执行命令

docker部署nginx

自己去安装docker,我相信你会的

创建目录

1
mkdir /hexo_nginx

拉取nginx镜像

1
docker pull amd64/nginx

运行nginx

1
docker run --name hexo_nginx --network=host -v /hexo_nginx/www/html:/usr/share/nginx/html -d nginx

设置权限

1
chmod -R 777 /hexo_nginx

git

自己安装git,我还是相信你会的

1
useradd -m -s /bin/bash git
  • -m 参数表示创建用户的同时创建用户的家目录
  • -s /bin/bash 参数表示将用户的默认 shell 设置为 Bash

更改密码

1
passwd git

切换git用户

1
su - git

创建Git文件夹

1
[git@archlinux ~]$ mkdir Git

进入Git文件夹

1
2
[git@archlinux ~]$ cd Git/
[git@archlinux Git]$

创建一个裸仓库

1
2
3
4
5
6
7
8
9
10
11
[git@archlinux Git]$ git init --bare hexo_nginx.git
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>

创建钩子脚本

1
2
3
4
cat >hexo_nginx.git/hooks/post-receive<<EOF
#!/bin/bash
git --work-tree=/hexo_nginx/www/html --git-dir=/home/git/Git/hexo_nginx.git checkout -f
EOF

赋予执行权限

1
chmod +x hexo_nginx.git/hooks/post-receive

hexo本地博客配置

编辑_config.yml配置文件

1
2
3
4
5
6
7
8
deploy:
- type: git
repo: git@github.com:julintongxue/julintongxue.github.io.git
branch: master
# 加下面这个
- type: git
repo: git@your_server_ip:/home/git/Git/hexo_nginx.git
branch: master

推送

1
2
3
hexo g
hexo d
# 要输入密码

免密推送

把本地的ssh公钥粘给服务器端的git用户

创建.ssh文件夹

1
[git@archlinux ~]$ mkdir .ssh && cd .ssh

创建authorized_keys文本

1
[git@archlinux .ssh]$ touch authorized_keys

把公钥粘贴进去得了

部署ssl实现https访问

首先,得先申请证书!然后下载到certs文件夹里面,欸!太简单了,我不想写

然后修改default.conf配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
server {
listen 80;
listen [::]:80;
#写你的域名
server_name www.xxx.com;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}

server {
listen 443 ssl;
#写你的域名
server_name www.xxx.com;
# 绝对路径指定证书的位置和证书名字
ssl_certificate /etc/ssl/certs/1.pem;
ssl_certificate_key /etc/ssl/1.key;

ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

然后docker数据卷映射就行了

把上一个docker容器删了,部署新的

1
docker rm -f hexo_nginx

我是在hexo_nginx创建了certs证书文件夹和default.conf文本文件

1
docker run --name hexo_nginx --network=host --restart always -v /hexo_nginx/www/html:/usr/share/nginx/html -v /hexo_nginx/certs:/etc/ssl/certs -v /hexo_nginx/default.conf:/etc/nginx/conf.d/default.conf:ro -d nginx

image-20240105003320649

访问就可以看到可爱的小锁了

image-20240105003423943