Skip to content

Commit e65e0e0

Browse files
authored
tiup: Update/fix no sudo mode docs (#20437)
1 parent 0447a65 commit e65e0e0

File tree

1 file changed

+40
-62
lines changed

1 file changed

+40
-62
lines changed

tiup/tiup-cluster-no-sudo-mode.md

Lines changed: 40 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This document describes how to use the TiUP no-sudo mode to deploy a cluster.
2424
1. Use the `tidb` user to set the `XDG_RUNTIME_DIR` environment variable.
2525

2626
```shell
27+
sudo -iu tidb # Switch to the tidb user
2728
mkdir -p ~/.bashrc.d
2829
echo "export XDG_RUNTIME_DIR=/run/user/$(id -u)" > ~/.bashrc.d/systemd
2930
source ~/.bashrc.d/systemd
@@ -32,8 +33,9 @@ This document describes how to use the TiUP no-sudo mode to deploy a cluster.
3233
2. Use the `root` user to start the user service.
3334

3435
```shell
35-
$ systemctl start [email protected] # `1000` is the ID of the tidb user. You can get the user ID by executing the `id` command.
36-
$ systemctl status [email protected]
36+
$ uid=$(id -u tidb) # Get the ID of the tidb user
37+
$ systemctl start user@${uid}.service
38+
$ systemctl status user@${uid}.service
3739
[email protected] - User Manager for UID 1000
3840
Loaded: loaded (/usr/lib/systemd/system/[email protected]; static; vendor preset>
3941
Active: active (running) since Mon 2024-01-29 03:30:51 EST; 1min 7s ago
@@ -57,11 +59,33 @@ This document describes how to use the TiUP no-sudo mode to deploy a cluster.
5759

5860
```shell
5961
loginctl enable-linger tidb
62+
loginctl show-user -p Linger tidb # This should show: Linger=yes
6063
```
6164

6265
You can read the systemd documentation for reference, [Automatic start-up of systemd user instances](https://wiki.archlinux.org/title/Systemd/User#Automatic_start-up_of_systemd_user_instances).
6366

64-
4. Generate a key using `ssh-keygen` on the control machine, and copy the public key to the other deployment machines to establish SSH trust.
67+
4. Generate a key using `ssh-keygen` on the control machine:
68+
69+
```shell
70+
ssh-keygen
71+
```
72+
73+
5. Copy the public key to the other machines in the cluster to establish SSH trust.
74+
75+
- If you have set a password for the `tidb` user, you can use `ssh-copy-id` command to copy the public key to the target machine.
76+
77+
```shell
78+
ssh-copy-id tidb@host
79+
```
80+
81+
You need to replace `host` with the hostname of the target machine and run this command on each of the other machines in the cluster.
82+
83+
- If you use a different method to copy the public key, make sure to check the permissions of the `/home/tidb/.ssh/authorized_keys` file after the copy.
84+
85+
```shell
86+
chown -R tidb:tidb /home/tidb/.ssh/authorized_keys
87+
chmod 600 /home/tidb/.ssh/authorized_keys
88+
```
6589

6690
## Prepare the topology file
6791

@@ -73,9 +97,9 @@ This document describes how to use the TiUP no-sudo mode to deploy a cluster.
7397

7498
2. Edit the topology file.
7599

76-
Compared with the previous mode, when using TiUP in no-sudo mode, you need to add a line `systemd_mode: "user"` in the `global` module of the `topology.yaml` file. The `systemd_mode` parameter is used to set whether to use the `systemd user` mode. If this parameter is not set, the default value is `system`, meaning sudo permissions are required.
100+
Compared with the regular mode, when using TiUP in no-sudo mode, you need to add a line `systemd_mode: "user"` in the `global` module of the `topology.yaml` file. The `systemd_mode` parameter is used to set whether to use the `systemd user` mode. If this parameter is not set, the default value is `system`, meaning sudo permissions are required.
77101

78-
Additionally, in no-sudo mode, because the non-root `tidb` user does not have permission to use the `/data` directory as `deploy_dir` or `data_dir`, you must select a path accessible to non-root users. The following example uses relative paths and the final paths used are `/home/tidb/data/tidb-deploy` and `/home/tidb/data/tidb-data`. The rest of the topology file remains the same as in the previous mode.
102+
Additionally, in no-sudo mode, because the non-root `tidb` user does not have permission to use the `/data` directory as `deploy_dir` or `data_dir`, you must select a path accessible to non-root users. The following example uses relative paths, and the actual paths used are `/home/tidb/data/tidb-deploy` and `/home/tidb/data/tidb-data`. The rest of the topology file remains the same as in the regular mode. Another option is to use the root user to create the directories and then use `chown` to change the ownership to `tidb:tidb`.
79103

80104
```yaml
81105
global:
@@ -90,6 +114,10 @@ This document describes how to use the TiUP no-sudo mode to deploy a cluster.
90114

91115
## Manually repair failed check items
92116

117+
> **Note:**
118+
>
119+
> If you use a minimal install, make sure the `tar` package is installed. Otherwise, the `tiup cluster check` command will fail.
120+
93121
Executing `tiup cluster check topology.yaml --user tidb` can generate some failed check items. The following is an example.
94122

95123
```shell
@@ -109,72 +137,22 @@ Node Check Result Message
109137
192.168.124.27 service Fail service firewalld is running but should be stopped
110138
```
111139

112-
In no-sudo mode, the `tidb` user does not have sudo permissions. As a result, running `tiup cluster check topology.yaml --apply --user tidb` cannot automatically fix the failed check items. You need to manually perform the following steps using the `root` user on the target machines:
113-
114-
1. Install the numactl tool.
115-
116-
```shell
117-
sudo yum -y install numactl
118-
```
119-
120-
2. Close swap.
121-
122-
```shell
123-
swapoff -a || exit 0
124-
```
125-
126-
3. Disable transparent huge pages.
127-
128-
```shell
129-
echo never > /sys/kernel/mm/transparent_hugepage/enabled
130-
```
131-
132-
4. Start the `irqbalance` service.
140+
In no-sudo mode, the `tidb` user does not have sudo permissions. As a result, running `tiup cluster check topology.yaml --apply --user tidb` cannot automatically fix the failed check items. You need to manually fix it by using the `root` user on the target machines.
133141

134-
```shell
135-
systemctl start irqbalance
136-
```
137-
138-
5. Stop the firewall and disable firewall auto-start.
139-
140-
```shell
141-
systemctl stop firewalld.service
142-
systemctl disable firewalld.service
143-
```
144-
145-
6. Modify sysctl parameters.
146-
147-
```shell
148-
echo "fs.file-max = 1000000">> /etc/sysctl.conf
149-
echo "net.core.somaxconn = 32768">> /etc/sysctl.conf
150-
echo "net.ipv4.tcp_tw_recycle = 0">> /etc/sysctl.conf
151-
echo "net.ipv4.tcp_syncookies = 0">> /etc/sysctl.conf
152-
echo "vm.overcommit_memory = 1">> /etc/sysctl.conf
153-
echo "vm.swappiness = 0">> /etc/sysctl.conf
154-
sysctl -p
155-
```
156-
157-
7. Configure the user's `limits.conf` file.
158-
159-
```shell
160-
cat << EOF >>/etc/security/limits.conf
161-
tidb soft nofile 1000000
162-
tidb hard nofile 1000000
163-
tidb soft stack 32768
164-
tidb hard stack 32768
165-
tidb soft core unlimited
166-
tidb hard core unlimited
167-
EOF
168-
```
142+
For more information, see [TiDB Environment and System Configuration Check](/check-before-deployment.md). Note that you need to skip the step [Manually configure the SSH mutual trust and sudo without password](/check-before-deployment.md#manually-configure-the-ssh-mutual-trust-and-sudo-without-password) in the document.
169143

170144
## Deploy and manage the cluster
171145

172146
To use the `tidb` user created in preceding steps and avoid creating a new one, add `--user tidb` when running the following `deploy` command:
173147

174148
```shell
175-
tiup cluster deploy mycluster v8.1.0 topology.yaml --user tidb
149+
tiup cluster deploy mycluster v8.5.0 topology.yaml --user tidb
176150
```
177151

152+
> **Note:**
153+
>
154+
> You need to replace `v8.5.0` in the preceding command with the TiDB version that you want to deploy and `mycluster` with the name you want to give to your cluster.
155+
178156
Start the cluster:
179157

180158
```shell

0 commit comments

Comments
 (0)