513.md 9.4 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
# Maintenance Rake tasks

> 原文:[https://docs.gitlab.com/ee/administration/raketasks/maintenance.html](https://docs.gitlab.com/ee/administration/raketasks/maintenance.html)

*   [Gather GitLab and system information](#gather-gitlab-and-system-information)
*   [Show GitLab license information](#show-gitlab-license-information-starter-only)
*   [Check GitLab configuration](#check-gitlab-configuration)
*   [Rebuild authorized_keys file](#rebuild-authorized_keys-file)
*   [Clear Redis cache](#clear-redis-cache)
*   [Precompile the assets](#precompile-the-assets)
*   [Check TCP connectivity to a remote site](#check-tcp-connectivity-to-a-remote-site)
*   [Clear exclusive lease (DANGER)](#clear-exclusive-lease-danger)
*   [Display status of database migrations](#display-status-of-database-migrations)
*   [Run incomplete database migrations](#run-incomplete-database-migrations)
*   [Import common metrics](#import-common-metrics)

# Maintenance Rake tasks[](#maintenance-rake-tasks-core-only "Permalink")

GitLab 提供 Rake 任务进行常规维护.

## Gather GitLab and system information[](#gather-gitlab-and-system-information "Permalink")

该命令收集有关您的 GitLab 安装及其运行系统的信息. 这些在寻求帮助或报告问题时可能很有用.

**全部安装**

```
sudo gitlab-rake gitlab:env:info 
```

**源安装**

```
bundle exec rake gitlab:env:info RAILS_ENV=production 
```

输出示例:

```
System information
System:           Debian 7.8
Current User:     git
Using RVM:        no
Ruby Version:     2.1.5p273
Gem Version:      2.4.3
Bundler Version:  1.7.6
Rake Version:     10.3.2
Redis Version:    3.2.5
Sidekiq Version:  2.17.8

GitLab information
Version:          7.7.1
Revision:         41ab9e1
Directory:        /home/git/gitlab
DB Adapter:       postgresql
URL:              https://gitlab.example.com
HTTP Clone URL:   https://gitlab.example.com/some-project.git
SSH Clone URL:    git@gitlab.example.com:some-project.git
Using LDAP:       no
Using Omniauth:   no

GitLab Shell
Version:          2.4.1
Repositories:     /home/git/repositories/
Hooks:            /home/git/gitlab-shell/hooks/
Git:              /usr/bin/git 
```

## Show GitLab license information[](#show-gitlab-license-information-starter-only "Permalink")

在 GitLab Starter 12.6 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20501) .

该命令显示有关您的[GitLab 许可证](../../user/admin_area/license.html)以及使用了多少个席位的信息. 它仅在 GitLab Enterprise 安装中可用:许可证无法安装到 GitLab Community Edition 中.

当通过支持人员举票或以编程方式检查许可证参数时,这些选项可能很有用.

**全部安装**

```
sudo gitlab-rake gitlab:license:info 
```

**源安装**

```
bundle exec rake gitlab:license:info RAILS_ENV=production 
```

输出示例:

```
Today's Date: 2020-02-29
Current User Count: 30
Max Historical Count: 30
Max Users in License: 40
License valid from: 2019-11-29 to 2020-11-28
Email associated with license: user@example.com 
```

## Check GitLab configuration[](#check-gitlab-configuration "Permalink")

`gitlab:check` Rake 任务运行以下 Rake 任务:

*   `gitlab:gitlab_shell:check`
*   `gitlab:gitaly:check`
*   `gitlab:sidekiq:check`
*   `gitlab:app:check`

它将检查是否已根据安装指南设置了每个组件,并针对发现的问题提出了修复建议. 此命令必须从您的应用程序服务器运行,并且在[Gitaly 之](../gitaly/index.html#run-gitaly-on-its-own-server)类的组件服务器上将无法正常运行.

您还可以查看我们的故障排除指南,以了解:

*   [GitLab](../index.html#troubleshooting)
*   [Omnibus GitLab](https://docs.gitlab.com/omnibus/README.html)

要运行`gitlab:check` ,请运行:

**全部安装**

```
sudo gitlab-rake gitlab:check 
```

**源安装**

```
bundle exec rake gitlab:check RAILS_ENV=production 
```

**注意:**`gitlab:check`使用`SANITIZE=true` `gitlab:check`是否要从输出中省略项目名称.

输出示例:

```
Checking Environment ...

Git configured for git user? ... yes
Has python2? ... yes
python2 is supported version? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version? ... OK (1.2.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
post-receive hook up-to-date? ... yes
post-receive hooks in repos are links: ... yes

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes

Checking Sidekiq ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
Redis version >= 2.0.0? ... yes

Checking GitLab ... Finished 
```

## Rebuild authorized_keys file[](#rebuild-authorized_keys-file "Permalink")

在某些情况下,有必要重建`authorized_keys`文件. 为此,请运行:

**全部安装**

```
sudo gitlab-rake gitlab:shell:setup 
```

**源安装**

```
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production 
```

输出示例:

```
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes 
```

## Clear Redis cache[](#clear-redis-cache "Permalink")

如果出于某种原因,仪表板显示了错误的信息,则可能需要清除 Redis 的缓存. 为此,请运行:

**全部安装**

```
sudo gitlab-rake cache:clear 
```

**源安装**

```
cd /home/git/gitlab
sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production 
```

## Precompile the assets[](#precompile-the-assets "Permalink")

有时,在版本升级期间,您可能会遇到一些错误的 CSS 或缺少某些图标的情况. 在这种情况下,请尝试再次重新编译资产.

这仅适用于源安装,不适用于 Omnibus 软件包.

**源安装**

```
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production 
```

对于多功能版本,未优化的资产(JavaScript,CSS)在上游 GitLab 发行时被冻结. 多功能版本包括这些资产的优化版本. 除非在安装软件包之后在生产机器上修改 JavaScript / CSS 代码,否则应该没有理由在生产机器上重做`rake gitlab:assets:compile` . 如果您怀疑资产已损坏,则应重新安装 omnibus 软件包.

## Check TCP connectivity to a remote site[](#check-tcp-connectivity-to-a-remote-site "Permalink")

有时您需要知道您的 GitLab 安装是否可以连接到另一台机器上的 TCP 服务-也许是 PostgreSQL 或 HTTPS 服务器. 包含一个 Rake 任务可以帮助您:

**全部安装**

```
sudo gitlab-rake gitlab:tcp_check[example.com,80] 
```

**源安装**

```
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:tcp_check[example.com,80] RAILS_ENV=production 
```

## Clear exclusive lease (DANGER)[](#clear-exclusive-lease-danger "Permalink")

GitLab 使用共享锁机制: `ExclusiveLease`防止共享资源中的同时操作. 一个示例是在存储库上运行定期垃圾收集.

在非常特殊的情况下,如果不释放锁定,则由专有租赁锁定的操作可能会失败. 如果您不能等待它过期,可以运行此任务以手动清除它.

要清除所有专有租赁:

**危险:**请勿在 GitLab 或 Sidekiq 运行时运行它

```
sudo gitlab-rake gitlab:exclusive_lease:clear 
```

要指定租约`type`或租约`type + id` ,请指定范围:

```
# to clear all leases for repository garbage collection:
sudo gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:*]

# to clear a lease for repository garbage collection in a specific project: (id=4)
sudo gitlab-rake gitlab:exclusive_lease:clear[project_housekeeping:4] 
```

## Display status of database migrations[](#display-status-of-database-migrations "Permalink")

请参阅[升级文档](../../update/README.html#checking-for-background-migrations-before-upgrading) ,以了解在升级 GitLab 时如何检查迁移是否完成.

要检查特定迁移的状态,可以使用以下 Rake 任务:

```
sudo gitlab-rake db:migrate:status 
```

这将为每个迁移 ID 输出一个`Status``up``down`的表.

```
database: gitlabhq_production

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     migration_id    migration_name 
```

## Run incomplete database migrations[](#run-incomplete-database-migrations "Permalink")

数据库迁移可能会停留在不完整的状态. 也就是说,它们在`sudo gitlab-rake db:migrate:status`命令的输出中将处于`down`状态.

要完成这些迁移,请使用以下 Rake 任务:

```
sudo gitlab-rake db:migrate 
```

命令完成后,运行`sudo gitlab-rake db:migrate:status`来检查是否所有迁移都已完成(具有`up`状态).

## Import common metrics[](#import-common-metrics "Permalink")

有时,您可能需要重新导入为"指标"仪表板提供动力的通用指标.

这可能是由于[更新现有指标](../../development/prometheus_metrics.html#update-existing-metrics)或作为[故障排除措施的结果](../../operations/metrics/dashboards/index.html#troubleshooting) .

要重新导入指标,可以运行:

```
sudo gitlab-rake metrics:setup_common_metrics 
```