Linux build Nexus private server

1. Use Docker to build Nexus private server

1. Install Nexus

1.1 Create a location to store data

# 进入自己指定存放目录
cd /usr/local/src

# 创建个文件夹
mkdir nexus

# 赋予权限,不然启动会报错,无操作权限
chmod 777 nexus

1.2 start

  1. Execute the following command, the image will be automatically pulled and started
docker run -d -p 8081:8081 --name nexus -v /srv/nexus-data:/nexus-data --restart=always sonatype/nexus3
  1. By docker logs -f nexuschecking the startup log, when it appears Started Sonatype Nexus OSSthat the startup is successful
  2. At this time, http://ip:8081you can access it through
  3. Click on the upper right corner Sign into log in, the account number is admin, and the password needs to be viewed in the mirror, as follows:
# 进入镜像
docker exec -it nexus bash
# 查看密码,路径在登录框会提示,然后复制即可,登录成功后会让你修改密码
cat /nexus-data/admin-password

2. Nexus Warehouse

  • Nexus has four warehouses and four warehouse types
warehouse name describe
maven-central The maven central library, by default pulls the jar from https://repo1.maven.org/maven2/
maven-releases Private library distribution jar
maven-snapshots Private library snapshot (debug version) jar
maven-public Warehouse grouping, combine the above three warehouses together to provide external services, and use it in the local maven basic configuration settings.xml
type describe
group (warehouse group type) A repository for developers to set up themselves
hosted (host type) The release warehouse of internal projects (internal developers, warehouses that are released and stored)
proxy (proxy type) Find the warehouse of the data from the remote central warehouse (you can click the Configuration tab of the corresponding warehouse, and the value of the Remote Storage Location attribute is the path of the remote warehouse being proxied)
virtual (virtual type) Virtual warehouse (this is basically not used, focus on the use of the above three warehouses)

3. use

maven project pom file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.zhang</groupId>
 <artifactId>demo</artifactId>
 <version>1.0</version>
 <name>demo</name>
 <description>Demo project for Spring Boot</description>

 <distributionManagement>
  <repository>
   <!--ID可以随便写,但是要与maven的setting文件中一致-->
   <id>releases</id>
   <!--指向仓库类型为hosted(宿主仓库)的储存类型为Release的仓库---->
   <url>http://你nexus仓库的IP:8081/repository/maven-releases/</url>
  </repository>
 </distributionManagement>

 <properties>
  <java.version>1.8</java.version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
     <source>1.8</source>
     <target>1.8</target>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
   </plugin>
  </plugins>
 </build>
</project>

maven's settings.xml file

<?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\maven\repository</localRepository>

  <!-- 发布私服账号密码验证 -->
  <servers>
	<server>
		<id>releases</id><!--对应项目pom文件中设置的-->
		<username>admin</username>
		<password>admin123456</password>
	</server>
	<server>
		<id>snapshots</id><!--对应项目pom文件中设置的-->
		<username>admin</username>
		<password>admin123456</password>
	</server>
  </servers>

  <!-- 相关私服地址 -->
  <mirrors>
	<mirror>
		<id>mynexus</id>
		<name>myself nexus repository</name>
		<url>http://你nexus仓库的IP:8081/repository/maven-public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
	<mirror>
		<id>AliMaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
    </mirror>
	<mirror>
		<id>jboossMaven</id>
		<name>jbooss maven</name>
		<url>http://repository.jboss.com/maven2/</url>
		<mirrorOf>central</mirrorOf>
    </mirror>
	<mirror>
		<id>apacheMaven</id>
		<name>apache maven</name>
		<url>http://repo.maven.apache.org/maven2/</url>
		<mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
</settings>

Reprint: https://www.jb51.net/article/171427.htm

  • Question: Maven private servers cannot be deployed repeatedly
# 报错信息
Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases.
  • Solution:
    After investigation, it was found that it was caused by repeated releases. The maven private warehouse does not allow repeated deployments by default.
    Log in to the nexus management interface with the browser –> Settings icon –> Repository –> Repositories –> maven-releases –> Hosted –> Please select the 'Allow redeploy' policy, the default is the disable policy, and then save.

2. Compressed package to install Nexus

1. The latest download address of the compressed package:

https://help.sonatype.com/repomanager3/product-information/download

2. Upload to the specified directory through ftp, decompress

# 进去压缩包存放目录
cd /home/nexus
# 解压命令
tar -zxvf nexus-3.38.0-01-unix.tar.gz

3. Enter the decompressed bin directory and run

# 进入解压目录
cd nexus-3.38.0-01/
# 创建收集日志文件
touch my-nexus.log
# 进入bin目录
cd bin/
# 启动命令
./nexus run >> ../my-nexus.log
或者
./nexus start >> ../my-nexus.log

4. Configuration file storage path

# 默认配置存放路径
/etc/nexus-default.properties

# 默认密码存放路径
sonatype-work/nexus3/admin.password
  • Problem: Nexus3 uses root reportWARNING: Detected execution as "root" user. This is NOT recommended!
  • Solution:
1:在bin目录下的nexus.rc文件添加:
vim nexus.rc 加入run_as_user=root

2:或者加入系统变量
vim /etc/profile 加入export RUN_AS_USER=root

3:vim nexus,里面有一句:run_as_root=true ,原来是此处直接给拦死了,故只要改成run_as_root=false 就可以。

4:或者添加nexus用户,即:
useradd nexus
chown -R nexus:nexus /opt/nexus
然后su nexus 执行:./nexus start 就成功了。

Guess you like

Origin blog.csdn.net/qq_40406380/article/details/123336804