Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // BackupETCDService defines the template of backup-etcd service for systemd. BackupETCDService = template.Must(template.New("backup-etcd.service").Parse( dedent.Dedent(`[Unit] Description=Backup ETCD [Service] Type=oneshot ExecStart={{ .ScriptPath }} `))) // BackupETCDTimer defines the template of backup-etcd timer for systemd. BackupETCDTimer = template.Must(template.New("backup-etcd.timer").Parse( dedent.Dedent(`[Unit] Description=Timer to backup ETCD [Timer] {{- if .OnCalendarStr }} OnCalendar={{ .OnCalendarStr }} {{- else }} OnCalendar=*-*-* 02:00:00 {{- end }} Unit=backup-etcd.service [Install] WantedBy=multi-user.target `))) )
View Source
var ( // ETCDService defines the template of etcd's service for systemd. ETCDService = template.Must(template.New("etcd.service").Parse( dedent.Dedent(`[Unit] Description=etcd After=network.target [Service] User=root Type=notify Nice=-20 OOMScoreAdjust=-1000 EnvironmentFile=/etc/etcd.env ExecStart=/usr/local/bin/etcd NotifyAccess=all RestartSec=10s LimitNOFILE=40000 Restart=always [Install] WantedBy=multi-user.target `))) )
View Source
var EtcdBackupScript = template.Must(template.New("etcd-backup.sh").Parse( dedent.Dedent(`#!/bin/bash set -o errexit set -o nounset set -o pipefail ETCDCTL_PATH='/usr/local/bin/etcdctl' ENDPOINTS='{{ .Etcdendpoint }}' {{- if .DataDir }} ETCD_DATA_DIR="{{ .DataDir }}" {{- else }} ETCD_DATA_DIR="/var/lib/etcd" {{- end }} BACKUP_DIR="{{ .Backupdir }}/etcd-$(date +%Y-%m-%d-%H-%M-%S)" KEEPBACKUPNUMBER='{{ .KeepbackupNumber }}' ETCDBACKUPSCIPT='{{ .EtcdBackupScriptDir }}' ETCDCTL_CERT="/etc/ssl/etcd/ssl/admin-{{ .Hostname }}.pem" ETCDCTL_KEY="/etc/ssl/etcd/ssl/admin-{{ .Hostname }}-key.pem" ETCDCTL_CA_FILE="/etc/ssl/etcd/ssl/ca.pem" [ ! -d $BACKUP_DIR ] && mkdir -p $BACKUP_DIR export ETCDCTL_API=2;$ETCDCTL_PATH backup --data-dir $ETCD_DATA_DIR --backup-dir $BACKUP_DIR sleep 3 { export ETCDCTL_API=3;$ETCDCTL_PATH --endpoints="$ENDPOINTS" snapshot save $BACKUP_DIR/snapshot.db \ --cacert="$ETCDCTL_CA_FILE" \ --cert="$ETCDCTL_CERT" \ --key="$ETCDCTL_KEY" } > /dev/null sleep 3 cd $BACKUP_DIR/../ && ls -lt |awk '{if(NR > '$KEEPBACKUPNUMBER'){print "rm -rf "$9}}'|sh `)))
EtcdBackupScriptTmpl defines the template of etcd backup script.
View Source
var EtcdEnv = template.Must(template.New("etcd.env").Parse( dedent.Dedent(`# Environment file for etcd {{ .Tag }} {{- if .DataDir }} ETCD_DATA_DIR={{ .DataDir }} {{- else }} ETCD_DATA_DIR=/var/lib/etcd {{- end }} ETCD_ADVERTISE_CLIENT_URLS=https://{{ .Ip }}:{{ .Port }} ETCD_INITIAL_ADVERTISE_PEER_URLS=https://{{ .Ip }}:{{ .PeerPort }} ETCD_INITIAL_CLUSTER_STATE={{ .State }} ETCD_METRICS=basic ETCD_LISTEN_CLIENT_URLS=https://{{ .Ip }}:{{ .Port }},https://127.0.0.1:{{ .Port }} ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd ETCD_LISTEN_PEER_URLS=https://{{ .Ip }}:{{ .PeerPort }} ETCD_NAME={{ .Name }} ETCD_PROXY=off ETCD_ENABLE_V2=true ETCD_INITIAL_CLUSTER={{ .PeerAddresses }} {{- if .ElectionTimeout }} ETCD_ELECTION_TIMEOUT={{ .ElectionTimeout }} {{- else }} ETCD_ELECTION_TIMEOUT=5000 {{- end }} {{- if .HeartbeatInterval }} ETCD_HEARTBEAT_INTERVAL={{ .HeartbeatInterval }} {{- else }} ETCD_HEARTBEAT_INTERVAL=250 {{- end }} {{- if .CompactionRetention }} ETCD_AUTO_COMPACTION_RETENTION={{ .CompactionRetention }} {{- else }} ETCD_AUTO_COMPACTION_RETENTION=8 {{- end }} {{- if .SnapshotCount }} ETCD_SNAPSHOT_COUNT={{ .SnapshotCount }} {{- else }} ETCD_SNAPSHOT_COUNT=10000 {{- end }} {{- if .Metrics }} ETCD_METRICS={{ .Metrics }} {{- end }} {{- if .QuotaBackendBytes }} ETCD_QUOTA_BACKEND_BYTES={{ .QuotaBackendBytes }} {{- end }} {{- if .MaxRequestBytes }} ETCD_MAX_REQUEST_BYTES={{ .MaxRequestBytes }} {{- end }} {{- if .MaxSnapshots }} ETCD_MAX_SNAPSHOTS={{ .MaxSnapshots }} {{- end }} {{- if .MaxWals }} ETCD_MAX_WALS={{ .MaxWals }} {{- end }} {{- if .LogLevel }} ETCD_LOG_LEVEL={{ .LogLevel }} {{- end }} {{- if .UnsupportedArch }} ETCD_UNSUPPORTED_ARCH={{ .Arch }} {{ end }} {{- if .ExtraArgs }} {{- range $index, $value := .ExtraArgs }} {{ $value }} {{- end }} {{- end }} # TLS settings ETCD_TRUSTED_CA_FILE=/etc/ssl/etcd/ssl/ca.pem ETCD_CERT_FILE=/etc/ssl/etcd/ssl/member-{{ .Hostname }}.pem ETCD_KEY_FILE=/etc/ssl/etcd/ssl/member-{{ .Hostname }}-key.pem ETCD_CLIENT_CERT_AUTH=true ETCD_PEER_TRUSTED_CA_FILE=/etc/ssl/etcd/ssl/ca.pem ETCD_PEER_CERT_FILE=/etc/ssl/etcd/ssl/member-{{ .Hostname }}.pem ETCD_PEER_KEY_FILE=/etc/ssl/etcd/ssl/member-{{ .Hostname }}-key.pem ETCD_PEER_CLIENT_CERT_AUTH=true # CLI settings ETCDCTL_ENDPOINTS=https://127.0.0.1:{{ .Port }} ETCDCTL_CACERT=/etc/ssl/etcd/ssl/ca.pem ETCDCTL_KEY=/etc/ssl/etcd/ssl/admin-{{ .Hostname }}-key.pem ETCDCTL_CERT=/etc/ssl/etcd/ssl/admin-{{ .Hostname }}.pem `)))
EtcdEnv defines the template of etcd's env.
Functions ¶
func BackupTimeOnCalendar ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.