nexus3 をインストールしてプライベート Maven ウェアハウスを構築する
docker に nexus3 をインストールします。デフォルトで docker がインストールされます。
インストール(これを使用することをお勧めします)
#创建docker卷
docker volume create --name nexus-data
#安装
docker run --restart=always -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3
またはこのようにインストールします
# 或者 指定CONTEXT(没必要,后面nginx可以转)
docker run -d -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus sonatype/nexus3
# 或者 映射物理机目录
mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
docker run --restart=always -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
# 或者 指定内存,兼容内存小的电脑,可以限制到1024
docker volume create --name nexus-data
docker run --restart=always -d -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus -e INSTALL4J_ADD_VM_PARAMS="-Xms1024m -Xmx1024m -XX:MaxDirectMemorySize=1024m -Djava.util.prefs.userRoot=/some-other-dir" -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
nexus3の使用
ブラウザを開きます: http://address:8081/
最初のログイン:
アカウント: 管理者
パスワード: コンテナ ( docker exec -it nexus bash
) を入力し、コマンド ( cat /nexus-data/admin.password
) を入力して表示します
[設定] をクリックしてユーザーを作成します。
倉庫の作成
管理者アカウントからログアウトし、作成したばかりのユーザーに切り替えて
、Create Warehouse をクリックします。
コードをリポジトリに送信する
独自のウェアハウスを含むように maven-public ウェアハウスを設定する
Maven または Gradle で、独自の倉庫アドレスを設定します
拡大
Nginx が https 証明書のリバース プロキシ ネクサスを追加
IPがドメイン名にバインドされたら、https証明書を申請し、証明書をnginxの下に置きます.nginxの構成は次のとおりです.
upstream nexus-server{
server 127.0.0.1:8081;
}
server {
listen 80;
server_name xx.xx;
location / {
return 301 https://xx.xx;
}
location ~ /.well-known {
root /tmp;
}
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
ssl_session_timeout 5m;
client_max_body_size 50m; #文件大小限制,默认1m
location /nexus {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto "https";
proxy_pass http://nexus-server/nexus;
}
location /repository {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto "https";
proxy_pass http://nexus-server/nexus/repository/maven-public/;
}
}
注: location の値は、作成時のコンテキストと等しくなければなりません。例: ロケーション /nexus を作成する場合: NEXUS_CONTEXT=nexus