You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs-2.0-en/20.appendix/0.FAQ.md
+1-6
Original file line number
Diff line number
Diff line change
@@ -313,12 +313,7 @@ You can use [NebulaGraph Algorithm](../graph-computing/nebula-algorithm.md).
313
313
314
314
### "The runtime log files are too large. How to recycle the logs?"
315
315
316
-
By default, the runtime logs of NebulaGraph are stored in `/usr/local/nebula/logs/`. The INFO level log files are `nebula-graphd.INFO, nebula-storaged.INFO, nebula-metad.INFO`. If an alarm or error occurs, the suffixes are modified as `.WARNING` or `.ERROR`.
317
-
318
-
NebulaGraph uses [glog](https://github.com/google/glog) to print logs. `glog` cannot recycle the outdated files. To rotate logs, you can:
319
-
320
-
- Add the parameters `timestamp_in_logfile_name=true` (timestamp added to logfile) and `max_log_size=500` (log size limit in MB) to the configuration files of the three services, and then use crontab to delete logs periodically. For more information, see [`Glog should delete old log files automatically`](https://github.com/google/glog/issues/423).
321
-
- Use [logrotate](https://github.com/logrotate/logrotate) to manage log files. Before using logrotate, modify the configurations of corresponding services and set `timestamp_in_logfile_name` to `false`.
316
+
{{nebula.name}} uses [glog](https://github.com/google/glog) for log printing, which does not support log recycling. You can manage runtime logs by using cron jobs or the log management tool [logrotate](https://man7.org/linux/man-pages/man8/logrotate.8.html). For operational details, see [Log recycling](../5.configurations-and-logs/2.log-management/logs.md).
Copy file name to clipboardexpand all lines: docs-2.0-en/5.configurations-and-logs/2.log-management/logs.md
+156-2
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,160 @@ If the log level is changed while NebulaGraph is running, it will be restored to
75
75
76
76
RocksDB runtime logs are usually used to debug RocksDB parameters and stored in`/usr/local/nebula/data/storage/nebula/$id/data/LOG`. `$id` is the ID of the example.
77
77
78
-
## Log recycle
78
+
## Log recycling
79
79
80
-
How to recycle logs when the runtime log file is too large, see [FAQs](../../20.appendix/0.FAQ.md).
80
+
Glog does not inherently support log recycling. To implement this feature, you can either use [cron jobs](https://man7.org/linux/man-pages/man1/crontab.1.html) in Linux to regularly remove old log files or use the log management tool, [logrotate](https://github.com/logrotate/logrotate), to rotate logs for regular archiving and deletion.
81
+
82
+
### Log recycling using cron jobs
83
+
84
+
This section provides an example of how to use cron jobs to regularly delete old log files from the Graph service's runtime logs.
85
+
86
+
1. In the Graph service configuration file, apply the following settings and restart the service:
87
+
88
+
```bash
89
+
timestamp_in_logfile_name = true
90
+
max_log_size = 500
91
+
```
92
+
93
+
- By setting `timestamp_in_logfile_name` to `true`, the log file name includes a timestamp, allowing regular deletion of old log files.
94
+
- The `max_log_size` parameter sets the maximum size of a single log file in MB, such as `500`. Once this size is exceeded, a new log file is automatically created. The default value is `1800`.
95
+
96
+
2. Use the following command to open the cron job editor.
97
+
98
+
```bash
99
+
crontab -e
100
+
```
101
+
102
+
3. Add a cron job command to the editor to regularly delete old log files.
The `find` command in the above command should be executed by the root user or a user with sudo privileges.
111
+
112
+
- `* * * * *`: This cron job time field signifies that the task is executed every minute. For other settings, see [Cron Expression](https://crontab.cronhub.io/).
113
+
- `<log_path>`: The path of the service runtime log file, such as `/usr/local/nebula/logs`.
114
+
- `<YourProjectName>`: The log file name, such as `nebula-graphd.*`.
115
+
- `-mtime +7`: This deletes log files that are older than 7 days. Alternatively, use `-mmin +n` to delete log files older than `n` minutes. For details, see the find command.
116
+
- `-delete`: This deletes log files that meet the conditions.
117
+
118
+
For example, to automatically delete the Graph service runtime log files older than 7 days at 3 o'clock every morning, use:
Logrotate is a tool that can rotate specified log files for archiving and recycling.
130
+
131
+
!!! note
132
+
133
+
You must be the root user or a user with sudo privileges to install or run logrotate.
134
+
135
+
This section provides an example of how to use logrotate to manage the Graph service's `INFO` level log file (`/usr/local/nebula/logs/nebula-graphd.INFO.impl`).
136
+
137
+
1. In the Graph service configuration file, set `timestamp_in_logfile_name` to `false` so that the logrotate tool can recognize the log file name. Then, restart the service.
138
+
139
+
```bash
140
+
timestamp_in_logfile_name = false
141
+
```
142
+
143
+
2. Install logrotate.
144
+
145
+
- For Debian/Ubuntu:
146
+
147
+
```bash
148
+
sudo apt-get install logrotate
149
+
```
150
+
151
+
- For CentOS/RHEL:
152
+
153
+
```bash
154
+
sudo yum install logrotate
155
+
```
156
+
157
+
3. Create a logrotate configuration file, add log rotation rules, and save the configuration file.
158
+
159
+
In the `/etc/logrotate.d` directory, create a new logrotate configuration file `nebula-graphd.INFO`.
160
+
161
+
```bash
162
+
sudo vim /etc/logrotate.d/nebula-graphd.INFO
163
+
```
164
+
165
+
Then, add the following content:
166
+
167
+
```bash
168
+
# The absolute path of the log file needs to be configured
169
+
# And the file name cannot be a symbolic link file, such as `nebula-graph.INFO`
| `daily` | Rotate the log daily. Other available time units include `hourly`, `daily`, `weekly`, `monthly`, and `yearly`. |
187
+
| `rotate 2` | Keep the most recent 2 log files before deleting the older one. |
188
+
| `copytruncate` | Copy the current log file and then truncate it, ensuring no disruption to the logging process. |
189
+
| `nocompress` | Do not compress the old log files. |
190
+
| `missingok` | Do not report errors if the log file is missing. |
191
+
| `notifempty` | Do not rotate the log file if it's empty. |
192
+
|`create 644 root root`| Create a new log file with the specified permissions and ownership. |
193
+
|`dateext`| Add a date extension to the log file name. <br/>The default is the current date in the format `-%Y%m%d`. <br/>You can extend this using the `dateformat` option. |
194
+
|`dateformat .%Y-%m-%d-%s`| This must follow immediately after `dateext` and defines the file name after log rotation. <br/>Before V3.9.0, only `%Y`, `%m`, `%d`, and `%s` parameters were supported. <br/>Starting from V3.9.0, the `%H` parameter is also supported.|
195
+
|`maxsize 1k`| Rotate the log when it exceeds 1 kilobyte (`1024` bytes) in size or when the specified time unit (e.g., `daily`) passes. <br/>You can use size units like `k` and `M`, with the default unit being bytes. |
196
+
197
+
Modify the parameters in the configuration file according to actual needs. For more information about parameter configuration, see [logrotate](https://github.com/logrotate/logrotate).
198
+
199
+
4. Test the logrotate configuration.
200
+
201
+
To verify whether the logrotate configuration is correct, use the following commandfor testing.
Although `logrotate` is typically executed automatically by cron jobs, you can manually execute the following command to perform log rotation immediately.
`-fv`: `f` stands for forced execution, `v` stands for verbose output.
216
+
217
+
6. Verify the log rotation results.
218
+
219
+
After log rotation, new log files are found in the `/usr/local/nebula/logs` directory, such as `nebula-graphd.INFO.impl.2024-01-04-1704338204`. The original log content is cleared, but the file is retained for new log entries. When the number of log files exceeds the value set by `rotate`, the oldest log file is deleted.
220
+
221
+
For example, `rotate `2` means keeping the 2 most recently generated log files. When the number of log files exceeds 2, the oldest log file is deleted.
222
+
223
+
```bash
224
+
[test@test logs]$ ll
225
+
-rw-r--r-- 1 root root 0 Jan 4 11:18 nebula-graphd.INFO.impl
226
+
-rw-r--r-- 1 root root 6894 Jan 4 11:16 nebula-graphd.INFO.impl.2024-01-04-1704338204 # This file is deleted when a new log file is generated
227
+
-rw-r--r-- 1 root root 222 Jan 4 11:18 nebula-graphd.INFO.impl.2024-01-04-1704338287
228
+
[test@test logs]$ ll
229
+
-rw-r--r-- 1 root root 0 Jan 4 11:18 nebula-graphd.INFO.impl
230
+
-rw-r--r-- 1 root root 222 Jan 4 11:18 nebula-graphd.INFO.impl.2024-01-04-1704338287
231
+
-rw-r--r-- 1 root root 222 Jan 4 11:18 nebula-graphd.INFO.impl.2024-01-04-1704338339 # The new log file is generated
232
+
```
233
+
234
+
If you need to rotate multiple log files, create multiple configuration files in the `/etc/logrotate.d` directory, with each configuration file corresponding to a log file. For example, to rotate the `INFO` level log file and the `WARNING` level log file of the Meta service, create two configuration files `nebula-metad.INFO` and `nebula-metad.WARNING`, and add log rotation rules in them respectively.
如果用户需要对多个日志文件进行轮转,可以在`/etc/logrotate.d`目录下创建多个配置文件,每个配置文件对应一个日志文件。例如,用户需要对 Meta 服务的`INFO`级别日志文件和`WARNING`级别日志文件进行轮转,可以创建两个配置文件`nebula-metad.INFO`和`nebula-metad.WARNING`,并在其中分别添加日志轮转规则。
0 commit comments