Introduction:
An efficient object repository is essential in the ever-changing world of DevOps and containerization. One feature-rich solution for handling binaries, objects, and Docker images is Nexus, a powerful repository manager. To ensure a safe and effective deployment, this article walks you through the exact steps of installing Nexus on a virtual machine.
Nexus Installation:
Step 1: Launch a VM and install a Nexus on top of that
Login as a root user
#sudo su - #cd /opt #yum install tar wget -y #wget http://download.sonatype.com/nexus/3/nexus-3.15.2-01-unix.tar.gz #tar -zxvf nexus-3.15.2-01-unix.tar.gz #mv /opt/nexus-3.15.2-01 /opt/nexus
#As a good security practice, Nexus is not advised to run Nexus service as a root user, so create a new user called Nexus and grant sudo access to manage Nexus services as follows.
#useradd nexus
#Give the sudo access to Nexus user
#visudo #nexus ALL=(ALL) NOPASSWD: ALL>
#Change the owner and group permissions to /opt/nexus and /opt/sonatype-work directories.
#chown -R nexus:nexus /opt/nexus #chown -R nexus:nexus /opt/sonatype-work #chmod -R 775 /opt/nexus #chmod -R 775 /opt/sonatype-work
#Open /opt/nexus/bin/nexus.rc file and uncomment run_as_user parameter and set as nexus user.
#vi /opt/nexus/bin/nexus.rc #run_as_user="nexus"
#Create Nexus as a service
#ln -s /opt/nexus/bin/nexus /etc/init.d/nexus
#Switch as a Nexus user and start the Nexus service as follows.
#su - nexus
#Enable the nexus services
#sudo systemctl enable nexus
#Start the Nexus service
#sudo systemctl start nexus
#Access the Nexus server from the Laptop/Desktop browser.
http://IPAddess/Hostname:8081/
#Default Credentials
User Name: admin Password: admin123
Troubleshooting
Nexus service is not starting?
a)make sure to change the ownership and group to /opt/nexus and /opt/sonatype-work directories and permissions (775) for nexus users.
b) Ensure you are trying to start the Nexus service with the Nexus user.
c)check if Java is installed or not using the Java -version command.
d) check the nexus.log file available in /opt/sonatype-work/nexus3/log directory.
Are you unable to access the Nexus URL?
a)make sure port 8081 is opened in security groups in the AWS ec2 instance.
Steps to configure Nexus 3 as a Docker Registry:
Nexus Repository (docker hosted) Creation:
docker hosted:
1. Login to your Nexus repository.
2. Create docker hosted
#Login to Nexus and click on the Server Administration link at the top of the window. Click on Repositories.
#Now click on Create the repository
#Choose docker hosted repository
#Choose the value as mentioned:
Click on Create Repository.
#Configure Realm
- Move the Docker Bearer Token realm to the right by clicking on >
This setting allows the docker repository to have anonymous read enabled.
#after moving save it
Do these steps in the Docker server to push and pull docker images from Nexus Repo:
1. Login as root user
2. Go to
/etc/docker
#cd /etc/docker
3. Then create a file called daemon.json
#vi /etc/docker/daemon.json
4. Write these scripts in daemon.json
{ "insecure-registries": [ "13.234.21.143:8083" ] }
(Here we are allowing our docker daemon to access the Nexus Hosted Repo)
5. Save the file
6. Restart the docker service using the below command.
systemctl restart docker
Steps to login Nexus repo and push the images:
1) Login to Nexus repo:
docker login –u admin –p password 13.234.21.143:8083
(or)
docker login 13.234.21.143:8083
2)Build an image using the below command:
docker build –t 13.234.21.143:8083/image1 .
(here while building a docker image we will use IP address with a port for the docked hosted repo instead of the username in http://hub.docker.com ).
3)Push the docker image to Nexus Repo:
Conclusion:
Starting an installation of Nexus requires several careful steps, such as starting a virtual machine and setting up a Docker registry. In line with the best standards for Nexus service and user management, the procedure guarantees the safe and effective management of objects. Assuring a smooth launch of the Nexus service requires troubleshooting techniques like verifying ownership and permissions, which are an essential component of the deployment process.
The following tutorial provides comprehensive instructions for creating and configuring Docker-hosted repositories, enabling customers to fully utilize Nexus for their containerized processes.