https://wiki.archlinux.org/api.php?action=feedcontributions&user=Lanthora&feedformat=atom
ArchWiki - User contributions [en]
2024-03-28T21:56:41Z
User contributions
MediaWiki 1.41.0
https://wiki.archlinux.org/index.php?title=GitLab_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=608197
GitLab (简体中文)
2020-04-26T05:59:24Z
<p>Lanthora: /* 安装 */</p>
<hr />
<div>[[Category:Version Control System (简体中文)]]<br />
[[Category:Web applications (简体中文)]]<br />
[[en:GitLab]]<br />
[[ja:Gitlab]]<br />
{{Related articles start}}<br />
{{Related|Gitolite}}<br />
{{Related|Ruby on Rails}}<br />
{{Related articles end}}<br />
{{TranslationStatus (简体中文)|Gitlab|2018-12-06|555172}}<br />
这是来自 [https://about.gitlab.com/ Gitlab的主页]:<br />
<br />
:GitLab 提供 git 仓储管理、代码查阅、问题追踪、动态监控和维基. 企业在本地安装Gitlab并用LDAP和活动目录服务器连接以进行安全的身份验证和授权。单个GitLab服务器可以处理超过25,000个用户,但也可以使用多个活动服务器创建高可用性设置。<br />
<br />
你可以在 [https://gitlab.com/ GitLab.com]找到实时版本的例子.<br />
<br />
== 安装 ==<br />
<br />
{{Note|这篇文章优先覆盖非https安装和配置Gitlab. 如果需要,查阅[[#Advanced Configuration]]{{Broken section link}} 来设置SSL.}}<br />
<br />
Gitlab需要 [[Redis]] 和数据库后端. 如果你计划在同一个机器运行的话, 首先得安装 [[PostgreSQL (简体中文)]].<br />
<br />
[[Install]] {{pkg|gitlab}} 包.<br />
<br />
为了接受邮件通知, 一个邮件服务器必须被安装和配置. 查阅 [[:Category:Mail server]] 获取更多细节.<br />
<br />
== 配置 ==<br />
<br />
=== 初步说明 ===<br />
<br />
Gitlab包括多种组件, 可查阅 [https://docs.gitlab.com/ce/development/architecture.html 架构概览页].<br />
<br />
{{pkg|gitlab}} 包会以更接近标准Linux公约的方式安装Gitlab:<br />
<br />
{| class="wikitable"<br />
! 描述 <br />
! [https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md GitLab's Official] <br />
! {{pkg|gitlab}} <br />
|----------------------------------------------------------<br />
| 配置文件 GitShell<br />
| {{ic|/home/git/gitlab-shell/config.yml}}<br />
| {{ic|/etc/webapps/gitlab-shell/config.yml}}<br />
|----------------------------------------------------------<br />
| 配置文件 GitLab<br />
| {{ic|/home/git/gitlab/config/gitlab.yml}}<br />
| {{ic|/etc/webapps/gitlab/gitlab.yml}}<br />
|----------------------------------------------------------<br />
| 用户 (家目录)<br />
| {{ic|git}} ({{ic|/home/git}})<br />
| {{ic|gitlab}} ({{ic|/var/lib/gitlab}})<br />
|}<br />
<br />
{{Tip|如果你熟悉 [[Arch Build System]] 你可以编辑PKGBUILD和相关文件来改变gitlab的家目录到你喜欢的位置.}}<br />
<br />
===GitLab===<br />
编辑 {{ic|/etc/webapps/gitlab/gitlab.yml}} 并至少设置下面的参数:<br />
<br />
{{Note| {{ic|hostname}} 和 {{ic|port}} 被用于 {{ic|git clone http://hostname:port}} 的例子中.}}<br />
<br />
'''Hostname:''' 在 {{ic|gitlab:}} 区里设置 {{ic|host:}} - 把 {{ic|localhost}} 换成 {{ic|yourdomain.com}} ('''注意:''' 不要加 'http://' 或者后面的斜线) - 到你的完全合格的域名.<br />
<br />
'''Port:''' {{ic|port:}} 可能会让你很困扰. 这不是Gitlab服务器运行的端口(unicorn) ; 这是用户通过浏览器初次连接的端口. 基本上, 如果你有意让用户通过他们的浏览器访问 'yourdomain.com' , 而且不用附加端口号, 把 {{ic|port:}} 设成 {{ic|80}}. 如果你想让用户输入比如 'yourdomain.com:3425' 这样的东西到浏览器, 那么你就得设置 {{ic|port:}} 成 {{ic|3425}}. 你也会得 '''设置你的网络服务器''' 来监听那个端口.<br />
<br />
'''Timezone (时区,可选):''' {{ic|time_zone:}} 参数是可选的, 但是它可能对强制Gitlab应用的区域有用.<br />
<br />
最后设置正确的 [[permissions]] 到 ''uploads''(上传) 目录:<br />
<br />
# chmod 700 /var/lib/gitlab/uploads<br />
<br />
=== 为Unicorn自定义端口 ===<br />
<br />
GitLab Unicorn 是处理大多数用户请求的主要组件. 默认的, 它监听 {{ic|127.0.0.1:8080}} 地址,并且能通过 {{ic|/etc/webapps/gitlab/unicorn.rb}} 文件来改变:<br />
<br />
{{hc|/etc/webapps/gitlab/unicorn.rb|2=<br />
listen "/run/gitlab/gitlab.socket", :backlog => 1024<br />
listen "'''127.0.0.1:8080'''", :tcp_nopush => true<br />
}}<br />
<br />
如果 Unicorn 地址被改变, 其它与Unicorn交流的组件的配置也需要被更新:<br />
<br />
*对于 GitLab Shell, 在 {{ic|/etc/webapps/gitlab-shell/config.yml}}更新 {{ic|gitlab_url}} 变量.<br />
: {{Tip|根据注释里的配置文件, UNIX 套接字能通过 URL转义斜杠(/) (即. {{ic|http+unix://%2Frun%2Fgitlab%2Fgitlab.socket}} 对应默认的 {{ic|/run/gitlab/gitlab.socket}}). 额外的, 未转义斜杠能用来指定 [https://docs.gitlab.com/ce/install/relative_url.html 相关URL根路径] (例如. {{ic|/gitlab}}).}}<br />
* 对于 GitLab Workhorse, [[edit]] {{ic|gitlab-workhorse.service}} 并更新 {{ic|-authBackend}} 选项.<br />
<br />
=== 秘密字符串 ===<br />
<br />
确定 {{ic|/etc/webapps/gitlab/secret}} 和 {{ic|/etc/webapps/gitlab-shell/secret}} 文件包含了些什么. 它们的内容应该被保密因为它们会被用作生成认证令牌等.<br />
<br />
比如, 能够通过下面的命令生成随机字符串:<br />
<br />
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab/secret<br />
# chown root:gitlab /etc/webapps/gitlab/secret<br />
# chmod 640 /etc/webapps/gitlab/secret<br />
<br />
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab-shell/secret<br />
# chown root:gitlab /etc/webapps/gitlab-shell/secret<br />
# chmod 640 /etc/webapps/gitlab-shell/secret<br />
<br />
===Redis===<br />
<br />
为了提供足够的性能,你可能需要一个缓存数据库. [[Redis#Installation|安装]] 并 [[Redis#Configuration|配置]] 一个redis实例, 注意专用于通过套接字监听的部分.<br />
<br />
* 添加 {{ic|gitlab}} 用户到 {{ic|redis}} [[user group]].<br />
<br />
* 更新配置文件:<br />
{{hc|/etc/webapps/gitlab/resque.yml|2=<br />
development: unix:/run/redis/redis.sock<br />
test: unix:/run/redis/redis.sock<br />
production: unix:/run/redis/redis.sock<br />
}}<br />
<br />
{{hc|/etc/webapps/gitlab-shell/config.yml|2=<br />
# Redis settings used for pushing commit notices to gitlab<br />
redis:<br />
bin: /usr/bin/redis-cli<br />
host: 127.0.0.1<br />
port: 6379<br />
# pass: redispass # Allows you to specify the password for Redis<br />
database: 5 # Use different database, default up to 16<br />
socket: /run/redis/redis.sock # '''uncomment''' this line<br />
namespace: resque:gitlab<br />
}}<br />
<br />
=== 数据库后端 ===<br />
<br />
在Gitlab运行之前需要一个数据库后端. GitLab [https://docs.gitlab.com/ce/install/installation.html#6-database 建议] 使用 PostgreSQL.<br />
<br />
==== PostgreSQL ====<br />
<br />
登录 PostgreSQL 并创造 {{ic|gitlabhq_production}} 数据库和它的用户一起. 记得改变 {{ic|your_username_here}} 和 {{ic|your_password_here}} 到你的真正的值:<br />
<br />
# psql -d template1<br />
<br />
{{bc|1=<br />
template1=# CREATE USER your_username_here WITH PASSWORD 'your_password_here';<br />
template1=# ALTER USER your_username_here SUPERUSER;<br />
template1=# CREATE DATABASE gitlabhq_production OWNER your_username_here;<br />
template1=# \q<br />
}}<br />
<br />
{{Note|创建超级用户的目的是Gitlab在视图变得"智能"并安装扩展(并不仅仅在它的命名区间创建).并且它只被Postgresql的超级用户允许.}}<br />
<br />
用新用户连接到新数据库来确定它有用:<br />
<br />
# psql -d gitlabhq_production<br />
<br />
复制 PostgreSQL 文件 ,在配置它之前 (覆盖默认的 MySQL 配置文件):<br />
<br />
# cp /usr/share/doc/gitlab/database.yml.postgresql /etc/webapps/gitlab/database.yml<br />
<br />
打开新的 {{ic|/etc/webapps/gitlab/database.yml}} 并设置 {{ic|username:}} 和 {{ic|password:}}的值. 比如:<br />
<br />
{{hc|/etc/webapps/gitlab/database.yml|<br />
#<br />
# PRODUCTION<br />
#<br />
production:<br />
adapter: postgresql<br />
encoding: unicode<br />
database: gitlabhq_production<br />
pool: 10<br />
username: your_username_here<br />
password: "your_password_here"<br />
# host: localhost<br />
# port: 5432<br />
# socket: /tmp/postgresql.sock<br />
...<br />
}}<br />
<br />
对于我们的目的 (除非你知道你在干什么),你不必担心配置列在 {{ic|/etc/webapps/gitlab/database.yml}}的其它数据库. 我们只需要设置生产的数据库来让Gitlab工作.<br />
<br />
==== MariaDB ====<br />
<br />
{{Warning|通过MariaDB使用Gitlab是 [https://docs.gitlab.com/ce/install/database_mysql.html 不推荐的]. 你可能会碰到像 {{ic|Specified key was too long; max key length is 767 bytes}} 的问题,当你试图使用[[MariaDB]].}}<br />
<br />
为了设置 MySQL (MariaDB) 你需要创建一个数据库叫做{{ic|gitlabhq_production}} ,和一个对数据库有全部权限的用户一起 (默认: {{ic|gitlab}}) :<br />
<br />
{{hc|$ mysql -u root -p|2=<br />
mysql> CREATE DATABASE `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;<br />
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'password';<br />
mysql> GRANT ALL ON `gitlabhq_production`.* TO 'gitlab'@'localhost';<br />
mysql> \q<br />
}}<br />
<br />
用新用户连接新数据库:<br />
<br />
$ mysql -u '''gitlab''' -p -D gitlabhq_production<br />
<br />
在配置MySQL模板文件前复制它:<br />
<br />
# cp /usr/share/doc/gitlab/database.yml.mysql /etc/webapps/gitlab/database.yml<br />
<br />
下一步你需要打开 {{ic|/etc/webapps/gitlab/database.yml}} 并为 {{ic|gitlabhq_production}}设置 {{ic|username:}} 和 {{ic|password:}} :<br />
<br />
{{hc|/etc/webapps/gitlab/database.yml|<br />
#<br />
# PRODUCTION<br />
#<br />
production:<br />
adapter: mysql2<br />
encoding: utf8<br />
collation: utf8_general_ci<br />
reconnect: false<br />
database: gitlabhq_production<br />
pool: 10<br />
username: '''username'''<br />
password: '''"password"'''<br />
# host: localhost<br />
# socket: /run/mysqld/mysqld.sock # If running MariaDB as socket<br />
...<br />
}}<br />
<br />
它不应该被设为全局可读,比如只有运行在{{ic|gitlab}}下的进程才有读/写权限:<br />
<br />
# chmod 600 /etc/webapps/gitlab/database.yml<br />
# chown gitlab:gitlab /etc/webapps/gitlab/database.yml<br />
<br />
获取更多信息和其它创建/管理MySQL数据库的办法, 查阅 [https://mariadb.org/docs/ MariaDB documentation] 和 [https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md GitLab official (generic) install guide].<br />
<br />
=== 防火墙 ===<br />
<br />
如果你想通过[[Iptables (简体中文)]] 防火墙给予Gitlab安装过程直接权限, 你可能需要调整端口和网络地址:<br />
<br />
# iptables -A tcp_inbound -p TCP -s '''192.168.1.0/24''' --destination-port '''80''' -j ACCEPT<br />
<br />
启用 API-access:<br />
<br />
# iptables -A tcp_inbound -p TCP -s '''192.168.1.0/24''' --destination-port '''8080''' -j ACCEPT<br />
<br />
如果你在一个路由器后面, 别忘了转发这个端口到Gitlab服务器端口, 如果你想运行 WAN-access的话.<br />
<br />
=== 初始化Gitlab数据库 ===<br />
<br />
在初始化数据库之前开启 [[Redis]] 服务器和 {{ic|gitlab-gitaly.service}} .<br />
<br />
初始化数据库并激活更多特性:<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:setup RAILS_ENV=production"<br />
<br />
最后运行下面的命令来检查你的安装:<br />
<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:env:info RAILS_ENV=production"<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:check RAILS_ENV=production"<br />
<br />
{{note|<br />
* ''gitlab:env:info'' 和 ''gitlab:check'' 命令会显示一个和Git相关的严重的错误. 这是正常的.<br />
*''gitlab:check'' 会显示缺少初始化脚本. 这也没什么好担心的, 因为 [[systemd]] 服务文件会被相应使用 (而这Gitlab无法识别).<br />
}}<br />
<br />
=== 调整修改位 ===<br />
(如果用户和组所有权没有正确配置的话Gitlab检查不会通过)<br />
<br />
# chmod -R ug+rwX,o-rwx /var/lib/gitlab/repositories/<br />
# chmod -R ug-s /var/lib/gitlab/repositories<br />
# find /var/lib/gitlab/repositories/ -type d -print0 | xargs -0 chmod g+s<br />
<br />
== 开始并测试Gitlab ==<br />
<br />
确定 [[MySQL (简体中文)]]或 [[PostgreSQL (简体中文)]] 和 [[Redis]] 运行和设置正确.<br />
<br />
然后 [[start]]/[[enable]] {{ic|gitlab.target}}.<br />
<br />
现在你可以通过访问 http://localhost:8080 或者 http://yourdomain.com来测试你的Gitlab, 你可能会被提示创建密码:<br />
<br />
{{bc|<br />
username: root<br />
password: You'll be prompted to create one on your first visit.<br />
}}<br />
<br />
查阅[[#Troubleshooting]]{{Broken section link}} 和在 {{ic|/usr/share/webapps/gitlab/log/}} 目录下的日志文件来 排除故障.<br />
<br />
== 每次更新时升级数据库==<br />
在更新 {{Pkg|gitlab}} 包后, 需要升级数据库:<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake db:migrate RAILS_ENV=production"<br />
<br />
之后, 之后重启Gitlab相关服务:<br />
# systemctl daemon-reload<br />
# systemctl restart gitlab-sidekiq gitlab-unicorn gitlab-workhorse gitlab-gitaly<br />
<br />
== 更多配置 ==<br />
<br />
=== 基本的 SSH ===<br />
在完成了基本安装后, 为用户设置ssh权限. [[Secure Shell (简体中文)]]的配置会在下面描述. [[Secure_Shell#Other_SSH_clients_and_servers|其它SSH客户端和服务器 ]]{{Broken section link}}需要不同的调整.<br />
<br />
获取添加用户SSH秘钥的建议,过程在[https://docs.gitlab.com/ee/ssh/ GitLab] 网站里描述的很好了. 你可以在 {{ic|/var/lib/gitlab/log/gitlab-shell.log}}检查管理员日志来确认用户SSH秘钥被正确提交了. 在这些事件之后, GitLab 添加这些秘钥到''authorized_keys'' 文件里,它在 {{ic|/var/lib/gitlab/.ssh/authorized_keys}}.<br />
<br />
测试秘钥的常见方法 (比如: {{ic|<nowiki>$ ssh -T git@</nowiki>''YOUR_SERVER''}}) 需要一点额外配置才能正常工作. 在 {{ic|/etc/webapps/gitlab/gitlab.yml}} (默认用户: {{ic|gitlab}})里配置的用户必须添加到服务器的sshd配置文件,除此之外还有几个其它改变 :<br />
{{hc|/etc/ssh/sshd_config|<br />
PubkeyAuthentication yes<br />
AuthorizedKeysFile %h/.ssh/authorized_keys<br />
}}<br />
<br />
更新配置文件之后, 重启ssh守护进程:<br />
# systemctl restart sshd<br />
<br />
测试用户SSH米哟啊 (可选添加 -v 来查看额外信息):<br />
<nowiki>$ ssh -T </nowiki>'''gitlab'''@''YOUR_SERVER''<br />
<br />
=== 自定义SSH连接 ===<br />
如果你在一个非标准端口运行SSH,你必须改变Gitlab用户的SSH配置:<br />
{{hc|/var/lib/gitlab/.ssh/config|2=<br />
host localhost # Give your setup a name (here: override localhost)<br />
user gitlab # Your remote git user<br />
port 2222 # Your port number<br />
hostname 127.0.0.1; # Your server name or IP<br />
}}<br />
<br />
你还必须在 {{ic|/etc/webapps/gitlab/gitlab.yml}} 文件里改变相应的选项 (比如. ssh_user, ssh_host, admin_uri) .<br />
<br />
=== HTTPS/SSL ===<br />
<br />
==== 改变Gitlab配置 ====<br />
修改 {{ic|/etc/webapps/gitlab/shell.yml}} 那样到你的Gitlab站点的URL就会以 {{ic|https://}}开头.<br />
修改 {{ic|/etc/webapps/gitlab/gitlab.yml}} 那样 {{ic|https:}} 设置就会被设为 {{ic|true}}.<br />
<br />
查阅 [[Apache HTTP Server#TLS]] 和 [[Let’s Encrypt]].<br />
<br />
==== Let's Encrypt(让我们加密吧) ====<br />
<br />
验证你的URL, Let's Encrypt的过程会试图用像 {{ic|<nowiki>https://gitlab.</nowiki>''YOUR_SERVER_FQDN''/.well-known/acme-challenge/''A_LONG_ID''}}的东西连接你的Gitlab服务器. 但是, 因为Gitlab配置, 每个到 {{ic|gitlab.''YOUR_SERVER_FQDN''}} 的请求会被重定向到一个代理 (gitlab-workhorse) 而它无法处理这个URL.<br />
<br />
为了绕过这个问题, 你可以使用 Let's Encrypt的webroot配置, 在 {{ic|/srv/http/letsencrypt/}}设置webroot.<br />
<br />
除此之外, 强迫到Gitlab的Let's Encrypt请求重定向到这个webroot可通过添加下面的:<br />
<br />
{{hc|/etc/http/conf/extra/gitlab.conf|<br />
Alias "/.well-known" "/srv/http/letsencrypt/.well-known"<br />
RewriteCond %{REQUEST_URI} !/\.well-known/.*<br />
}}<br />
<br />
===Web服务器配置===<br />
如果你想把Gitlab集成进一个运行的服务器而不是用它的内置http服务器Unicorn,那么按照这些说明操作.<br />
<br />
===== Node.js =====<br />
你可以轻松在443端口设置http代理来代理到8080端口的Gitlab程序的流量,通过为Node.js使用http-master. 在你创建你的域名的 OpenSSL 秘钥并获取你的CA 证书 (或自己设置的)后, 然后去 https://github.com/CodeCharmLtd/http-master 来学习使用https代理到Gitlab的请求多容易. http-master 建立在 [https://github.com/nodejitsu/node-http-proxy node-http-proxy]之上.<br />
<br />
==== Nginx ====<br />
<br />
查阅 [[Nginx#Configuration]] 获取基本的 ''nginx'' 配置信息和 [[Nginx#TLS]] 来启用 HTTPS. 在这个部分的例子假设服务器区块是用 [[Nginx#Managing server entries]]管理的.<br />
<br />
创建和编辑基于下面代码的配置. 查阅 [https://gitlab.com/gitlab-org/gitlab-ce/tree/master/lib/support/nginx upstream GitLab repository]获取更多例子.<br />
<br />
{{hc|/etc/nginx/servers-available/gitlab|<nowiki><br />
upstream gitlab-workhorse {<br />
server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;<br />
}<br />
<br />
server {<br />
listen 80;<br />
#listen 443 ssl; # uncomment to enable ssl<br />
server_name example.com<br />
<br />
#ssl_certificate ssl/example.com.crt;<br />
#ssl_certificate_key ssl/example.com.key;<br />
<br />
location / {<br />
# unlimited upload size in nginx (so the setting in GitLab applies)<br />
client_max_body_size 0;<br />
<br />
# proxy timeout should match the timeout value set in /etc/webapps/gitlab/unicorn.rb<br />
proxy_read_timeout 60;<br />
proxy_connect_timeout 60;<br />
proxy_redirect off;<br />
<br />
proxy_set_header Host $http_host;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
proxy_set_header X-Forwarded-Ssl on;<br />
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
proxy_set_header X-Forwarded-Proto $scheme;<br />
<br />
proxy_pass http://gitlab-workhorse;<br />
}<br />
<br />
error_page 404 /404.html;<br />
error_page 422 /422.html;<br />
error_page 500 /500.html;<br />
error_page 502 /502.html;<br />
error_page 503 /503.html;<br />
location ~ ^/(404|422|500|502|503)\.html$ {<br />
root /usr/share/webapps/gitlab/public;<br />
internal;<br />
}<br />
}<br />
</nowiki>}}<br />
<br />
==== Apache ====<br />
<br />
安装并配置 [[Apache HTTP Server (简体中文)]]. 你可以使用这些 [https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/apache upstream recipes] 来开始Gitlab虚拟主机的配置文件.<br />
<br />
对于SSL配置查阅 [[Apache HTTP Server#TLS]]. 如果你不需要它, 移除它. 注意到SSL虚拟主机需要特定IP而不是通用IP. 同样如果你为Unicorn设置了自定义端口, 不要忘了在 {{ic|BalanceMember}} 行也设置它.<br />
<br />
=== Gitlab-workhorse ===<br />
<br />
{{Remove| {{Pkg|gitlab-workhorse}} 组件现在是有必要的. 默认设置能应对普遍的情况所以这个部分能被移除.}}<br />
<br />
{{Expansion|这个部分还需要配置指导.}}<br />
<br />
Gitlab8.0以后使用分开的http服务器{{Pkg|gitlab-workhorse}}来应对大量的http请求比如 Git 推送/拉取. 如果你想使用这个而不是 SSH, 安装 {{Pkg|gitlab-workhorse}} 包, 启用 {{ic|gitlab-workhorse.service}} 并为它配置web服务器. {{Pkg|gitlab-workhorse}} 优先级应高于 {{ic|gitlab-unicorn}} 根据 GitLab 的建议: https://gitlab.com/gitlab-org/gitlab-ce/issues/22528#note_16036216<br />
<br />
{{Note|Unicorn还是需要所以不要disable或者stop它 {{ic|gitlab-unicorn.service}}.}}<br />
<br />
默认 {{Pkg|gitlab-workhorse}} 监听 {{ic|/run/gitlab/gitlab-workhorse.socket}}. 你可以 [[edit]] {{ic|gitlab-workhorse.service}} 并改变参数 {{ic|-listenAddr}} 来让它监听一个地址, 例如 {{ic|-listenAddr 127.0.0.1:8181}}. 如果你监听一个地址的话你也要把网络类型设置为 {{ic|-listenNetwork tcp}}<br />
<br />
当你使用nginx时记得修改你的nginx配置文件. 从gitlab-unicorn 转换到 gitlab-workhorse 相应的编辑以下两个设置<br />
{{hc|/etc/nginx/servers-available/gitlab|2=<br />
upstream gitlab {<br />
server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;<br />
}<br />
<br />
...<br />
<br />
proxy_pass http://unix:/run/gitlab/gitlab-workhorse.socket;<br />
} <br />
}<br />
}}<br />
<br />
==有用的建议==<br />
<br />
===隐藏选项===<br />
到Gitlab的家目录:<br />
# cd /usr/share/webapps/gitlab<br />
<br />
并运行:<br />
{{hc|<nowiki># rake -T | grep gitlab</nowiki>|<nowiki><br />
rake gitlab:app:check # GITLAB | Check the configuration of the GitLab Rails app<br />
rake gitlab:backup:create # GITLAB | Create a backup of the GitLab system<br />
rake gitlab:backup:restore # GITLAB | Restore a previously created backup<br />
rake gitlab:check # GITLAB | Check the configuration of GitLab and its environment<br />
rake gitlab:cleanup:block_removed_ldap_users # GITLAB | Cleanup | Block users that have been removed in LDAP<br />
rake gitlab:cleanup:dirs # GITLAB | Cleanup | Clean namespaces<br />
rake gitlab:cleanup:repos # GITLAB | Cleanup | Clean repositories<br />
rake gitlab:env:check # GITLAB | Check the configuration of the environment<br />
rake gitlab:env:info # GITLAB | Show information about GitLab and its environment<br />
rake gitlab:generate_docs # GITLAB | Generate sdocs for project<br />
rake gitlab:gitlab_shell:check # GITLAB | Check the configuration of GitLab Shell<br />
rake gitlab:import:all_users_to_all_groups # GITLAB | Add all users to all groups (admin users are added as owners)<br />
rake gitlab:import:all_users_to_all_projects # GITLAB | Add all users to all projects (admin users are added as masters)<br />
rake gitlab:import:repos # GITLAB | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance<br />
rake gitlab:import:user_to_groups[email] # GITLAB | Add a specific user to all groups (as a developer)<br />
rake gitlab:import:user_to_projects[email] # GITLAB | Add a specific user to all projects (as a developer)<br />
rake gitlab:satellites:create # GITLAB | Create satellite repos<br />
rake gitlab:setup # GITLAB | Setup production application<br />
rake gitlab:shell:build_missing_projects # GITLAB | Build missing projects<br />
rake gitlab:shell:install[tag,repo] # GITLAB | Install or upgrade gitlab-shell<br />
rake gitlab:shell:setup # GITLAB | Setup gitlab-shell<br />
rake gitlab:sidekiq:check # GITLAB | Check the configuration of Sidekiq<br />
rake gitlab:test # GITLAB | Run all tests<br />
rake gitlab:web_hook:add # GITLAB | Adds a web hook to the projects<br />
rake gitlab:web_hook:list # GITLAB | List web hooks<br />
rake gitlab:web_hook:rm # GITLAB | Remove a web hook from the projects<br />
rake setup # GITLAB | Setup gitlab db<br />
</nowiki>}}<br />
<br />
===备份和恢复===<br />
<br />
创建Gitlab系统的备份:<br />
# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create<br />
<br />
从之前创建的备份文件恢复 {{ic|/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740_gitlab_backup.tar}}:<br />
# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740<br />
<br />
{{Note| 备份文件夹在 {{ic|config/gitlab.yml}}设置. GitLab 备份和恢复记录在 [https://github.com/gitlabhq/gitlabhq/blob/master/doc/raketasks/backup_restore.md 这里].}}<br />
<br />
===通过SMTP从Gitlab发送邮件===<br />
<br />
你可能想用 gmail (或者其它邮件服务) 从你的Gitlab寄邮件. 这能避免在Gitlab服务器上安装邮件守护进程的需要.<br />
<br />
根据你的邮件服务器设置调整 {{ic|smtp_settings.rb}} :<br />
<br />
{{hc|/usr/share/webapps/gitlab/config/initializers/smtp_settings.rb|<nowiki><br />
if Rails.env.production?<br />
Gitlab::Application.config.action_mailer.delivery_method = :smtp<br />
<br />
ActionMailer::Base.delivery_method = :smtp<br />
ActionMailer::Base.smtp_settings = {<br />
address: 'smtp.gmail.com',<br />
port: 587,<br />
domain: 'gmail.com',<br />
user_name: 'username@gmail.com',<br />
password: 'application password',<br />
authentication: 'plain',<br />
enable_starttls_auto: true<br />
}<br />
end</nowiki>}}<br />
<br />
Gmail 会拒绝这样接受的邮件 (并会邮寄给你一个邮件它拒绝了). 你需要关闭安全认证 (按照拒绝邮件中的链接) 来解决这个问题. 更安全的办法是为username@gmail.com开启双因素认证并为这个配置文件设置应用密码.<br />
<br />
==故障排除==<br />
<br />
=== HTTPS不是绿色 (gravatar不使用 https) ===<br />
Redis 缓存了 gravatar 图像, 如果你用http拜访 GitLab, 那么启用 https, gravatar 会加载不安全的图像. 你可以清楚这些缓存通过执行以下命令<br />
<br />
cd /usr/share/webapps/gitlab<br />
RAILS_ENV=production bundle-2.3 exec rake cache:clear<br />
<br />
以Gitlab用户的身份.<br />
<br />
=== 更新后的错误 ===<br />
从AUR更新安装包后, 数据库迁移和资源更新有时候会失败. 这些步骤可以解决这些问题, 如果简单的开关机不行的话.<br />
<br />
首先, 移动到Gitlab安装目录.<br />
# cd /usr/share/webapps/gitlab<br />
<br />
如果每个Gitlab页面都给了一个500页面, 那么数据库迁移和资源可能太陈旧了. 如果不是的话, 跳过这步.<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake db:migrate RAILS_ENV=production"<br />
<br />
如果Gitlab一直在等待布置完成的话, 那么资源可能没有被重新编译.<br />
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:assets:clean gitlab:assets:compile cache:clear RAILS_ENV=production"<br />
<br />
最后, 重启Gitlab服务再测试你的网站.<br />
# systemctl restart gitlab-unicorn gitlab-sidekiq gitlab-workhorse<br />
<br />
=== Gitlab-Unicorn 无法访问非默认的从库目录 ===<br />
<br />
如果自定义的仓库存储目录被设置在 {{ic|/home}}, 在{{ic|gitlab-unicorn.service}}禁用 {{ic|1=ProtectHome=true}} 参数 (查阅 [[Systemd#Drop-in files]] 和 [https://forum.gitlab.com/t/cannot-change-repositores-location/9634/2 github.com上的相关论坛帖子]).<br />
<br />
=== 无法连接到 Gitaly ===<br />
<br />
有时候, Gitaly服务无法开始, 让gitlab无法连接到gitlay. 解决办法很简单:<br />
# systemctl start gitlab-gitaly<br />
<br />
==也可查阅==<br />
*[https://docs.gitlab.com/ce/install/installation.html Official installation documentation]<br />
*[https://gitlab.com/gitlab-org/gitlab-recipes GitLab recipes with further documentation on running it with several web servers]<br />
*[https://gitlab.com/gitlab-org/gitlab-ce GitLab source code]</div>
Lanthora
https://wiki.archlinux.org/index.php?title=Pacman_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)/Tips_and_tricks_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=573448
Pacman (简体中文)/Tips and tricks (简体中文)
2019-05-18T00:18:51Z
<p>Lanthora: /* pacman-optimize 已经移除 */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package management (简体中文)]]<br />
[[Category:简体中文]]<br />
[[en:Pacman/Tips and tricks]]<br />
[[es:Pacman/Tips and tricks]]<br />
[[fa:Pacman tips]]<br />
[[fr:Pacman/Trucs et Astuces]]<br />
[[it:Pacman/Tips and tricks]]<br />
[[ja:Pacman ヒント]]<br />
[[pt:Pacman/Tips and tricks]]<br />
[[ru:Pacman/Tips and tricks]]<br />
{{Related articles start (简体中文)}}<br />
{{Related|Mirrors (简体中文)}}<br />
{{Related2|Creating packages (简体中文)|创建软件包}}<br />
{{Related articles end}}<br />
{{TranslationStatus (简体中文)|Pacman_tips|2017-08-29|487415}}<br />
Pacman 本身也是 bash 程序,所以有些通用优化请参考 [[Core utilities]] 和 [[Bash]].<br />
<br />
==维护==<br />
保持系统干净,遵循 [[Arch Linux (简体中文)|Arch 之道]]。参考 [[System maintenance]].<br />
<br />
=== 查询软件包 ===<br />
要获取已经的软件包以及它们的版本:<br />
<br />
* 所有明确安装的软件包: {{ic|pacman -Qe}}.<br />
* 所有明确安装的,存在于数据库而且不是直接或可选依赖的软件包: {{ic|pacman -Qent}}.<br />
* 所有外部软件包 (通常是手动下载安装,或者已经从数据库中删除): {{ic|pacman -Qm}}.<br />
* 所有从数据库中安装的软件包: {{ic|pacman -Qn}}.<br />
* 按正则表达式查询软件包: {{ic|pacman -Qs ''regex''}}.<br />
* 按正则表达式查询软件包,自定义输出格式:{{ic|expac -s "%-30n %v" ''regex''}} (需要安装 {{Pkg|expac}}).<br />
<br />
===显示所有软件包及其大小===<br />
将所有软件包按占用空间大小排序输出:<br />
<br />
* 安装 {{Pkg|expac}} 并运行 {{ic| expac -s "%-30n %m" | sort -rhk 2}}<br />
* 用 [community] 中的 {{pkg|pacgraph}} 加 -c 选项可以生成所有安装的软件包及其大小.<br />
<br />
==== 获取大小 ====<br />
<br />
要按大小排序安装的软件包:<br />
<br />
* 安装 {{Pkg|expac}} 并运行 {{ic|<nowiki>expac -H M '%m\t%n' | sort -h</nowiki>}}.<br />
* 以 {{ic|-c}} 参数执行 {{Pkg|pacgraph}}.<br />
<br />
查询软件包的下载大小(不加 {{ic|''packages''}} 将查询所有软件包):<br />
<br />
$ expac -S -H M '%k\t%n' ''packages''<br />
<br />
查询不属于 {{Grp|base}} 或 {{Grp|base-devel}} 的软件包,带大小和描述:<br />
<br />
$ expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <(pacman -Qqg base base-devel | sort)) | sort -n<br />
<br />
==== 按日期查询 ====<br />
<br />
用 {{Pkg|expac}} 查询最近安装的 20 个软件包:<br />
<br />
$ expac --timefmt='%Y-%m-%d %T' '%l\t%n' | sort | tail -n 20<br />
<br />
用从 epoch(1970-01-01 UTC) 开始的秒数:<br />
<br />
$ expac --timefmt=%s '%l\t%n' | sort -n | tail -n 20<br />
<br />
====查找不属于任何软件包的文件====<br />
建议定期检查 pacman 数据库之外的文件。通常这些文件是第三方程序使用一般方式安装 (例如 '''./configure; make; make install''')。下面脚本可以找出它们:<br />
{{hc|pacman-disowned|2=<br />
<nowiki><br />
#!/bin/sh<br />
<br />
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$<br />
db=$tmp/db<br />
fs=$tmp/fs<br />
<br />
mkdir "$tmp"<br />
trap 'rm -rf "$tmp"' EXIT<br />
<br />
pacman -Qlq | sort -u > "$db"<br />
<br />
find /bin /etc /lib /sbin /usr \<br />
! -name lost+found \<br />
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"<br />
<br />
comm -23 "$fs" "$db"<br />
</nowiki><br />
}}<br />
<br />
要生成列表:<br />
$ pacman-disowned > non-db.txt<br />
<br />
注意删除 {{ic|non-db.txt}} 中的文件时先仔细确认。有写是配置文件、日志等,不要删除它们。<br />
<br />
===删除孤立软件包===<br />
递归删除孤立软件包:<br />
# pacman -Rs $(pacman -Qtdq)<br />
<br />
如果没有孤立软件包,将显示错误 {{ic|error: no targets specified}}. 这个是正常的,因为 {{ic|pacman -Rns}} 没有收到任何参数.<br />
<br />
{{Note|{{ic|-Qt}} 仅显示真的孤立包,要包含可选依赖,请使用 {{ic|-Qtt}} .}}<br />
<br />
===删除base软件包组以外的所有软件包===<br />
以下命令会保留base软件包组、删除其他所有软件包:<br />
{{bc|<nowiki># pacman -Rs $(comm -23 <(pacman -Qeq|sort) <((for i in $(pacman -Qqg base); do pactree -ul $i; done)|sort -u|cut -d ' ' -f 1))</nowiki>}}<br />
<br />
来源:[https://bbs.archlinux.org/viewtopic.php?id=130176 这个帖子]<br />
<br />
注记:<br />
# {{ic|comm}}命令需要已排序的输入,否则会得到诸如“comm: file 1 is not in sorted order”之类的错误信息。<br />
# {{ic|pactree}}是生成软件包依赖树的工具,输出如下:<br />
{{hc|$ pactree -lu logrotate|<nowiki><br />
logrotate<br />
popt<br />
glibc<br />
linux-api-headers<br />
tzdata<br />
dcron cron<br />
bash<br />
readline<br />
ncurses<br />
gzip</nowiki>}}<br />
为了避免“dcron cron”(前者是软件包名,后者是该软件包提供的软件包名)这样的内容导致错误,用到了{{ic|cut -d ' ' -f 1}}——只保留软件包名称。<br />
<br />
=== 仅显示正式安装的软件包 ===<br />
<br />
pacman -Qq |grep -Fv -f <(pacman -Qqm)<br />
<br />
==安装和修复==<br />
几种获取和修复软件包的方法。<br />
<br />
===从 CD/DVD/ISO 安装软件包===<br />
<!-- could easily be adapted to work with usb sticks --><br />
*先挂载 CD (如果需要,替换''cdrom''为''dvd''或其他介质):<br />
# mount /mnt/cdrom<br />
<br />
:如果使用的是ISO映像,先在 /mnt 建立一个目录:<br />
# mkdir /mnt/iso<br />
:然后挂载镜像:<br />
# mount -t iso9660 -o ro,loop /path/to/iso /mnt/iso<br />
<br />
*配置pacman:<br />
# nano -w /etc/pacman.conf<br />
<br />
*将如下仓库信息添加到其他软件仓库(如 extra、core)之前,确保优先使用介质中的软件包:<br />
# 使用 cdrom 作为仓库<br />
[custom]<br />
Server = file:///mnt/cdrom/arch/pkg<br />
:如果使用其他介质,记得替换 ''cdrom'' 。<br />
<br />
修改{{ic|pacman.conf}}后,更新软件仓库即可。<br />
<br />
====从 Arch 的 core 镜像安装软件包====<br />
<br />
如果暂时无法链接网络(比如要配置无线网络),可以通过Arch的core仓库镜像获取软件包。先挂载之:<br />
# mount -o loop /path/to/arch_core_image/i686/repo-core-i686.sfs /mnt/iso<br />
然后修改{{ic|pacman.conf}}的{{ic|[core]}}段,(临时)替换为镜像挂载的位置:<br />
[core]<br />
#Include = /etc/pacman.d/mirrorlist<br />
Server = file:///mnt/iso<br />
然后同步:<br />
# pacman -Syu<br />
<br />
===自建本地仓库===<br />
pacman 3 引入了一个名为{{ic|repo-add}}脚本,用于帮助个人用户生成软件仓库。使用 {{ic|repo-add --help}} 查看详细用法。<br />
<br />
将所有要加入仓库的软件包放入一个目录,运行如下命令(''repo''是自建仓库的名称):<br />
$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.xz<br />
<br />
注意,{{ic|repo-add}}生成的数据库文件不一定和软件包放在同一目录,但使用pacman同步时,两者必须放在一起。<br />
<br />
向仓库添加新软件包(并移除旧的):<br />
$ repo-add /path/to/repo.db.tar.gz /path/to/packagetoadd-1.0-1-i686.pkg.tar.xz<br />
<br />
{{注意|使用{{ic|repo-remove}}删除软件包。}}<br />
<br />
本地仓库建立后,添加仓库到{{ic|pacman.conf}}。{{ic|db.tar.gz}}文件的名字就是仓库的名字,路径格式是''file://...''或FTP地址''ftp://localhost/path/to/directory''。<br />
<br />
欢迎到[[Unofficial user repositories|非官方用户软件仓库]],分享你的仓库。<br />
<br />
===在网络上共享pacman缓存===<br />
{{小贴士|另外一个方案:[http://xyne.archlinux.ca/projects/pacserve/ pacserve]。}}<br />
<br />
要在多机间共享软件包,使用任何网络协议共享{{ic|/var/cache/pacman/}}目录即可。本节介绍如何使用shfs或sshfs,在局域网内的多机间分享软件包及相关库文件目录。注意,网络间共享可能速度缓慢,取决于所选文件系统等因素。<br />
<br />
首先,在服务器安装任意网络文件系统:[[SSHFS]],[[shfs]],[[ftpfs]],[[smbfs]]或[[NFS]]。<br />
{{小贴士|使用sshfs或shfs前,先阅读[[Using SSH Keys]]。}}<br />
<br />
然后,挂载服务器的{{ic|/var/cache/pacman/pkg}}到客户端机器上的{{ic|/var/cache/pacman/pkg}}目录即可。<br />
<br />
要分享软件包数据,使用同样方法共享{{ic|<nowiki>/var/lib/pacman/sync/{core,extra,testing,community}</nowiki>}}即可。修改{{ic|/etc/fstab}}以开机自动挂载。<br />
<br />
====避免过度清理缓存====<br />
执行{{ic|pacman -Sc}}清理软件包缓存时,会删除所有当前机器上为安装的软件包。由于pacman无法判断软件包是否在其他机器上安装,这会导致移除某些还需要的软件包。<br />
<br />
避免的方法是修改清理方式为:删除所有已有新版本的过期软件包。添加以下内容到{{ic|/etc/pacman.conf}}的{{ic|[options]}}段:<br />
CleanMethod = KeepCurrent<br />
<br />
===备份和恢复已安装软件包===<br />
定期备份软件包是个好习惯。万一系统出了大问题,需要重装,就可以利用备份的软件包恢复到原先的系统。<br />
<br />
*第一步,生成系统上安装的非本地(即从官方仓库获取的)软件包列表:<br />
$ comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) > pkglist<br />
<br />
*把生成的pkglist存储在一个安全的地方,比如U盘,或者gist.github.com、evernote、dropbox之类的文本储存网站。<br />
<br />
*今后重装系统时,把pkglist复制到新系统。<br />
<br />
*使用如下命令安装所有软件包:<br />
# pacman -S $(< pkglist)<br />
<br />
要是备份的软件包列表包含非官方软件包(从AUR或其他什么地方下载的),就得使用下面这个吓人的命令了,不然pacman会出错:<br />
# pacman -S --needed $(diff <(cat badpkglist|sort) <(diff <(cat badpkglist|sort) <(pacman -Slq|sort)|grep \<|cut -f2 -d' ')|grep \<|cut -f2 -d' ')<br />
解释:<br />
* ''pacman -Slq''列出所有可以安装的软件包。由于输出是按照来源仓库排序的,需要再调用''sort''排序。<br />
* 排序是为''diff''命令比对列表做准备。<br />
* 第一个''diff''返回所有无法安装的软件包;第二个返回所有可以安装的软件包。<br />
* ''--needed''表示跳过已安装软件包。<br />
<br />
可以接着用''yaourt''恢复从AUR获取的软件包(不推荐):<br />
$ yaourt -S --noconfirm $(diff <(cat badpkglist|sort) <(pacman -Slq|sort) |grep \<|cut -f2 -d' ')<br />
<br />
最后,还可以卸载掉新系统上安装的、但之前系统并未安装的软件包。<br />
警告:务必小心使用,仔细查看pacman输出,避免悲剧。<br />
# pacman -Rsu $(diff <(cat badpkglist|sort) <(pacman -Qq|sort) | grep \>|cut -f2 -d' ')<br />
<br />
===列出所有不属于base或base-devel的已安装软件包===<br />
下列命令输出所有不属于base或base-devel软件包组的已安装软件包。这些软件包一般都是用户自己安装的:<br />
comm -23 <(pacman -Qeq|sort) <(pacman -Qgq base base-devel|sort)<br />
<br />
===重新安装所有软件包===<br />
要是你的系统遭到了大规模破坏(比如{{ic|rm -rf}}什么的),可以通过pacman重新安装所有软件包来挽救。<br />
<br />
如果没有安装外来软件包(比如来自AUR的),使用如下命令即可:<br />
# pacman -Qeq | pacman -S -<br />
# pacman -Qdq | pacman -S --asdeps -<br />
<br />
如果安装了外来软件包,使用上面的命令会出错。下面的命令先生成所有软件包列表,再用{{ic|pacman -Qmq}}剔除外来软件包,即重新安装所有仓库中可以找到的软件包,同时保留依赖安装、手动安装标志:<br />
# comm -23 <(pacman -Qeq) <(pacman -Qmq) | pacman -S -<br />
# comm -23 <(pacman -Qdq) <(pacman -Qmq) | pacman -S --asdeps -<br />
<br />
===从已有安装修复 USB 系统===<br />
如果你有一个Arch安装在U盘上,不小心搞坏了(比如,写入U盘时断电了),可以使用主机上的Arch修复U盘上的Arch(假设U盘挂载在/newarch):<br />
# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman<br />
<br />
===解压缩软件包===<br />
Arch软件包其实就是普通的xz压缩包,解压方法没啥特别的:<br />
$ tar -Jxvf package.tar.xz<br />
<br />
== 性能 ==<br />
<br />
=== 加快下载速度 ===<br />
<br />
{{注意|如果你的包下载速度变得极慢,首先确定你用的是那些([[mirrors (简体中文)|镜像]])网站而不是ftp.archlinux.org,因为后者[https://www.archlinux.org/news/302/ 从2007年3月开始限速]。}}<br />
<br />
可以通过各种下载工具而不是Pacman内置的下载方式,来改善Pacman的下载速度。<br />
<br />
不论怎样,在做任何修改前,你必须确定拥有了最新版的Pacman:<br />
<br />
# pacman -Syu<br />
<br />
==== 使用 Powerpill ====<br />
Powerpill 是 Pacman 的完整包裹程序,增加了平行下载和分段下载功能,加速下载过程。Pacman 一次只下载一个软件包,完成后才开始下一个下载。 Powerpill 同时下载多个软件包。[[Powerpill|Powerpill wiki 页面]]提供了基本的配置和使用方法。<br />
<br />
==== 使用wget ====<br />
<br />
对于需要更强大代理支持的用户来说,用wget比用Pacman自己的下载方式更加方便。<br />
<br />
要使用 {{ic|wget}},首先使用{{ic|pacman -S wget}}安装它,然后修改{{ic|/etc/pacman.conf}}并在其中的{{ic|[options]}}区段将下面内容去掉注释:<br />
<br />
{{bc|1=XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u}}<br />
<br />
除了将{{ic|wget}}参数放在{{ic|/etc/pacman.conf}}里,你也可以直接修改{{ic|wget}}配置文件(全局文件是{{ic|/etc/wgetrc}},各个用户的文件是{{ic|$HOME/.wgetrc}})。<br />
<br />
=== 使用aria2 ===<br />
<br />
[[aria2]]是一个具有断点续传和分块下载功能的轻量级下载软件,支持HTTP/HTTPS/FTP协议。[http://aria2.sourceforge.net/ aria2]可以多线程通过HTTP/HTTPS和FTP协议连接镜像服务器,显著提高下载速度。<br />
<br />
{{注意|在Pacman的XferCommand使用 aria2c '''不会'''导致并行下载多个包。因为Pacman调用XferCommand时是一次一个包调用的,等待下载完成才会启动下一个。想要并行下载多个包,参见下面的 [[#使用 Powerpill|powerpill-light]] 部分。}}<br />
<br />
===== 安装 =====<br />
通过{{ic|pacman -S aria2}}安装{{pkg|aria2}}。<br />
<br />
===== 配置 =====<br />
修改{{ic|/etc/pacman.conf}},在{{ic|[option]}}段添加下列一行(如果已存在则修改之):<br />
<br />
{{bc|1=XferCommand = /usr/bin/aria2c --allow-overwrite=true -c --file-allocation=none --log-level=error -m2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf --remote-time=true --summary-interval=60 -t5 -d / -o %o %u}}<br />
<br />
==== 参数细节 =====<br />
<br />
; {{Ic|/usr/bin/aria2c}}: aria2主程序的完整路径。<br />
; {{Ic|1=--allow-overwrite=true}}: 如果相应的控制文件不存在则重新下载。(默认值:false)<br />
; {{Ic|-c, --continue}}: 如果相应的控制文件存在则继续未完成的下载。<br />
; {{Ic|1=--file-allocation=none}}: 下载开始前预设空间。(默认值: prealloc) <b><sup>1</sup></b><br />
; {{Ic|1=--log-level=error}}: 设置错误输出级别。 (默认值: debug)<br />
; {{Ic|1=-m2, --max-tries=2}}: 从每个镜像源下载特定文件的最大尝试次数设为2。 (默认值: 5)<br />
; {{Ic|1=--max-connection-per-server=2}}: 下载每个文件时到每个镜像源的最大连接数设为2。(默认值: 1)<br />
; {{Ic|1=--max-file-not-found=5}}: 如果5次尝试后仍未下载完成1字节则强制停止。(默认值: 0)<br />
; {{Ic|1=--min-split-size=5M}}: 只有当文件大于5MB时才分割下载。 (默认值: 20M)<br />
; {{Ic|--no-conf}}: 不加载 {{ic|aria2.conf}} 。 (默认值: {{ic|~/.aria2/aria2.conf}})<br />
; {{Ic|1=--remote-time=true}}: 对远程文件应用时间戳并应用到本地文件。 (默认值: false)<br />
; {{Ic|1=--summary-interval=60}}: 每60s显式一次下载总进度。 (默认值: 60) <b><sup>2</sup></b><br />
; {{Ic|1=-t5, --timeout=5}}: 对镜像源的连接建立后5s超时。 (默认值: 60)<br />
; {{Ic|-d, --dir}}: 由 [[pacman]] 设定的文件下载目录。<br />
; {{Ic|-o, --output}}: 输出的下载文件的文件名<br />
; {{Ic|%o}}: 代表 pacman 指定的文件名的变量<br />
; {{Ic|%u}}: 代表 pacman 指定的 URL 的变量<br />
<br />
===== 其他解释 =====<br />
<br />
; <sup>1</sup> {{Ic|1=--file-allocation=falloc}}: 对较新的文件系统建议使用,如 ext4(支持extents)、 btrfs 和 xfs 因为它们存储大文件(GB级别)时速度很快。 较老的文件系统如ext3则不要使用falloc,因为prealloc消耗的时间几乎和标准分配相同,同时会锁定aria2进程而停止下载。<br />
<br />
;<sup>2</sup> {{Ic|1=--summary-interval=0}}: 减少下载总进度的输出并有可能改善性能。日志会按照 {{Ic|log-level}} 选项的设置继续输出。<br />
<br />
==== 使用其它程序 ====<br />
<br />
这里还有一些可以和Pacman协同工作的下载软件。下面列举了它们对应的XferCommand命令写法:<br />
<br />
* {{ic|snarf}}: {{ic|1=XferCommand = /usr/bin/snarf -N %u}}<br />
* {{ic|lftp}}: {{ic|1=XferCommand = /usr/bin/lftp -c pget %u}}<br />
* {{ic|axel}}: {{ic|1=XferCommand = /usr/bin/axel -n 2 -v -a -o %o %u}}<br />
<br />
== 工具 ==<br />
<br />
* {{App|Lostfiles|Script that identifies files not owned by any package.|https://github.com/graysky2/lostfiles|{{Pkg|lostfiles}}}}<br />
* {{App|Pacmatic|Pacman wrapper to check Arch News before upgrading, avoid partial upgrades, and warn about configuration file changes.|http://kmkeen.com/pacmatic|{{Pkg|pacmatic}}}}<br />
* {{App|pacutils|Helper library for libalpm based programs.|https://github.com/andrewgregory/pacutils|{{Pkg|pacutils}}}}<br />
* {{App|[[pkgfile]]|Tool that finds what package owns a file.|http://github.com/falconindy/pkgfile|{{Pkg|pkgfile}}}}<br />
* {{App|pkgtools|Collection of scripts for Arch Linux packages.|https://github.com/Daenyth/pkgtools|{{AUR|pkgtools}}}}<br />
* {{App|repoctl|Tool to help manage local repositories.|https://github.com/cassava/repoctl|{{AUR|repoctl}}}}<br />
* {{App|repose|An Arch Linux repository building tool.|https://github.com/vodik/repose|{{Pkg|repose}}}}<br />
* {{App|[[Snapper#Wrapping_pacman_transactions_in_snapshots|snap-pac]]|Make pacman automatically use snapper to create pre/post snapshots like openSUSE's YaST.|https://github.com/wesbarnett/snap-pac|{{pkg|snap-pac}}}}<br />
<br />
=== 图形前端 ===<br />
<br />
{{Warning|1=Some front-ends such as {{AUR|octopi}} [https://github.com/aarnt/octopi/issues/134#issuecomment-142099266] perform [[partial upgrade]]s periodically.}}<br />
<br />
* {{App|Arch-Update| Update indicator for Gnome-Shell.|https://github.com/RaphaelRochet/arch-update|{{AUR|gnome-shell-extension-arch-update}}}}<br />
* {{App|Arch-Update-Notifier| Update indicator for KDE.|https://github.com/I-Dream-in-Code/kde-arch-update-plasmoid|{{AUR|plasma5-applets-kde-arch-update-notifier-git}}}}<br />
* {{App|Discover|A collection of package management tools for KDE, using PackageKit.|https://projects.kde.org/projects/kde/workspace/discover|{{Pkg|discover}}}}<br />
* {{App|GNOME packagekit|GTK based package management tool|http://www.freedesktop.org/software/PackageKit/|{{Pkg|gnome-packagekit}}}}<br />
* {{App|GNOME Software|Gnome Software App. (Curated selection for GNOME)|https://wiki.gnome.org/Apps/Software|{{pkg|gnome-software}}}}<br />
* {{App|kalu|A small application that will add an icon to your systray and sit there, regularly checking if there's anything new for you to upgrade.|https://jjacky.com/kalu/|{{aur|kalu}}}}<br />
* {{App|pamac|A DBus daemon and Gtk3 frontend for libalpm written in Vala.|https://github.com/manjaro/pamac/|{{AUR|pamac-aur}}}}<br />
* {{App|pcurses|Package management in a curses frontend|https://github.com/schuay/pcurses|{{Pkg|pcurses}}}}<br />
* {{App|tkPacman|Depends only on Tcl/Tk and X11, and interacts with the package database via the CLI of ''pacman''.|http://sourceforge.net/projects/tkpacman|{{AUR|tkpacman}}}}</div>
Lanthora