Nexus私服搭建

Nexus是Maven仓库管理工具,Team内部之前存在一套,但管理比较混乱,这段时间腾出手来重新搭了一套,把整个过程记录下。

下载解压

我这里出现ssl链接问题,所以加了—no-check-certificate

1
2
3
4
cd /opt/
wget --no-check-certificate https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.1-01-bundle.zip
unzip nexus-2.14.1-01-bundle.zip
ln -s nexus-2.14.1-01/ nexus
修改.bashrc文件增加环境变量
1
NEXUS_HOME="/opt/nexus"
配置为Service
1
2
3
4
ln -s $NEXUS_HOME/bin/nexus /etc/init.d/nexus
cd /etc/init.d/
sudo chkconfig --add nexus
sudo chkconfig --levels 345 nexus on
处理权限
1
2
3
4
5
6
groupadd nexus
useradd -g nexus nexus
cd /opt/
chown -R nexus:nexus nexus
chown -R nexus:nexus nexus-2.14.1-01/
chown -R nexus:nexus sonatype-work/
配置Nginx代理

Nexus默认的context path是/nexus,如果使用Nginx代理访问,
需要修改$NEXUS_HOME/conf/nexus.propertiesnexus-webapp-context-path=/nexus改为nexus-webapp-context-path=/
否则通过Nginx访问Nexus会出现登陆不了的情况。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
http {

    proxy_send_timeout 120;
    proxy_read_timeout 300;
    proxy_buffering    off;
    keepalive_timeout  5 5;
    tcp_nodelay        on;

    server {
        listen   *:80;
        server_name  repo.example.com;

        # allow large uploads of files - refer to nginx documentation
        client_max_body_size 1G;

        # optimize downloading files larger than 1G - refer to nginx doc before adjusting
        #proxy_max_temp_file_size 2G;

        location / {
            proxy_pass http://localhost: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;
        }
    }
}
启动Nexus服务,通过域名访问
1
sudo service nexus start
配置LDAP

让同学们都有各自权限来使用Nexus,但这个是麻烦SA同学帮忙配置的。需要的同学可以参考 Sonatype Nexus的LDAP配置指导书

修改settings.xml