My linux world » Nexus

Nexus


Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "create nexus auto-update script"
  4. mkdir -p /opt/nexus/bundle
  5. mkdir -p /opt/nexus/scripts
  6.  
  7. echo "create user nexus"
  8. useradd nexus
  9.  
  10. #remove nexus as a service if exists
  11. systemctl stop nexus.service
  12. systemctl disable nexus.service
  13.  
  14. # download latest bundle
  15. rm -fr /opt/nexus/bundle/*
  16. mkdir -p /opt/nexus/download
  17. wget -O /opt/nexus/download/nexus-latest-bundle.tar.gz http://download.sonatype.com/nexus/3/latest-unix.tar.gz
  18. tar xvfz /opt/nexus/download/nexus-latest-bundle.tar.gz -C /opt/nexus/bundle
  19. chown nexus:nexus /opt/nexus/bundle -R
  20.  
  21. #set nexus as a service
  22. nexusDirectory=`ls /opt/nexus/bundle/ | grep nexus`
  23. sed -i "s/^#\(run_as_user=\s*\).*/\1\"nexus\"/" /opt/nexus/bundle/$nexusDirectory/bin/nexus.rc
  24. sed -i "s/^\(nexus-context-path=\s*\).*/\1\/nexus/" /opt/nexus/bundle/$nexusDirectory/etc/nexus-default.properties
  25.  
  26. cat > /etc/systemd/system/nexus.service << EOF
  27. [Unit]
  28. Description=nexus service
  29. After=network.target
  30.  
  31. [Service]
  32. Type=forking
  33. ExecStart=/opt/nexus/bundle/$nexusDirectory/bin/nexus start
  34. ExecStop=/opt/nexus/bundle/$nexusDirectory/bin/nexus stop
  35. User=nexus
  36. Restart=on-abort
  37.  
  38. [Install]
  39. WantedBy=multi-user.target
  40. EOF
  41.  
  42. systemctl daemon-reload
  43. systemctl enable nexus.service
  44. systemctl start nexus.service
  45.  
  46. rm -fr /opt/nexus/bundle/sonatype-work
  47. ln -s /opt/nexus/sonatype-work /opt/nexus/bundle/sonatype-work
  48. mkdir -p /opt/nexus/sonatype-work
  49. chown nexus:nexus /opt/nexus/sonatype-work/ -R
  50.  
  51. systemctl start nexus.service
  52.  
  53.  
  54. echo "configure httpd (create /etc/httpd/conf.d/nexus.conf)"
  55. cat > /etc/httpd/conf.d/nexus.conf << "EOF"
  56. ProxyPreserveHost On
  57. Proxypass /nexus http://localhost:8081/nexus
  58. Proxypassreverse /nexus http://localhost:8081/nexus
  59. ProxyRequests Off
  60. EOF
  61. systemctl restart httpd.service
  62.  
  63. myip=`hostname -I`
  64. echo "Now meet you here: http://$myip/nexus"
  65.  

That’s all 🙂


Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub