gitlab備份與還原(使用docker)

我家裡的 gitlab 之前是用 docker-gitlab 架設的,前一陣子因為誤刪了某些檔案,導致有問題。現在就改用 gitlab 官方的 docker image 來架設,目前一切安好,為了之後的長長久久,必須看一下怎麼備份跟回存。

主要參考資料:

備份方法

docker-compose exec -it gitlab-ce gitlab-backup create

還原方法

還原時,需要先把容器裡的某些服務停掉,所以步驟比較多。

docker-compose exec -it gitlab-ce gitlab-ctl stop puma
docker-compose exec -it gitlab-ce gitlab-ctl stop sidekiq
docker-compose exec -it gitlab-ce gitlab-ctl status
docker-compose exec -it gitlab-ce gitlab-backup restore BACKUP=<backup_name>
docker-compose exec -it gitlab-ce gitlab-ctl restart
docker-compose exec -it gitlab-rake gitlab:check SANITIZE=true

結語

備份、還原蠻簡單的,很容易放到 crontab 裡去執行,之後再把備份出來的複製到遠端就可以了。

PowerShell網路

最近幫朋友寫腳本,需要變更網路,這首選當然是用 PowerShell ,再來是 netsh 指令。

所以就查了這部份,以下這些腳本都需要管理者權限。

從固定IP改為DHCP

Set-NetIPInterface -InterfaceAlias 'Ethernet 2' -Dhcp Enabled
Get-NetIPAddress -InterfaceAlias 'Ethernet 2' | Remove-NetRoute

從 DHCP 改為固定IP

Get-NetIpAddress -InterfaceAlias 'Ethernet 2' | New-NetIpAddress  IpAddress 192.168.1.10 -PrefixLength 24 -DefaultGateway 192.168.1.1

變更固定IP

Get-NetIPAddress -InterfaceAlias 'Ethernet 2' | Remove-NetRoute
Get-NetIPAddress -InterfaceAlias 'Ethernet 2' | Remove-NetIpAddress
Get-NetIpAddress -InterfaceAlias 'Ethernet 2' | New-NetIpAddress ‑IpAddress 192.168.1.11 -PrefixLength 24 -DefaultGateway 192.168.1.1

重設DNS

Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses
Set-DnsClientServerAddress -InterfaceAlias "Wi-fi" -ResetServerAddresses

設定DNS

Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8","8.8.4.4")
Set-DnsClientServerAddress -InterfaceAlias "Wi-fi" -ServerAddresses ("8.8.8.8","8.8.4.4")

參考資料

避免 ephemeral storage 空間用完

來源:Avoid running out of ephemeral storage space on your Kubernetes worker Nodes

Kubernetes 裡用 emptyDir 的 volume 的話,就是用 ephemeral storage,這塊空間就是 node 上的磁碟空間。所以用完的話,表示 node 上也沒空間了,其他 pod 在使用上可能就會有狀況。

node 上的位置可能會因發行版而有差異,文章裡提供的位置是:/var/lib/kubelet/pods//volumes/kubernetes.io~empty-dir//…

避免的方法有兩種。

第1種是在掛載 volume 時,設定 sizeLimit ,例如

volumes:
- name: www-content
  emptyDir:
    sizeLimit: 2Mi

缺點是當超過這限制時,kubernetes 會把這個 pod evict 掉。

第二種是設定 ResourceQuotas/LimitRange,先新增以下 YAML,然後 apply

apiVersion: v1
kind: ResourceQuota
metadata:
  name: default-resource-quotas
  namespace: my-application-namespace
spec:
  hard:
    limits.cpu: "2"
    limits.memory: 8Gi
    limits.ephemeral-storage: 2Gi
    requests.cpu: "1"
    requests.memory: 4Gi
    requests.ephemeral-storage: 1Gi
---
apiVersion: v1
kind: LimitRange
metadata:
  name: default-limit-ranges
  namespace: my-application-namespace
spec:
  limits:
  - default:
      cpu: 100m
      memory: 128Mi
      ephemeral-storage: "2Mi"
    defaultRequest:
      cpu: 25m
      memory: 64Mi
      ephemeral-storage: "1Mi" 
   type: Container

再來在 deployment/statefulset 裡增加 resource 指定,例如

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment-3
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: helloworld-deployment-3
  replicas: 2
  template:
    metadata:
      labels:
        app.kubernetes.io/name: helloworld-deployment-3
    spec:
      volumes:
      - name: www-content
        emptyDir: {}
      containers:
        - name: hello-world
          image: helloworld:1.0
          volumeMounts:
          - mountPath: /www
            name: www-content
          resources:
            requests:
              ephemeral-storage: "1Mi"
            limits:
              ephemeral-storage: "2Mi"


在 Kubernetes 裡雖然可以很容易擴充,但不表示資源無限,反而更應該去管控好,避免浪費。

如何檢查RHEL有受到特定CVE影響?

因為好奇怎麼去查,就找到這篇:How to check if an RHEL system is vulnerable to a CVE ,文章裡面提到兩個方法。

第一個方法是用 rpm -q --changelog <套件> | grep <CVE_number>

舉個例子

rpm -q --changelog openssl | grep CVE-2021-3450

第二個方法是用 yum updateinfo info --cve <CVE_number>

舉個例子

yum updateinfo info --cve CVE-2021-3445

最後,想調查這台 RHEL 有受到哪些 Errata 影響,可以用

yum updateinfo info --summary
yum updateinfo info --list

若要帶入 CVE 資訊,可以用這兩個指令

yum updateinfo info --summary --with-cve
yum updateinfo info --list --with-cve

Red Hat 也有一篇 KB ,方法相似:https://access.redhat.com/solutions/3628301

不太一樣的地方是,指令是查看 rpm 的,所以是用

rpm -qp kernel-3.10.0-862.11.6.el7.x86_64.rpm --changelog | grep CVE-2017-12190

或者是用 yum list –cve <CVE_number>

yum list --cve CVE-2017-12190 | grep kernel.x86_64