Devops_CICD/Nexus2020. 8. 19. 17:37

1. system Requirements

------------------------------------------------------------------

● cpu

Minimum CPUs: 4, Recommended CPUs: 8+

 

● memory

                        JVM Heap        JVM Direct    Host Physical RAM

------------------------------------------------------------------

Minimum ( default )         2703MB           2703MB         8GB

Maximum                 4GB            (host physical RAM * 2/3) - JVM max heap        no limit

 

● disk space

formats like Docker and Maven can use very large amounts of storage (500Gb easily).

 

2. yum update & install OpenJDK

------------------------------------------------------------------

yum update -y

yum -y install wget vim

 

# Install OpenJDK

yum list java*jdk-devel

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

java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64.rpm

 

#ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 /usr/lib/jvm/java-1.8.0

 

ls -l /usr/bin/javac

/usr/bin/javac -> /etc/alternatives/javac

ls -l /etc/alternatives/javac

/etc/alternatives/javac -> /usr/lib/jvm/java-1.8.0/bin/javac

alternatives --config java

alternatives --config javac

java -version

 

# Set JAVA_HOME environment variable.

echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0" >> ~/.bashrc

echo "PATH=$PATH:$JAVA_HOME/bin:$HOME/bin" >> ~/.bashrc

echo "export PATH" >> ~/.bashrc

 

source ~/.bashrc

env | grep JAVA

JAVA_HOME=/usr/lib/jvm/java-1.8.0

 

 

3. Download and extract nexus

------------------------------------------------------------------

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

tar xvf nexus.tar.gz -C /opt

/opt/nexus-3.23.0-03

/opt/sonatype-work

 

ln -s /opt/nexus-3.23.0-03/ /opt/nexus

ln -s /opt/nexus/bin/nexus /etc/init.d/nexus

 

# nexus 2 download

wget -O nexus2.tar.gz https://download.sonatype.com/nexus/oss/nexus-latest-bundle.tar.gz

 

 

4. Setup nexus user

------------------------------------------------------------------

# Create nexus user

groupadd -g 1002 -r nexus

useradd -c "nexus3 oss" -u 1002 -g nexus -s /bin/bash -r -p password nexus

 

chown -R nexus:nexus /opt/nexus

chown -R nexus:nexus /opt/sonatype-work

 

5. Running as nexus user

------------------------------------------------------------------

vim /opt/nexus/bin/nexus.rc

run_as_user="nexus"

 

#VM options

vim /opt/nexus/bin/nexus.vmoptions

-Xms2703m

-Xmx2703m

-XX:MaxDirectMemorySize=2703m

-XX:+UnlockDiagnosticVMOptions

-XX:+LogVMOutput

-XX:LogFile=../sonatype-work/nexus3/log/jvm.log

-XX:-OmitStackTraceInFastThrow

-Djava.net.preferIPv4Stack=true

-Dkaraf.home=.

-Dkaraf.base=.

-Dkaraf.etc=etc/karaf

-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties

-Dkaraf.data=../sonatype-work/nexus3

-Dkaraf.log=../sonatype-work/nexus3/log

-Djava.io.tmpdir=../sonatype-work/nexus3/tmp

-Dkaraf.startLocalConsole=false

 

6. Running nexus as Linux service

------------------------------------------------------------------

#ln -s /opt/nexus/bin/nexus /etc/init.d/nexus

systemctl enable nexus

Executing /sbin/chkconfig nexus ons

 

#cd /etc/init.d

#chkconfig --add nexus

#chkconfig --levels 345 nexus on

#service nexus start

 

# vim /etc/security/limits.conf

nexus - nofile 65536

 

# vim /etc/systemd/system/nexus.service

[Unit]

Description=nexus service

After=network.target

 

[Service]

Type=forking

LimitNOFILE=65536

User=nexus

Group=nexus

ExecStart=/opt/nexus/bin/nexus start

ExecStop=/opt/nexus/bin/nexus stop

User=nexus

Restart=on-abort

TimeoutSec=600

 

[Install]

WantedBy=multi-user.target

 

7. Starting nexus

------------------------------------------------------------------

# open firewall

firewall-cmd --permanent --zone=public --add-port=22/tcp

firewall-cmd --permanent --zone=public --add-port=8081/tcp

firewall-cmd --reload

firewall-cmd --permanent --list-all

 

systemctl daemon-reload

systemctl enable nexus

systemctl restart nexus

systemctl status nexus

 

tail -f /opt/sonatype-work/nexus3/log/nexus.log

 

# console login

http://localhost:8081

Default username is admin / admin123

# default admin password

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

 

8. Running behind reverse proxy

------------------------------------------------------------------

yum install -y httpd

 

# vim /opt/sonatype-work/nexus3/etc/nexus.properties

nexus-context-path=/nexus

 

# vim /etc/httpd/conf.d/nexus.conf

ProxyRequests Off

ProxyPreserveHost On

 

<VirtualHost 127.0.0.1:80>

    ServerName centos.dev

    ServerAdmin admin@centos.dev

    ProxyPass /nexus http://localhost:8081/nexus

    ProxyPassReverse /nexus http://localhost:8081/nexus

    ErrorLog /var/log/nexus/error.log

    CustomLog /var/log/nexus/access.log common

</VirtualHost>

 

9. ErrorLog and CustomLog directives configuration

------------------------------------------------------------------

mkdir /var/log/nexus

apachectl configtest

Syntax OK

systemctl httpd restart

 

10. Maven Artifacts Uploader

------------------------------------------------------------------

This is a friendly command line tool for uploading a directory of artifacts to Nexus 3.x repository

 

1) Installation

Clone package

git clone https://github.com/ronbadur/maven-artifacts-uploader.git

cd maven-artifacts-uploader

mvn install

 

conf/config.properties

=> repository url, repositroy id

 

PATH enviroment

echo "export MVN-UPLOAD=/opt/maven-artifacts-uploader" >> ~/.bashrc

echo "PATH=$PATH:$MVN-UPLOAD/bin:$HOME/bin" >> ~/.bashrc

echo "export PATH" >> ~/.bashrc

 

settings.xml

<servers>

   <server>

      <id>nexus</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

 </servers>

 

2) upload all the artifacts in specific directory

#mvnUploader -d path/to/your/artifacts

java -jar ./lib\nexus-uploader.jar -d /opt/mvn-repo

 

# To get all the options that available

mvnUploader -h

 

11. upload files into Nexus 3

------------------------------------------------------------------

curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/repository/maven-releases/org/foo/1.0/foo-1.0.pom

 

# Example without a pom file

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -Dfile=target/project-1.0.0.jar

 

# With a pom file

mvn deploy:deploy-file -DgeneratePom=false -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -DpomFile=pom.xml -Dfile=target/project-1.0.0.jar

 

12. Gradle을 이용한 Nexus 저장소 Upload

------------------------------------------------------------------

Nexus 배포를 위한 uploadArchives 스크립트를 작성

# vi build.gradle

apply plugin: 'maven'

 

group = "paas.test"

version = '0.0.1-SNAPSHOT'

 

project.group = 'paas.test'

 

uploadArchives {

  repositories {

    mavenDeployer {

      repository(url: 'http://your.nexus.repository.com/nexus/content/repositories/releases/') {

        authentication(userName: '계정명', password: '비밀번호')

      }

      snapshotRepository(url: 'http://your.nexus.repository.com/nexus/content/repositories/snapshot/') {

        authentication(userName: '계정명', password: '비밀번호')

      }

    }

  }

}

=> eclipse에서 uploadArchives 실행하 Nexus 업로드

 

https://help.sonatype.com/repomanager3/installation

https://drmanalo.github.io/blog/2017/installing-nexus-centos7.html

https://devopscube.com/how-to-install-latest-sonatype-nexus-3-on-linux/

https://help.sonatype.com/repomanager2/download

https://github.com/ronbadur/maven-artifacts-uploader

https://support.sonatype.com/hc/en-us/articles/115006744008-How-can-I-programmatically-upload-files-into-Nexus-3-

https://kingbbode.tistory.com/37

Posted by sonorous34