创建android下repo的mirror镜像然后内网访问

本文详细介绍了如何搭建Android源码的Git镜像服务器,包括Git服务器的配置、使用代理绕过防火墙的方法、创建镜像的具体步骤及权限设置等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
(2011-02-07 19:48)

repo init -u git://10.0.67.68/android/platform/manifest.git --repo-url=git://10.0.67.68/android/tools/repo.git

在.repo/manifest.xml加入kernel
<manifest>
<project path="kernel" name="kernel/common"/>
</manifest>
还需要加入具体的revision号(也可以是hash id或者是固定的tags号revision="refs/tags/android-2.2_r1.3")
<project path="kernel" name="kernel/common" revision="android-2.6.38" />
或者
<project path="kernel" name="kernel/common" revision="archive/android-2.6.32" />
否则repo sync时将会提示如下错误
Fetching projects: 100% (171/171), done.
Syncing work tree: 66% (113/171) error: revision master in kernel/common not found



Creating an Android Mirror
1. Prerequisites/Assumptions
install repo git http://sites.google.com/a/android.com/opensource/download
Git工具使用和安装git服务器即git-daemon配置git://localhost/test.git匿名下载服务器
2.Setting up a Git Server
a.sudo apt-get install git-daemon
b.change iptables, git-daemon use tcp port 9481
sudo /sbin/iptables -A INPUT -p tcp -m tcp --dport 9481 -j ACCEPT
c.config /etc/sv/git-daemon/run, to export git trees in "/opt/coderepo"
====================================================
#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec git-daemon --verbose --export-all --base-path=/opt/coderepo /opt/coderepo
====================================================

restart git-daemon: sudo /etc/init.d/git-daemon retart

d.git-dameon log file: /var/log/git-daemon/current
3. Using Git Behind a Firewall
install corkscrew http://www.agroman.net/corkscrew
create a new file called "git-proxy.sh" with following contents and replace <proxy-name> and <proxy-port>
==================================================
#!/bin/sh
exec /usr/bin/corkscew <proxy-name> <proxy-port> $*
==================================================
chmod a+x git-proxy.sh
git config --global core.gitproxy '<path to proxy>/git-proxy.sh'

to configure git to only use the proxy for specific URLs
git config --global core.gitproxy '"<path to proxy>/git-proxy.sh" for kernel.org' 'for kernel.org$'
4. Create the mirror.
mkdir /opt/coderepo/myandroid
cd /opt/coderepo/myandroid
repo init -u git://android.git.kernel.org/platform/manifest.git --mirror
repo sync
5.change manifest.git config, if not , can not push code change
cd /opt/coderepo/myandroid/platform/manifest.git
edit config file, add following lines
[daemon]
uploadpack=true
uploadarch=true
receivepack=true
因为我按照如上方法完成之后git push时仍然出现如下问题
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 312 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
error: unpack failed: unpack-objects abnormal exit
To git://10.0.67.68/android/platform/manifest.git
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'git://10.0.67.68/android/platform/manifest.git'
那么最简答的解决办法就是将上面的设置去掉恢复到android默认的所有内容
然后修改权限让其他组用户可以写你的git仓库
luther@gliethttp:/vobs/git_repos/android-pub-mirror$ sudo chmod o+w -R platform/manifest.git
这样之后就可以正常的git push了[luther.gliethttp]

6. change manifest.git
其实直接git clone git://10.0.67.68/android/platform/manifest.git然后git push即可[luther.gliethttp]
a.clone manifest.git
cd ~
git clone git://android.git.kernel.org/platform/manifest.git

b.Edit the file "~/manifest.git/default.xml"
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="korg"
- fetch="git://android.git.kernel.org/"
+ fetch="git://<your local ip>/myandroid/"
review="review.source.android.com" />
<default revision="master"
remote="korg" />

c. commit and push this change.
git commit -a
git push git://<your local ip>/myandroid/platform/manifest.git
7. The setup of the mirror is now complete. make a test
cd ~
mkdir testmirror
repo init -u git://<you local ip>/myandroid/platform/manifest.git
repo sync

8.References
http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html
http://sites.google.com/a/android.com/opensource/download
http://sites.google.com/a/android.com/opensource/download/using-repo

repo mirror允许上传:
repo forall -c 'git config receive.denyNonFastForwards True'
repo forall -c 'git config daemon.uploadpack true'
repo forall -c 'git config daemon.uploadarch true'
repo forall -c 'git config daemon.receivepack true'

### 下载并部署 hf-mirror 上的 unsloth 大模型 #### 设置环境变量 在下载模型前,需配置 `HF_ENDPOINT` 环境变量指向 hf-mirror 的地址。可以通过以下命令完成设置: ```bash export HF_ENDPOINT=https://hf-mirror.com ``` 此操作会将 Hugging Face 默认的 API 地址替换为国内镜像站点[^3]。 #### 使用 Python 脚本下载模型 为了实现自动化下载过程,可利用 `huggingface_hub` 库中的 `snapshot_download` 函数来获取指定的大模型文件。以下是具体代码示例: ```python import os from huggingface_hub import snapshot_download # 设置镜像 endpoint os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com' # 定义本地保存路径和目标模型 ID model_path = "/path/to/local/directory" repo_id = "unsloth/large-model" # 执行下载任务 snapshot_download( repo_id=repo_id, local_dir=model_path, max_workers=8 # 可调整并发线程数以优化速度 ) ``` 上述脚本通过设定 `max_workers` 参数提升多线程下载效率,并将模型存入自定义目录下[^4]。 #### 将模型迁移到内网环境 (unslothh) 1. **打包已下载的模型**: 在外网环境下完成模型下载后,建议将其压缩成 `.tar.gz` 或其他归档格式以便传输。 ```bash tar -czvf unsloth_model.tar.gz /path/to/local/directory/* ``` 2. **上传至内网服务器**: 利用 SCP、FTP 工具或者物理介质(U盘等),把归档包转移到内网机器上。 3. **解压与加载模型**: 解开归档包并将内容放置于适合的位置供后续调用。 ```bash mkdir -p /mnt/models/unsloth/ tar -xzvf unsloth_model.tar.gz -C /mnt/models/unsloth/ ``` 4. **修改运行环境配置**: 如果 unslothh 是独立框架,则可能需要更新其资源配置文件或初始化脚本来指明新模型的具体位置。 --- #### 注意事项 - 若涉及敏感数据处理,请确认访问令牌的安全管理方式[^1]。 - 对于超大规模模型,考虑分批次迁移策略减少单次网络负载压力。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值