nexus私服搭建

搭建 nexus 私服(centos6.7)

备注:Centos 6.7 、 nexus-2.12.1-01-bundle.tar.gz 、java环境


  • 创建私有文件夹

    cd /usr/local && mkdir hy_nexus && cd hy_nexus

  • 下载nexus安装包

    wget http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz 或者 手动下载拷贝到hy_nexus中

  • 解压nexus-2.12.1-01-bundle.tar.gz

    tar -zxvf nexus-2.12.1-01-bundle.tar.gz  //解压
    mv nexus-2.12.1-01 nexus //重命名
    mv sonatype-work /usr/local/hy_nexus/nexus/nexus-work //移动sonatype-work到nexus下
    
  • 编辑nexus中conf下nexus.properties文件,配置端口和work目录信息

    vim /usr/local/hy_nexus/nexus/conf/nexus.properties
    配置端口信息如下:

    application-port=8081

    application-port=8081(可选)

    > 配置IP端口访问目录如下:
    > ```java
    #nexus-webapp-context=/nexus 如:http://ip:port/nexus  即可
     nexus-webapp-context=/(可选) 如:http://ip:port/  即可
    

    配置work目录地址,Maven仓库JAR缓存地址如下:

    nexus-work=${bundleBasedir}/../sonatype-work/nexus

    nexus-work=${bundleBasedir}/nexus-work/nexus

  • 编辑nexus文件,拷贝nexus到/etc/init.d/下,配置NEXUS_HOME/RUN_AS_USER/PIDDIR参数,设置开机启动

    vim /usr/local/hy_nexus/nexus/bin/nexus
    修改如下:

    NEXUS_HOME=".."

    NEXUS_HOME="/usr/local/hy_nexus/nexus"

    RUN_AS_USER=

    RUN_AS_USER=root

    Location of the pid file.

    PIDDIR="."

    PIDDIR="/var/run"

    添加JAVA环境

    JAVA HOME

    JAVA_HOME=/usr/java/jdk1.7.0_79
    PATH=$JAVA_HOME/bin:$PATH

    > `cp /usr/local/hy_nexus/nexus/bin/nexus /etc/init.d/ && cd /etc/init.d/ && ls`
    > 
    > `chmod 755 nexus && chkconfig nexus on && service nexus start` //设置nexus权限,设置开机启动,启动nexus服务
    > 
    > 看到以下打印信息代表安装成功:(查看nexus服务状态命令:service nexus status)
    > ```java
    ****************************************
    WARNING - NOT RECOMMENDED TO RUN AS ROOT
    ****************************************
    Starting Nexus OSS...
    Started Nexus OSS.
    
  • 注意开启8081端口

    /sbin/iptables -I INPUT -p tcp --dport 8081 -j ACCEPT
    /etc/init.d/iptables save //保存修改
    service iptables restart //重启防火墙,修改生效

  • 打开浏览器输入http://192.168.0.22:8081/回车,登录可通过admin/admin123

  • 登录私服,进行相关配置

  • 更新索引文件(由于国内网络环境不推荐使用在线自动更新),故进行手动更新,先停止nexus服务(service nexus stop

  • 手动更新索引

    • 首先到http://repo.maven.apache.org/maven2/.index/,下载nexus-maven-repository-index.gz 和 nexus-maven-repository-index.properties两个文件

    • 还需要一个jar,到http://search.maven.org 搜索框中输入g:"org.apache.maven.indexer" AND a:"indexer-cli",下载indexer-cli-5.1.1.jar文件

    • nexus-maven-repository-index.gz 和 nexus-maven-repository-index.propertiesindexer-cli-5.1.1.jar 放到同一个文件夹(/usr/local/hy_nexus/index)中,通过命令解压

      • cd /usr/local/hy_nexus/index,然后执行java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer //解压时间比较长,耐心等待

      • 执行完之后,把indexer下的所有内容都复制到/usr/local/hy_nexus/nexus/nexus-work/nexus/indexer/central-ctx下面

      • 重新启动nexus,进入管理界面,选择Views/Repositories下的Repositories,然后选中Central,在下方tab中选择Configuration,将DownloadRemoteIndexs至为true(表示允许远程下载),保存(save)

        nexus远程索引设置.png

      • 选择central->Browse Index,就看到更新的索引了。

        查看索引更新.png

  • 如果需要允许开发中的jar发布到nexus私服,提供其他开发者下载,需要配置3rd party

    选择3rd party,在下方tab中选中Configuration,将Deployment Policy设置为Allow Redeploy,然后保存(save)即可
    在开发中要发布jarnexus中还需要在pom.xml中添加以下配置:

      <distributionManagement>
          <repository>
              <id>nexus-releases</id>
              <name>Nexus Internal Releases Repository</name>
              <url>http://192.168.0.22:8081/content/repositories/releases/</url>
          </repository>
          <snapshotRepository>
              <id>nexus-snapshots</id>
              <name>Nexus Internal Snapshots Repository</name>
              <url>http://192.168.0.22:8081/content/repositories/snapshots/</url>
          </snapshotRepository>
      </distributionManagement>
    
  • 此外要能在maven中使用私服nexus,需要修改setting.xml文件,以下附上setting.xml配置:

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>D:/java_develop/apache-maven-3.3.9/respository</localRepository>
    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <servers>
    <server>
    <id>nexus-releases</id>
    <username>deployment</username>
    <password>deployment123</password>
    </server>
    <server>
    <id>nexus-snapshots</id>
    <username>deployment</username>
    <password>deployment123</password>
    </server>
    <server>
    <id>nexus-thirdparty</id>
    <username>deployment</username>
    <password>deployment123</password>
    </server>
    </servers>
    <mirrors>
    <mirror>
    <id>nexus-mirror</id>
    <mirrorOf>*</mirrorOf>
    <url>http://192.168.0.22:8081/content/groups/public/</url>
    </mirror>
    </mirrors>
    <profiles>
    <profile>
    <id>nexus-profile</id>
    <repositories>
    <repository>
    <id>nexus-repository</id>
    <url>http://nexus-mirror</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>nexus-plugin-repositorie</id>
    <url>http://nexus-mirror</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </pluginRepository>
    </pluginRepositories>
    </profile>
    </profiles>
    <activeProfiles>
    <activeProfile>nexus-profile</activeProfile>
    </activeProfiles>
    </settings>

    
    

另附上java安装步骤

  • 下载jdk安装包rpm,地址jdk1.7
  • 安装jdk

    yum -y localinstall jdk-7u79-linux-x64.rpm

  • 配置环境变量
    vim /etc/profile
    加入以下配置信息:
    export PATH=$PATH:/usr/local/bin
    export JAVA_HOME=/usr/java/jdk1.7.0_79
    export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
    export PATH=$PATH:$JAVA_HOME/bin
  • 刷新配置文件,配置生效

    source /etc/profile

  • 如果要使用jps命令,只需执行以下命令

    ln -s /usr/java/jdk1.7.0_79/bin/jps /usr/bin

  • 一切都结束了
  • 测试下吧

    java -version 如果输出jdk信息,恭喜你,成功了!

作者:逐暗者 (转载请注明出处)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,100评论 18 139
  • 下载 nexus-3.0.0-01-mac.tgz 环境配置 将解压后的nexus-3.3.0-01-mac包复制...
    PengFly阅读 886评论 0 0
  • 下载 官网下载 Nexus Repository OSS 社区版,笔者是在CentOS 7.2环境下安装的。 安装...
    adeng2016阅读 432评论 0 1
  • 人好像有个通病:喜欢等待。 小孩子望着哈根达斯冰激凌想,等我长大一定要吃好几盒;胖子看着橱窗里一件美丽的裙子想,等...
    008明瑾阅读 137评论 0 0
  • 陪伴孩子成长的路上,有很多发自肺腑的感言,想要一吐为快,更想坚持记录下来。 从今天开始,练笔,磨心,陪伴孩子,记录...
    馨向未来阅读 128评论 0 0