Using nexus to build private warehouse under Centos

1, Download and install

download

Server is centos, go to https://www.sonatype.com/download-oss-sonatype Download the unix version of.

install

  • decompression
tar xvf nexus-3.21.1-01-unix.tar.gz
mv nexus-3.21.1-01 /home/nexus
  • Open port It will start on port 8081 by default, because my port 8081 has been used, use port 8082 instead.
firewall-cmd --zone=public --add-port=8082/tcp --permanent
firewall-cmd --reload
  • Create the running user of nexus
adduser nexus # Create user
passwd nexus # Change password

Add permissions to nexu users

vi /etc/sudoers
chmod u+w /etc/sudoers

Add to

nexus ALL=(ALL) ALL

Recall write permission after saving

chmod u-w /etc/sudoers

Modify the owner of the nexus directory

chown -R nexus /home/nexus

Two, operation

Modify profile

cd /home/nexus/etc/
vim nexus-default.properties

Change to

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8082
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

nexus.hazelcast.discovery.isEnabled=true

start-up

  • Function
cd /home/nexus/bin/
./nexus start #start-up
./nexus restart
./nexus stop
./nexus run

Show nexus is running to indicate that it is running.

  • Change to run user

nexus does not recommend starting with root. We run it with nexus users. Go to the bin directory of nexus Edit the following file

vi nexus.rc

Change to run as user = "nexus", and remove the previous comment symbols.

  • Add Java home to the startup file of nexus (optional)

Open the startup file of nexus in the bin directory of Nexus

Enter the following command

vi nexus

Then find the following code at the beginning, uncomment and add the jdk address

INSTALL4J_JAVA_HOME_OVERRIDE=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64

Add systemctl startup service

vi /usr/lib/systemd/system/nexus.service

Write in

[Unit] 
   Description = nexus service 
   After = network.target 
[Service] 
   Type = forking 
   LimitNOFILE = 65536 
   ExecStart = /home/nexus/bin/nexus start 
   ExecReload= //home/nexus/bin/nexus restart
   ExecStop =  /home/nexus/bin/nexus stop  
   User = nexus
   Restart = on- abort 
[Install] 
  WantedBy = multi-user.target

Execute the following commands respectively

systemctl daemon-reload
systemctl enable nexus.service
systemctl start nexus.service

Then type in the browser http://ip:8082 Then click login to enter the account admin password admin123

Three, use

Configure settings.xml of maven locally

vi ~/.m2/settings.xml

Add servers configuration to the root node

<servers>
	<server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	<server>
		<id>releases</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
</servers>

Used to authorize when mvn deploy is executed. This is an admin user, or you can create new users and roles in nexus to authorize. At the same time, you need to release the anonymous access permission in nexus, or you will report "Not Authorized" error when accessing Maven public to pull.

pom.xml configuration

  • Package publishing configuration
	<distributionManagement>
		<snapshotRepository>
			<id>snapshots</id>
			<url>http://1.2.3.4:8082/repository/maven-snapshots/</url>
		</snapshotRepository>
		<repository>
			<id>releases</id>
			<url>http://1.2.3.4:8082/repository/maven-releases/</url>
		</repository>
	</distributionManagement>
  • Pull warehouse configuration
	<repositories>
		<repository>
			<id>nexus</id>
			<name>nexus repository</name>
			<url>http://1.2.3.4:8082/repository/maven-public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

Tags: Programming nexus Jetty xml Maven

Posted on Tue, 17 Mar 2020 00:20:36 -0700 by zeppis