Nexus系列:简介和安装(Windows、Linux)以及反向代理Nexus

目录

简介

Sonatype Nexus是一个Maven仓库管理器,可以节省网络带宽并加速项目搭建的进程。它可以管理jar包的仓库,包括上传和下载jar包。此外,Sonatype Nexus还可以配置其他远程maven仓库站点,作为公共maven仓库的专用代理服务器,为maven项目部署提供存储库。它可以搭建局域网maven私服仓库,实现局域网用户共享,并且支持代理广域网上的远程仓库。

官网:https://help.sonatype.com/en/sonatype-nexus-repository.html

安装

Windows

https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.30.0-01-win64.zip

输入命令 nexus.exe runnexus.exe install,前者是命令行式启动,后者是安装Nexus服务

Linux

shell 复制代码
#!/bin/bash
#需要java环境
#创建nexus源码目录
mkdir /usr/local/src/nexus
#进入nexus源码目录
cd /usr/local/src/nexus
#下载nexus压缩包
wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.30.0-01-unix.tar.gz
#创建nexus安装目录
mkdir -p /usr/local/package/
#解压nexus
tar -zxvf nexus-3.30.0-01-unix.tar.gz -C /usr/local/package
#进入包路径
cd /usr/local/package
#重命名
mv  nexus-3.30.0-01 nexus
#配置环境变量
echo "#nexus config.">>/etc/profile
echo "export NEXUS_HOME=/usr/local/package/nexus">>/etc/profile
echo 'export PATH=$PATH:${NEXUS_HOME}/bin'>>/etc/profile
#立即生效
source /etc/profile

#vim /usr/local/package/nexus/bin/nexus.rc #修改启动用户
#run_as_user=""			#内容就这一行,放开注释,填写用户即可
#vim /usr/local/package/nexus/etc/nexus-default.properties	#默认是8081
#访问http://ip:8081,登陆用户admin 密码存放在:/usr/local/nexus/sonatype-work/nexus3/admin.password 目录

#配置nexus启动用户
useradd -d "/home/nexus" -m -s "/sbin/nologin" nexus
chown -R nexus:nexus  /usr/local/package/nexus
chown -R nexus:nexus /usr/local/package/sonatype-work
echo run_as_user='"nexus"' >>/usr/local/nexus/bin/nexus.rc

#配置 nexus.service
#https://www.cnblogs.com/vitoboy/p/12657581.html init.d
#启动nexus需要依赖rpcbind
# 否则提示错误:Cannot add dependency job for unit rpcbind.socket, ignoring: Unit not found.
yum install -y rpcbind
systemctl start rpcbind.service 
cat >/etc/systemd/system/nexus.service<<EOF
[Unit]
Description=nexus
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/package/nexus/bin/nexus start
ExecStop=/usr/local/package/nexus/bin/nexus stop
User=nexus
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
#启动nexus
systemctl start nexus
#设置开启自启动
systemctl enable nexus

Nexus相关命令

  1. 启动命令:nexus start
  2. 停止命令:nexus stop
  3. 重启命令:nexus restart
  4. 安装为服务:nexus install
  5. 卸载服务:nexus uninstall

此外,还有显示设备软件版本和硬件信息的命令:show version;显示设备硬件清单的命令:show inventory;显示所有接口的状态和连接情况的命令:show interfaces status等。

命令 说明
install 安装为服务
uninstall 卸载服务
start 后台启动
stop 停止
status 状态
run 运行
run-redirect 运行重定向

Nginx反向代理Nexus

nginx 复制代码
   server {
    listen   80;
    server_name  nuget.vmcode.cn;
    client_max_body_size 1G;
    #proxy_max_temp_file_size 2G;
    location / {
      # Use IPv4 upstream address instead of DNS name to avoid attempts by nginx to use IPv6 DNS lookup
      proxy_pass http://127.0.0.1:8081/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_max_temp_file_size 0; 
      client_max_body_size    20m;
      client_body_buffer_size  128k;
      proxy_connect_timeout   90;
      proxy_send_timeout     90;
      proxy_read_timeout     90; 
      proxy_temp_file_write_size 64k;
      proxy_http_version 1.1;
      proxy_request_buffering off;
    }
  }