Install and configure nexus under linux

1. How to obtain the installation package

Method 1: Directly upload the downloaded installation package to the server

Insert image description here

Method 2 2. Install the Nexus compressed package through wget

①. You can use the following command to install the latest version of Nexus

wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz

②. You can also click on the official website to copy the Nexus compressed package you want to download and install it.
Nexus official website address: Neuxs official website address
Insert image description here

After obtaining the installation address from the official website, use this command to install it.

wget https://download.sonatype.com/nexus/3/nexus-XXXXXXXX-unix.tar.gz

3. Install and decompress the Nexus installation package

1、切换到上传Nexus安装包的路径下
cd  /tmp/  #切换到tmp路径下
1.
2、把nexus安装包移动到home路径下
登录后复制 
mv  nexus-3.49.0-02-unix.tar.gz  /home/admin/    #移动到home路径下
cd  /home/admin/   #切换到home路径
ls  #查看homg路径中是否有移动过来的nexus安装包
mkdir nexus  #创建文件夹
ls  #查看homg路径中是否有创建好的文件夹
mv nexus-3.49.0-02-unix.tar.gz  nexus  #把nexus安装包移动到创建好的文件夹中
cd nexus/  #切换到刚才创建好的nexus文件夹中
ls  #查看移动过来的nexus安装包

Insert image description here
3. Unzip the nexus installation package
tar -zxvf xxxx -C yyyy Unzip xxxx to the yyy directory

tar -zxvf nexus-3.49.0-02-unix.tar.gz  #解压
ls  #查看是否有截图中的两个文件

Insert image description here

4. Start Nexus

1. View and modify the port number

cd nexus-3.49.0-02  #切换到nexus-3.49.0-02路径下
ls  # 查看
cd etc/  #切换到etc路径下
ls  #查看
vi nexus-default.properties  #编辑nexus-default.properties文件

Insert image description here

The default port number is 8081. Here I changed it to 8089. The port number can be modified as needed.

Insert image description here

2. Configure environment variables

4. 赋予nexus文件夹权限,方便启动和操作:
bash
sudo chown -R 200:200 /opt/nexus-3.23.0-01 
5. 配置环境变量,编辑/etc/profile文件,在末尾添加:
bash 
export NEXUS_HOME=/opt/nexus-3.23.0-01
export PATH=$PATH:$NEXUS_HOME/bin 
使环境变量生效:
bash
source /etc/profile

3. Open port

When non-root users execute firewall-related commands, they need to add sudo before the command, elevate their permissions, and enter their password as prompted.

sudo firewall-cmd --query-port=8089/tcp  #查询8089端口是否开启

sudo firewall-cmd --add-port=8089/tcp --permanent  #添加指定需要开放的端口

sudo firewall-cmd --reload  #重启防火墙

Insert image description here
The default port of Nexus is 8081, which can be configured in the /opt/nexus-3.23.0-01/etc/nexus.properties file. After startup, you can visit http://yourserver:8081 to access the Nexus interface.
Log in to Nexus, the default account password is admin/admin123. After successful login, you will be asked to choose a new strong password.

3. Start Nexus

Startup method one

In the /home/thp/public/nexus/nexus-3.25.1-04/bin directory, execute the script command to start the Nexus service as a background process (does not occupy the current command terminal window): it
will take a while to start. You can use a browser to access the Linux server IP:8081 to verify whether the service is started.

cd ..  #切换到上一级
ls  #查看
cd bin/  #切换到bin路径下
ls  #查看
./nexus start  #启动nexus
ps aux | grep nexus  #查看nexus是否启动

Insert image description here

Startup method 2: run command startup (current process form)

In the /home/thp/public/nexus/nexus-3.25.1-04/bin directory, execute the script command to start the Nexus service in the current process form (it will occupy the current command terminal window):

./nexus run
   等待一段时间后,看到类似如下信息,则为启动成功:

Insert image description here
Summary:
In order not to occupy the current command terminal window, it is recommended to use the 2.1 start command to start the Nexus service (in the form of a background process).

The "/root/.m2/repository" directory usually refers to the local Maven repository on the Unix/Linux system. Maven is a popular build automation tool mainly used for Java projects. The local repository is a cache of all dependencies and artifacts downloaded from the remote repository during the build process.
In Maven, when you specify project dependencies in the project's POM (Project Object Model) file, Maven automatically downloads these dependencies from the remote repository and stores them in the local repository. This helps speed up subsequent builds and avoids downloading the same dependencies repeatedly.
By default, the location of the local Maven repository is usually located in the "~/.m2/repository" directory on Unix/Linux systems. The "/root" directory is the root user's home directory, so "/root/.m2/repository" refers to the root-specific local Maven repository on that system.

Five verification services

There are many ways to verify:

    1、linux 系统命令终端 查看 8081 端口所占用的进程:
netstat -tunlp | grep 8081

Insert image description here
Method 2 ps command

 ps -ef|grep nexus

Insert image description here


6. Initialize and access services

1. Change initial password

1. After opening the Nexus page, the following prompt will appear when logging in. You can find the initial password according to the path prompt.

Insert image description here
2. Enter the following command to search

cd /home/admin/Nexus/sonatype-work/nexus3/

cat admin.password

Insert image description here
After clicking Next, configure anonymous access:
Insert image description here

2. Use and create a warehouse

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
After clicking, you can see the details. The url is the IP address of the new warehouse:

Insert image description here

3. Create roles and configure permissions (it is not recommended to assign deletion permissions):

    依次点击 Repository 仓库管理图标(齿轮)、 Roles、Create role、Nexus role:
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/263d150c95bc45b49ccd7944dec74855.png)

Insert image description here
Retrieve the library name of the custom warehouse and grant permission nx-repository-view-maven2-custom library name-*:

Notice:

    这些权限一定要配置完整,否则很容易导致各种问题(比如:maven项目上传依赖失败等)

Insert image description here

Click Create role to create the role:
Insert image description here
Created successfully:
Insert image description here

4.Create user

Insert image description here
Verify the user:
Click Sign out in the upper right corner, log out of the admin account, and try logging in with the custom user you just created:
Insert image description here
After successful login, you need to enter a credential. You can enter anything you want, or you can cancel directly:

Insert image description here
Expansion:
You can see that although the login is successful, the permissions are relatively small.
Insert image description here
On the home page, you can see that this user does not have Search, Browse and Upload options:
Insert image description here

solve:

    重新用 admin 账号登录后,找到我们之前创建的角色,并分别检索 search、browse、upload 关键字,把 nx-search-read、nx-repository-view-*-*.browse、nx-comopnet-upload 权限赋予给该角色:

Insert image description here

Insert image description here

Insert image description here
Log in as a custom user again. On the homepage, you can see that the Search, Browse and Upload options appear on the navigation bar:

Insert image description here

7. Upload dependency packages:

1. Manual upload

    依次点击首页图标(箱子) 、Upload、最定义的私库:

Insert image description here
Select the file and fill in the relevant information, click Upolad:
Insert image description here
the following error message appears:

Insert image description here
This is because the uploaded jar package does not comply with the MIME type format of the custom warehouse.

solve:

    回到仓库管理中,选择自定义仓库,并找到 Storage 下 的 Strict Content Type Validation:

Uncheck the option (Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format).

Insert image description here
Save configuration:

Insert image description here
Upload again. If the following information appears, the upload is successful:

Insert image description here

View the uploaded jar file:
Click view it now in the previous picture, or directly click Search in the left navigation bar. You can see that the jar package has been manually uploaded successfully:
Insert image description here

2. Automatic upload

Mainly means that when using the maven project for packaging operations, you can configure a custom nexus warehouse IP address and upload it to the warehouse. The specific steps are as follows:

1. Modify maven’s settings.xml configuration file:

    如:IDEA中,点击左上角的 File - Settings ,检索 maven 关键字,可以看到自己当前项目所引用的 maven 配置:

Insert image description here
Insert image description here
Find the settings.xml configuration file,

Insert image description here
Add the following code to the servers tag:

<server> 
	<id>cell</id> 
	<username>cell</username> 
	<password>xxxx</password> 
</server> 

Insert image description here
Save and close the settings.xml file.

  1. The project uploads the .jar dependency package to the custom Nexus warehouse xxx-nexus:
    Find the pom file in the module that needs to upload the .jar package (all jar packages in the project must be uploaded, which can be in the outermost pom.xml of the project) Add the following code to the project tag:
    <!--远程仓库地址-->
    <distributionManagement>
        <repository>
            <id>xxx-nexus</id>
            <name>Xxx Nexus3 Repository</name>
            <url>http://自定义仓库ip:8081/repository/xxx-nexus/</url>
        </repository>
    </distributionManagement>

Insert image description here
Open the Maven Projects window on the right side of IDEA, click the reimport icon in the upper left corner, and then click deploy under LifeCycle:
Insert image description here

     上传成功: 

Insert image description here

Guess you like

Origin blog.csdn.net/tian830937/article/details/132645613