go.etcd.io/etcd@v3.3.27+incompatible/contrib/systemd/etcd3-multinode/README.md (about) 1 # etcd3 multi-node cluster 2 3 Here's how to deploy etcd cluster with systemd. 4 5 ## Set up data directory 6 7 etcd needs data directory on host machine. Configure the data directory accessible to systemd as: 8 9 ``` 10 sudo mkdir -p /var/lib/etcd 11 sudo chown -R root:$(whoami) /var/lib/etcd 12 sudo chmod -R a+rw /var/lib/etcd 13 ``` 14 15 ## Write systemd service file 16 17 In each machine, write etcd systemd service files: 18 19 ``` 20 cat > /tmp/my-etcd-1.service <<EOF 21 [Unit] 22 Description=etcd 23 Documentation=https://github.com/coreos/etcd 24 Conflicts=etcd.service 25 Conflicts=etcd2.service 26 27 [Service] 28 Type=notify 29 Restart=always 30 RestartSec=5s 31 LimitNOFILE=40000 32 TimeoutStartSec=0 33 34 ExecStart=etcd --name my-etcd-1 \ 35 --data-dir /var/lib/etcd \ 36 --listen-client-urls http://${IP_1}:2379 \ 37 --advertise-client-urls http://${IP_1}:2379 \ 38 --listen-peer-urls http://${IP_1}:2380 \ 39 --initial-advertise-peer-urls http://${IP_1}:2380 \ 40 --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \ 41 --initial-cluster-token my-etcd-token \ 42 --initial-cluster-state new 43 44 [Install] 45 WantedBy=multi-user.target 46 EOF 47 sudo mv /tmp/my-etcd-1.service /etc/systemd/system/my-etcd-1.service 48 ``` 49 50 ``` 51 cat > /tmp/my-etcd-2.service <<EOF 52 [Unit] 53 Description=etcd 54 Documentation=https://github.com/coreos/etcd 55 Conflicts=etcd.service 56 Conflicts=etcd2.service 57 58 [Service] 59 Type=notify 60 Restart=always 61 RestartSec=5s 62 LimitNOFILE=40000 63 TimeoutStartSec=0 64 65 ExecStart=etcd --name my-etcd-2 \ 66 --data-dir /var/lib/etcd \ 67 --listen-client-urls http://${IP_2}:2379 \ 68 --advertise-client-urls http://${IP_2}:2379 \ 69 --listen-peer-urls http://${IP_2}:2380 \ 70 --initial-advertise-peer-urls http://${IP_2}:2380 \ 71 --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \ 72 --initial-cluster-token my-etcd-token \ 73 --initial-cluster-state new 74 75 [Install] 76 WantedBy=multi-user.target 77 EOF 78 sudo mv /tmp/my-etcd-2.service /etc/systemd/system/my-etcd-2.service 79 ``` 80 81 ``` 82 cat > /tmp/my-etcd-3.service <<EOF 83 [Unit] 84 Description=etcd 85 Documentation=https://github.com/coreos/etcd 86 Conflicts=etcd.service 87 Conflicts=etcd2.service 88 89 [Service] 90 Type=notify 91 Restart=always 92 RestartSec=5s 93 LimitNOFILE=40000 94 TimeoutStartSec=0 95 96 ExecStart=etcd --name my-etcd-3 \ 97 --data-dir /var/lib/etcd \ 98 --listen-client-urls http://${IP_3}:2379 \ 99 --advertise-client-urls http://${IP_3}:2379 \ 100 --listen-peer-urls http://${IP_3}:2380 \ 101 --initial-advertise-peer-urls http://${IP_3}:2380 \ 102 --initial-cluster my-etcd-1=http://${IP_1}:2380,my-etcd-2=http://${IP_2}:2380,my-etcd-3=http://${IP_3}:2380 \ 103 --initial-cluster-token my-etcd-token \ 104 --initial-cluster-state new 105 106 [Install] 107 WantedBy=multi-user.target 108 EOF 109 sudo mv /tmp/my-etcd-3.service /etc/systemd/system/my-etcd-3.service 110 ``` 111 112 ## Start the service 113 114 The service needs to be enabled first, in case of system reboot: 115 116 ``` 117 sudo systemctl daemon-reload 118 sudo systemctl enable my-etcd-1.service 119 sudo systemctl start my-etcd-1.service 120 ``` 121 122 ``` 123 sudo systemctl daemon-reload 124 sudo systemctl enable my-etcd-2.service 125 sudo systemctl start my-etcd-2.service 126 ``` 127 128 ``` 129 sudo systemctl daemon-reload 130 sudo systemctl enable my-etcd-3.service 131 sudo systemctl start my-etcd-3.service 132 ``` 133 134 ## Check logs 135 136 systemd stores etcd server logs with journald: 137 138 ``` 139 sudo systemctl status my-etcd-1.service -l --no-pager 140 sudo journalctl -u my-etcd-1.service -l --no-pager|less 141 sudo journalctl -f -u my-etcd-1.service 142 ``` 143 144 ``` 145 sudo systemctl status my-etcd-2.service -l --no-pager 146 sudo journalctl -u my-etcd-2.service -l --no-pager|less 147 sudo journalctl -f -u my-etcd-2.service 148 ``` 149 150 ``` 151 sudo systemctl status my-etcd-3.service -l --no-pager 152 sudo journalctl -u my-etcd-3.service -l --no-pager|less 153 sudo journalctl -f -u my-etcd-3.service 154 ``` 155 156 ## Stop etcd 157 158 To disable etcd process: 159 160 ``` 161 sudo systemctl stop my-etcd-1.service 162 sudo systemctl disable my-etcd-1.service 163 ``` 164 165 ``` 166 sudo systemctl stop my-etcd-2.service 167 sudo systemctl disable my-etcd-2.service 168 ``` 169 170 ``` 171 sudo systemctl stop my-etcd-3.service 172 sudo systemctl disable my-etcd-3.service 173 ```