1 tar xf jdk.tar.gz -C /opt/export
1 # vim /etc/profile 2 export JAVA_HOME=/opt/export/jdk 3 export PATH=$JAVA_HOME/bin:$PATH 4 export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar 5 export RUN_AS_USER=root # 后边启动nexus须要 6 7 # source /etc/profile
1 # java -version 2 java version "1.7.0_80" 3 Java(TM) SE Runtime Environment (build 1.7.0_80-b15) 4 Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
下载地址:html
https://www.sonatype.com/download-oss-sonatype
https://help.sonatype.com/repomanager2/download/download-archives---repository-manager-ossjava
1 cd /opt 2 tar xf nexus-2.4.0-09-bundle.tar.gz
解压后有两个目录:linux
1 $ ls /opt/ 2 nexus-2.4.0-09 sonatype-work
更改目录名称:git
1 mv nexus-2.4.0-09 nexus
默认端口为8081,可根据须要修改:github
1 $ vim /opt/nexus/conf/nexus.properties 2 # Jetty section 3 application-port=8081 # 修改成10890 4 application-host=0.0.0.0 5 nexus-webapp=${bundleBasedir}/nexus 6 nexus-webapp-context-path=/nexus 7 8 # Nexus section 9 nexus-work=${bundleBasedir}/../sonatype-work/nexus 10 runtime=${bundleBasedir}/nexus/WEB-INF
1 /etc/init.d/iptables stop 2 chkconfig iptables off
1 $ /opt/nexus/bin/jsw/linux-x86-64/nexus start 2 **************************************** 3 WARNING - NOT RECOMMENDED TO RUN AS ROOT 4 **************************************** 5 Starting Nexus OSS... 6 Started Nexus OSS.
若是没有配置环境变量RUN_AS_USER=root,会报错:web
1 # /opt/nexus/bin/jsw/linux-x86-64/nexus start 2 **************************************** 3 WARNING - NOT RECOMMENDED TO RUN AS ROOT 4 **************************************** 5 If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
1 http://ip地址:8081/nexus 2 登陆,默认用户名 admin 默认密码 admin123
访问登陆:apache
若是想要将nexus仓库迁移,只须要打包此目录,迁移到新nexus主机:vim
1 $ du -sh /opt/sonatype-work/nexus/storage 2 47G /opt/sonatype-work/nexus/storage/
因为文件过大,可采用rsync的方式。浏览器
本文参考:http://www.javashuo.com/article/p-wqroehgi-mh.html缓存
描述:因为nexus进程会由于某些缘由挂掉,为了避免影响使用,决定作nexus高可用。
准备:根据上一章,准备两台服务器搭建nexus,主:192.168.51.204 maven01,备:192.168.51.207 maven02:
主:
1 # cat /etc/keepalived/keepalived.conf 2 ! Configuration File for keepalived 3 4 global_defs { 5 router_id maven01 6 } 7 vrrp_script chk_http_port { #检测nexus端口是否存在,不存在进行vip漂移 8 script "</dev/tcp/127.0.0.1/10890" 9 interval 1 10 weight -30 11 fall 1 12 rise 1 13 } 14 vrrp_instance VI_1 { 15 state MASTER 16 interface eth0 17 virtual_router_id 88 18 priority 150 19 advert_int 1 20 authentication { 21 auth_type PASS 22 auth_pass 1111 23 } 24 virtual_ipaddress { 25 192.168.51.210 26 } 27 track_script { 28 chk_http_port 29 } 30 }
备:
1 # cat /etc/keepalived/keepalived.conf 2 ! Configuration File for keepalived 3 4 global_defs { 5 router_id maven01 6 } 7 vrrp_script chk_http_port { 8 script "</dev/tcp/127.0.0.1/10890" 9 interval 1 10 weight -30 11 fall 1 12 rise 1 13 } 14 vrrp_instance VI_1 { 15 state MASTER 16 interface eth0 17 virtual_router_id 88 18 priority 100 19 advert_int 1 20 authentication { 21 auth_type PASS 22 auth_pass 1111 23 } 24 virtual_ipaddress { 25 192.168.51.210 26 } 27 track_script { 28 chk_http_port 29 } 30 }
描述:对比同步数据方式,1⃣️定时任务rsync同步:不及时,容易遗漏数据。2⃣️nfs共享:可以解决数据一致问题,可是主一旦宕机,备库起不到任何做用。3⃣️sersync或者inotify+rsync:能够实现实时同步,最后选用inotify方式。
安装rsync软件
1 yum install -y rsync
编写配置文件
1 $ cat /etc/rsyncd.conf 2 #created by yjn at 2018 3 4 uid = rsync 5 gid = rsync 6 use chroot = no 7 max connections = 10 8 strict modes = yes 9 pid file = /var/run/rsyncd.pid 10 lock file = /var/run/rsync.lock 11 log file = /var/log/rsyncd.log 12 13 [nexus] 14 path = /opt/sonatype-work/nexus/storage 15 comment = "nexus backup dir" 16 ignore errors 17 read only = no 18 write only = no 19 hosts allow = 192.168.0.0/16 20 auth users = rsync_backup 21 secrets file = /etc/rsync.password
建立备份目录的管理用户
1 useradd -s /sbin/nologin -M rsync
建立安全认证文件
1 echo "rsync_backup:123" >/etc/rsync.password 2 chmod 600 /etc/rsync.password
修改备份目录属主
1 chown -R rsync.rsync /opt/sonatype-work/nexus/storage
启动rsync服务
1 rsync --daemon 2 说明:rsync服务的端口号为873端口(tcp)
安装rsync软件
1 yum install -y rsync
建立安全认证文件
1 echo "123" >/etc/rsync.password 2 chmod 600 /etc/rsync.password
inotify软件的参考资料连接:https://github.com/rvoicilas/inotify-tools/wiki
1 # yum install -y inotify-tools 2 Loaded plugins: fastestmirror, security 3 Setting up Install Process 4 Loading mirror speeds from cached hostfile 5 * base: mirrors.zju.edu.cn 6 * extras: mirror.bit.edu.cn 7 * updates: mirrors.tuna.tsinghua.edu.cn 8 No package inotify-tools available. 9 Error: Nothing to do
没有这个包,更新epel源:
1 yum install -y epel-release && yum update
#!/bin/bash ########### inotifywait -mrq /opt/sonatype-work/nexus/storage --format '%w%f' -e create,delete,close_write,moved_to|\ while read line do rsync -az --delete /opt/sonatype-work/nexus/storage/* rsync_backup@192.168.51.207::nexus --password-file=/etc/rsync.password &>/dev/null done
1 sh /yjn/scripts/backup.sh &
1 Failed to watch /opt/sonatype-work/nexus/storage; upper limit on inotify watches reached! 2 Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.
注意:inotify默认监控同步文件的个数是有限制的,8192,经过配置文件/proc/sys/fs/inotify/max_user_watches能够调整监控的个数。此问题明显就是文件太多,致使没法监控。
1 echo 8192000 > /proc/sys/fs/inotify/max_user_watches
此时再执行脚本,没有报错信息,验证能够同步。
转自 http://www.javashuo.com/article/p-hpykvysy-m.html
--------
一 前提准备
1 maven环境 3.5+,java环境 1.8+。
##maven环境变量
M2_HOME ##建立maven环境变量
F:\Mysoft\maven\apache-maven-3.5.2-bin\apache-maven-3.5.2 ##安装路径 bin文件夹父目录
%M2_HOME%\bin; ##加入path
2 安装好nexus3 window安装nexus(maven私服)
二 实现目标
1 配置maven本地仓库
2 配置远程仓库
名称 类型 做用
仓库组(group) maven2-group 虚拟仓库组,用于集中管理仓库
第三方依赖仓库(3dr) maven2-hosted 本地仓库,用于管理公网无资源的第三方jar,例如oracle驱动
稳定发行仓库(releases) maven2-hosted 本地仓库,用于管理稳定发行的jar
内测快照仓库(snapshots) maven2-hosted 本地仓库,用于管理内测发行的jar
代理中央仓库(proxy) maven2-proxy 代理中央仓库,用于指定公网仓库地址,例如指定阿里云maven中央仓库
3 配置使用maven私服,以及发布下载jar
三 架构图
一、结构图
如图:为maven-nexus-proxymaven的交互架构图
蓝色虚线为使用外网代理私服的路线
红色虚线为使用内网资源转移下载路线
##外网
maven本地仓库 指定本地位置缓存下载的jar 默认为官方中央仓库 可配置为私服代理(阿里私服)
nexus私服仓库 经过代理仓库下载缓存jar 提供给局域网内各个maven资源
maven本地仓库 能够经过发布jar到nexus私服进行管理 提供给其余用户使用
##内网
maven本地仓库 指定本地位置缓存下载的jar 必须配置私服 不然下载时超时
nexus私服仓库 经过代理仓库下载缓存jar 若是内网有穿透的机子能够使用代理,若无则要经过存储媒介在外网下载jar后 内网上传至nexus私服仓库 提供给局域网内各个maven资源
maven本地仓库 能够经过发布jar到nexus私服进行管理 提供给其余用户使用
2 部署图
##根据开发规范细分私服如上
一、3rd 私服本地库:用于存放三方包,包括oracle驱动,公司外部支持jar
二、releases 私服本地库:用于存放稳定版本的jar 内网环境下能够上传外网下载的jar
三、snapshots 私服本地库:用于存放内测版本的jar 能够设置更新策略为实时
四、proxy 私服代理库:用于存放外网中央仓库地址 内网环境下通常不存在
五、group 私服公共库:将多个库虚拟成一个库 供方便引用和管理
注意:开发上传外网资源能够存在稳定版本release库,则公司内部jar在内网中如同外网jar
开发正在开发的小版本库能够上传内测snapshot库,通常状况使用svn去管理
开发使用的公司外部jar,须要上传3rd库,以便其余用户下载
开发下载插件和依赖jar均使用公共库group便可
四 配置nexus
一、检测maven环境
mvn -v ##须要配置 JAVA_HOME,M2_HOME
二、启动nexus并登录
http://localhost:8082/ ##nexus服务ip:port 帐号密码默认 admin admin123
若是不修改默认有4个库 1个proxy,1个group,1个release和1个snapshot,3rd在低版本有 nexus3默认没有了
若是须要使用,须要按实际状况配置,一下可选为*
(1)* 配置仓库
可点击新建仓库(略)
(2)* 配置proxy
点击maven-central 进入配置
配置外网代理maven仓库,例如 http://maven.aliyun.com/nexus/content/groups/public/ 阿里云
选择缓存文件位置,默认只有一个在nexus安装路径
(3)配置maven-snapshot和maven-release
启用maven-snapshot与maven-release发布功能 (snapshot修改相同)
(4)*配置maven-public仓库
能够将现有仓库聚合
三、*配置用户
用户默认为admin,admin123
(1)* 新增一个zhangsan
五 配置maven
(若是配置在maven setting中则为全局配置 若是配置为项目pom中则为项目配置)
一、修改maven setting.xml配置
##文件坐标
F:\mysoft\apache-maven-3.5.2-bin\apache-maven-3.5.2\conf\setting.xml
关键配置
<!--maven 私服管理配置-->
<servers>
<server>
<id>maven-releases</id>
<!--保持id惟一 用于引用-->
<username>admin</username>
<password>admin123</password>
<!--这个密码就是你设置的密码-->
</server>
<server>
<id>maven-snapshots</id>
<!--保持id惟一 用于引用-->
<username>admin</username>
<password>admin123</password>
<!--这个密码就是你设置的密码-->
</server>
</servers>
详细配置(可省略)
<!--maven本地仓库配置-->
<localRepository>F:\mysoft\apache-maven-3.5.2-bin\maven_repository</localRepository>
<!--maven 私服管理配置-->
<servers>
<server>
<id>maven-releases</id>
<!--保持id惟一 用于引用-->
<username>admin</username>
<password>admin123</password>
<!--这个密码就是你设置的密码-->
</server>
<server>
<id>maven-snapshots</id>
<!--保持id惟一 用于引用-->
<username>admin</username>
<password>admin123</password>
<!--这个密码就是你设置的密码-->
</server>
</servers>
<!--如下是中央仓库配置 如同使用proxy指定下载点 再无私服公共仓库时直接到中央仓库下载-->
<mirrors>
<!--如下是默认配置,本来为注释-->
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
<!--能够新增 配置私服公共仓库 配置阿里云公共仓库-->
</mirrors>
<!--如下是通常不配置 由于项目多个状况下仍是使用pom文件配置最佳-->
<!--动态配置参数-->
<profiles>
<!--各个环境配置-->
<profile>
<id>env-test</id>
<!--省略 仓库分类指定,版本库刷新等,详见pom.xml-->
</profile>
<profile>
<id>env-dev</id>
</profile>
</profiles>
<!--激活配置参数-->
<activeProfiles>
<activeProfile>env-dev</activeProfile>
</activeProfiles>
二、修改项目pom.xml文件 (父pom便可)
(1)配置下载使用maven公共库maven-group
<!--仓库配置 如同maven 配置镜像-->
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://localhost:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<!--插件库配置 -->
<pluginRepositories>
<pluginRepository>
<id>mmaven-public</id>
<name>maven-public</name>
<url>http://localhost:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
(2)配置发布到maven本地库 maven-releases以及maven-snapshots
<!--配置仓库管理-->
<distributionManagement>
<!--设置发布稳定仓库-->
<repository>
<id>maven-releases</id>
<!--id必须与setting中对应 使用setting配置用户-->
<name>User Project Release</name>
<url>http://localhost:8082/repository/maven-releases/</url>
</repository>
<!--设置发布的快照库-->
<snapshotRepository>
<id>maven-snapshots</id>
<!--id必须与setting中对应 使用setting配置用户-->
<name>User Project SNAPSHOTS</name>
<url>http://localhost:8082/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
(3)使用profile(可省略)
<profiles>
<profile>
<id>env-dev</id>
<!--命名惟一-->
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://localhost:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://localhost:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>User Project Release</name>
<url>http://localhost:8082/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>User Project SNAPSHOTS</name>
<url>http://localhost:8082/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</profile>
<!--如下省略其余profile-->
</profiles>
六 使用(以idea为例)
(1)配置使用maven
file--》setting--》maven--》指定安装的maven
(2)使用maven工具
ctrl+shift+A 输入 maven projects 点击则右边侧边栏出现maven project管理工具
一、下载远程仓库文件
二、发布release
##
注意release版本发布 版本号必须不能以snapshot结尾
三、上传第三方文件
语法:
mvn deploy:deploy-file
-DgroupId= <group-id>\包名前缀 com.公司名
-DartifactId= <artifact-id>\包项目名 xxx项目
-Dversion= <version>\包版本号 v1.0.0.1(纯数字最佳)
-Dpackaging= <type-of-packaging>\打包类型 通常为jar
-Dfile= <path-to-file>\须要上传文件的路径
-DrepositoryId= <id-to-map-on-server-section-of-settings.xml>\serverid(setting指定)
-Durl= <url-of-the-repository-to-deploy>
例子:
mvn deploy:deploy-file -DgroupId=com.oracle
-DartifactId=jdbc -Dversion=1.0 -Dfile=ojdbc6.jar
-DrepositoryId=maven-release -Durl=http://ip:prot/repository/maven-releases/
--------------------- 版权声明:本文为CSDN博主「MarsAres」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处连接及本声明。原文连接:https://blog.csdn.net/qq_22211217/article/details/81075978