Skip to content

Commit 1a38f74

Browse files
author
扣丁禅师
committed
文件添加一些注释,删除无用文件
1 parent 1c9138f commit 1a38f74

23 files changed

+337
-316
lines changed

INSTALL.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# ZComposer 镜像的安装部署
2+
3+
```sh
4+
$ apt install beanstalkd
5+
$ cd composer-mirror
6+
$ composer install
7+
```
8+
9+
## 常用命令
10+
11+
```sh
12+
# 执行抓取任务
13+
$ php ./bin/console app:crawler
14+
15+
# 后台多进程模型同步又拍云
16+
$ php ./bin/console app:daemon
17+
18+
# 清理过期垃圾文件
19+
$ php ./bin/console app:clear --expired=json
20+
21+
# 扫描并校验所有json和zip文件的hash256
22+
$ php ./bin/console app:scan
23+
```
24+
25+
## 修改配置参数
26+
27+
> 通常根据自己部署的实际环境,修改参数。详细配置说明详见 config.default.php
28+
29+
`cp config.default.php config.php`,修改 config.php 中的如下参
30+
31+
```php
32+
/**
33+
* distdir 用于存储 zip 包
34+
*/
35+
'distdir' => __DIR__ . '/dist/',
36+
37+
/**
38+
* 指向 mirrorUrl 对应的 web 实际目录
39+
*/
40+
'cachedir' => __DIR__ . '/cache/',
41+
42+
/**
43+
* packagistUrl:官方采集源
44+
*/
45+
'packagistUrl' => 'https://packagist.org',
46+
47+
/**
48+
* 镜像包发布站点, packages.json 入口根域名
49+
*/
50+
'mirrorUrl' => 'https://packagist.laravel-china.org',
51+
52+
/**
53+
* .json 中 dist 分发 zip 包的CDN域名
54+
*/
55+
'distUrl' => 'https://dl.laravel-china.org/',
56+
```
57+
58+
### supervisor 配置
59+
60+
`sudo vim /etc/supervisor/supervisord.conf`,添加如下配置信息:
61+
62+
[program:crawler]
63+
command=php ./bin/console app:crawler
64+
directory=/home/zencodex/composer-mirror/ ;部署代码的位置,自行替换
65+
autostart=true
66+
autorestart=true
67+
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
68+
stdout_logfile_maxbytes = 10MB ; stdout 日志文件大小,默认 50MB
69+
stdout_logfile_backups = 5 ; stdout 日志文件备份数
70+
stdout_logfile = /tmp/composer_crawler_stdout.log
71+
72+
[program:composer_daemon]
73+
command=php ./bin/console app:daemon
74+
directory=/home/zencodex/composer-mirror/ ;部署代码的位置,自行替换
75+
autostart=true
76+
autorestart=true
77+
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
78+
stdout_logfile_maxbytes = 10MB ; stdout 日志文件大小,默认 50MB
79+
stdout_logfile_backups = 5 ; stdout 日志文件备份数
80+
stdout_logfile = /tmp/composer_daemon_stdout.log
81+
82+
### crontab 定时任务
83+
84+
```
85+
# sudo crontab -e
86+
# 根据自己环境代码的位置,替换 /home/zencodex/composer-mirror
87+
# getcomposer 是获取最新的 composer,上传到 CDN 云存储
88+
89+
0 */2 * * * /usr/bin/php /home/zencodex/composer-mirror/bin/console app:clear --expired=json
90+
0 1 * * * /usr/bin/php /home/zencodex/composer-mirror/getcomposer.php
91+
```
92+
93+
### 注意最大子目录数的坑
94+
95+
代码详情见 `src/Commands/PatchCommand.php`
96+
97+
```php
98+
/*
99+
|--------------------------------------------------------------------------
100+
| linux ext4 支持的最大子目录数有上限,大约 64000 ~ 65000,目前包的数量已经超过上限
101+
|--------------------------------------------------------------------------
102+
|
103+
| 有三种解决方法,前2种基本不现实。所以自己通过尝试,找到了3 (软连接不计数的方案)
104+
|
105+
| 1. 更换没有子文件夹数量限制的文件系统,比如 xfs
106+
| 2. 或者更改相关代码,重新编译 ext4 内核
107+
| 3. 切割大的文件夹,分散不同字母开头的文件。在主文件夹里面使用软连接,软连接并不计数
108+
|
109+
*/
110+
```

README.md

+81-61
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,92 @@
1-
packagist-crawler
2-
========================
3-
4-
Requirement
5-
------------------
6-
- PHP >= 5.6
7-
- ext-curl
8-
- ext-hash
9-
- ext-json
10-
- ext-zlib
11-
- ext-PDO
12-
- ext-pdo\_sqlite
13-
14-
Install
15-
------------------
16-
17-
```sh
18-
$ apt install beanstalkd
19-
$ cd packagist-crawler
20-
$ composer install
1+
ZComposer 镜像诞生于2017年3月份,至今已运行了2年多。当前是第二次重构过的代码,基本是0故障,期间发现的一些停更问题,大多也是第三方接口调用策略/频率限制调整导致的误伤,沟通后也能很快解决。
2+
3+
## 镜像的安装部署
4+
5+
如果你想独立安装及部署镜像站点,详见[INSTALL.md]
6+
7+
## 镜像的使用方法
8+
9+
> 请尽可能用比较新的 Composer 版本。
10+
11+
使用 Composer 镜像加速有两种选项:
12+
13+
- 选项一:全局配置,这样所有项目都能惠及(推荐);
14+
- 选项二:单独项目配置;
15+
16+
选项一、全局配置(推荐)
17+
18+
```shell
19+
$ composer config -g repo.packagist composer https://packagist.laravel-china.org
2120
```
2221

23-
How to use
24-
------------------
22+
选项二、单独使用
23+
24+
如果仅限当前工程使用镜像,去掉 -g 即可,如下:
25+
26+
```shell
27+
$ composer config repo.packagist composer https://packagist.laravel-china.org
28+
```
2529

26-
```sh
30+
## 遇到问题?
31+
32+
`composer` 命令后面加上 -vvv (是3个v)可以打印出调错信息,命令如下:
33+
34+
```shell
35+
$ composer -vvv create-project laravel/laravel blog
36+
$ composer -vvv require psr/log
37+
```
38+
39+
如果自己解决不了,或发现 BUG,可以在 [@扣丁禅师](https://laravel-china.org/users/12063) 的 GitHub 上 [创建 Issue](https://github.com/zencodex/composer/issues/new)
2740

28-
# 执行抓取任务
29-
$ php ./crawler.php
41+
注意提问时请带上 -vvv 的输出,并且要求叙述清晰,第一次提问的同学请阅读 [关于提问的智慧](https://laravel-china.org/topics/2396/wisdom-of-asking-questions-chinese-version)
3042

31-
# 后台多进程模型同步又拍云
32-
$ php daemon.php
43+
## 常见问题
3344

34-
# 清理过期垃圾文件
35-
$ php clearexpired.php
45+
1. 已存在 composer.lock 文件,先删除,再运行 `composer install` 重新生成。
46+
> 原因:composer.lock 缓存了之前的配置信息,从而导致新的镜像配置无效。
3647
37-
# 检测所有 json文件的 hash256
38-
$ php ./checkhash.php
48+
2. 使用 `laravel new` 命令创建工程, 这个命令会从 [这里](http://cabinet.laravel.com/latest.zip) 下一个zip包,里面自带了 composer.lock,和上面原因一样,也无法使用镜像加速,解决方法:
3949

50+
- 方法一(推荐):
51+
不使用 `laravel new`,直接用 `composer create-project laravel/laravel xxx` 新建工程。
52+
53+
- 方法二:
54+
运行 `laravel new xxx`,当看见屏幕出现 - Installing doctrine/inflector 时,`Ctrl + C` 终止命令,cd xxx 进入,删除 composer.lock,再运行 `composer install`
55+
56+
3. 缓存多久更新一次?
57+
58+
- 0时 - 早上7时,这个时间段考虑使用人数不会太频繁,间隔为15分钟
59+
- 其余时间,间隔为5分钟
60+
61+
> 正常更新速度可在1分内完成 ,但更新太快,会降低CDN命中率,如果总有新文件让CDN去缓存,反而拖慢了速度,所以故意加了些延迟。我们每次采集中还会删减掉数千个僵尸包,以加快传输速度。
62+
63+
## 安装 Composer
64+
65+
### Linux/Mac:
66+
67+
wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer
68+
chmod a+x /usr/local/bin/composer
69+
70+
如遇权限不足,可添加 `sudo`
71+
72+
### Windows:
73+
74+
1. 直接下载 composer.phar,地址:https://dl.laravel-china.org/composer.phar
75+
2. 把下载的 composer.phar 放到 PHP 安装目录
76+
3. 新建 composer.bat, 添加如下内容,并保存:
77+
78+
<pre>@php "%~dp0composer.phar" %*</pre>
79+
80+
### 查看当前版本
81+
82+
```shell
83+
$ composer -V
4084
```
4185

86+
### 升级版本
87+
88+
```shell
89+
$ composer selfupdate
90+
```
4291

43-
Configuration
44-
------------------
45-
46-
- config.default.php
47-
- config.php
48-
49-
copy config.default.php to config.php
50-
51-
supervisor config:
52-
53-
[program:crawler]
54-
command=/usr/bin/php /home/zencodex/packagist-crawler/crawer.php
55-
directory=/home/zencodex/packagist-crawler/
56-
autostart=true
57-
autorestart=true
58-
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
59-
stdout_logfile_maxbytes = 10MB ; stdout 日志文件大小,默认 50MB
60-
stdout_logfile_backups = 5 ; stdout 日志文件备份数
61-
stdout_logfile = /tmp/composer_crawler_stdout.log
62-
63-
[program:composer_daemon]
64-
command=/usr/bin/php /home/zencodex/packagist-crawler/deaemon.php
65-
directory=/home/zencodex/precache/
66-
autostart=true
67-
autorestart=true
68-
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
69-
stdout_logfile_maxbytes = 10MB ; stdout 日志文件大小,默认 50MB
70-
stdout_logfile_backups = 5 ; stdout 日志文件备份数
71-
stdout_logfile = /tmp/composer_daemon_stdout.log
72-
92+
> 注意 `selfupdate` 升级命令会连接官方服务器,速度很慢。建议直接下载我们的 `composer.phar` 镜像,每天都会更新到最新。

bin/console

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ require_once __DIR__ . '/../src/lib/init.php';
55

66
use Symfony\Component\Finder\Finder;
77
use Symfony\Component\Console\Application;
8-
use zencodex\PackagistCrawler\Commands\ClearCommand;
8+
use zencodex\ComposerMirror\Commands\ClearCommand;
99

1010
$app = new Application();
1111

1212
$finder = new Finder();
1313
$finder->files()->in(__DIR__ . '/../src/Commands');
1414
foreach ($finder as $fileObj) {
1515
$nameWithoutExtention = str_replace('.php', '', $fileObj->getFilename());
16-
$className = "zencodex\\PackagistCrawler\\Commands\\" . $nameWithoutExtention;
16+
$className = "zencodex\\ComposerMirror\\Commands\\" . $nameWithoutExtention;
1717
$app->add(new $className());
1818
}
1919

composer.json

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "zencodex/packagist-crawler",
3-
"description": "build mirror of packagist.org",
4-
"license": "CC0-1.0",
2+
"name": "zencodex/composer-mirror",
3+
"description": "mirror full packages on packagist.org, including json and dist/zip files",
4+
"license": "MIT",
55
"authors": [
66
{
7-
"name": "ZenCodex",
7+
"name": "扣丁禅师",
88
"email": "[email protected]"
99
}
1010
],
@@ -16,25 +16,17 @@
1616
"ext-json": "*",
1717
"ext-hash": "*",
1818
"ext-curl": "*",
19-
"ext-PDO": "*",
2019
"ext-zlib": "*",
21-
"ext-pdo_sqlite": "*",
2220
"symfony/finder": "^4.1",
2321
"pda/pheanstalk": "^3.1",
2422
"symfony/console": "^4.1"
2523
},
2624
"autoload": {
2725
"psr-4": {
28-
"zencodex\\PackagistCrawler\\": "src/"
26+
"zencodex\\ComposerMirror\\": "src/"
2927
}
3028
},
31-
"bin": [
32-
"parallel.php"
33-
],
3429
"scripts": {
35-
"crawl": "php crawler.php",
36-
"test": "php check.php",
37-
"compress": "tar cjf packagist.tar.bz2 cache/",
38-
"sync": "rsync -rvz --include=cache/index.php --include=vendor --exclude-from=.gitignore ./ root@linodejp:/home/zencodex/packagist-crawler/"
30+
"sync": "rsync -rvz --include=cache/index.php --include=vendor --exclude-from=.gitignore ./ root@linodejp:/home/zencodex/composer-mirror/"
3931
}
4032
}

0 commit comments

Comments
 (0)