Installing Nexus on Cent OS - cloudeguru/How-To-Install GitHub Wiki

KloudBlogs Youtube

image

nexus

In this document we will see a step by step guide on how to install Nexus on Cent OS

What is Nexus ?

Nexus Repository Manager is a repository manager used for storing and managing software artifacts. It serves as a central hub for storing binary artifacts such as JAR files, Docker images, npm packages, Maven artifacts, and more. Nexus provides a secure, reliable, and scalable solution for managing dependencies and artifacts throughout the software development lifecycle.

Steps to run Nexus on CentOS:

  1. Launch a t2 medium AWS EC2 instance and choose OS as CentOS 9 or your choice of CentOS 9 and login to it.

  2. If you are launching instance on AWS add the below script as part of user data.

      #!/bin/bash
      yum install java-1.8.0-openjdk.x86_64 wget -y
      mkdir -p /opt/nexus/
      mkdir -p /tmp/nexus/                           `
      cd /tmp/nexus/
      NEXUSURL="https://download.sonatype.com/nexus/3/latest-unix.tar.gz"
      wget $NEXUSURL -O nexus.tar.gz
      sleep 10
      EXTOUT=`tar xzvf nexus.tar.gz`
      NEXUSDIR=`echo $EXTOUT | cut -d '/' -f1`
      sleep 5
      rm -rf /tmp/nexus/nexus.tar.gz
      cp -r /tmp/nexus/* /opt/nexus/
      sleep 5
      useradd nexus
      chown -R nexus.nexus /opt/nexus
      cat <<EOT>> /etc/systemd/system/nexus.service
      [Unit]                                                                          
      Description=nexus service                                                       
      After=network.target                                                            
                                                               
      [Service]                                                                       
      Type=forking                                                                    
      LimitNOFILE=65536                                                               
      ExecStart=/opt/nexus/$NEXUSDIR/bin/nexus start                                  
      ExecStop=/opt/nexus/$NEXUSDIR/bin/nexus stop                                    
      User=nexus                                                                      
      Restart=on-abort                                                                
                                                               
      [Install]                                                                       
      WantedBy=multi-user.target                                                      
    
      EOT
    
      echo 'run_as_user="nexus"' > /opt/nexus/$NEXUSDIR/bin/nexus.rc
      systemctl daemon-reload
      systemctl start nexus
      systemctl enable nexus
    
  3. If you are using any other system of CentOS run the below commands one by one.

  4. Install Java in CentOS

    yum install java-1.8.0-openjdk.x86_64 wget -y

  5. Make a directory nexus inside /opt and /tmp using below commands

    mkdir -p /opt/nexus mkdir -p /tmp/nexus

  6. Download latest nexus inside /tmp/nexus

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

  7. Untar it using below command

    tar xzvf nexus.tar.gz

  8. Delete the tar file now and copy all the contents to /opt/nexus using below commands

    rm -rf /tmp/nexus/nexus.tar.gz cp -r /tmp/nexus/* /opt/nexus

  9. Create a nexus user using below command

    useradd nexus

  10. Provide nexus user permission to /opt/nexus directory by following below command

    chown -R nexus.nexus /opt/nexus/

  11. Create a service for nexus by adding nexus.service file inside /etc/systemd/system by running below command

    vim /etc/systemd/system/nexus.service

    and add below content [Unit]
    Description=nexus service
    After=network.target

    [Service]
    Type=forking
    LimitNOFILE=65536
    ExecStart=/opt/nexus/$NEXUSDIR/bin/nexus start
    ExecStop=/opt/nexus/$NEXUSDIR/bin/nexus stop
    User=nexus
    Restart=on-abort

    [Install]
    WantedBy=multi-user.target

  12. Edit nexus.rc file inside /opt/nexus/nexus3*/nexus.rc and uncomment the line run_as_user and add nexus . The content should be

    run_as_user="nexus"

    save and quit.

  13. Reload system manager

    systemctl daemon-reload

  14. Start nexus service

systemctl start nexus

  1. Enable nexus service

systemctl enable nexus

  1. If all good then open your favorite browser and add http://host-ip:port, you should see something like below
image
  1. Click on login option at the right top corner and you will see that username is admin and password can be retrieved from given location. Cat the file and get the password

sudo cat /opt/nexus/sonatype-work/nexus3/admin.password

image
⚠️ **GitHub.com Fallback** ⚠️