在CentOS上安装Sonatype Nexus Repository OSS

时间:2020-02-23 14:39:21  来源:igfitidea点击:

SONATYPE Nexus是一个流行的存储库管理器,用于大多数组件,二进制文件和构建文物。
它配备了支持Java虚拟机(JVM)生态系统,包括Gradle,Ant,Maven和Ivy。

兼容标准工具,包括Eclipse,Intellij,Hudson,Jenkins,Puppet,Chef,Docker等,Sonatype Nexus Repo可以通过交付二进制文件Docker,装配和成品来管理Dev组件。

在本教程中,我们将为我们提供在CentOS 7上设置Sonatype Nexus存储库OSS版本的全面教程。

在CentOS上安装Sonatype Nexus Repository OSS

在开始教程之前,让我们来看看运行Sonatype Nexus Repo的最低系统要求。

1.预安装

从设置主机名开始。

hostnamectl set-hostname nexus

更新CentOS系统。

yum update -y

使用以下命令安装Java:

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

安装完成后,请检查Java版本以确保我们全部设置为下载repo的下一步。

java -version

2.下载Nexus Repository Manager 3

导航到Opt目录:

cd /opt

从官方WebSIniiteAnd复制repo的最新URL,然后使用WGet下载。

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

提取TAR文件。

tar -xvzf latest-unix.tar.gz

我们应该看到两个目录,包括Nexus文件和Nexus数据目录。

ls -lh

重命名文件夹。

mv nexus-3.20.1-01 nexus
mv sonatype-work nexusdata

3.设置用户/权限和配置

I.为Nexus服务添加用户。

useradd --system --no-create-home nexus

II。
为Nexus文件和Nexus数据设置所有权。

chown -R nexus:nexus /opt/nexus
chown -R nexus:nexus /opt/nexusdata

III。
更改Nexus配置并设置自定义数据目录

编辑"nexus.vmoptions"。

vim /opt/nexus/bin/nexus.vmoptions

更改数据目录。

-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../nexusdata/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=../nexusdata/nexus3
-Dkaraf.log=../nexusdata/nexus3/log
-Djava.io.tmpdir=../nexusdata/nexus3/tmp
-Dkaraf.startLocalConsole=false

保存并退出文件。

IV。
将用户更改为Nexus服务帐户。

编辑"nexus.rc"文件。

vim /opt/nexus/bin/nexus.rc

取消注释"run_as_user"参数并添加新值。

run_as_user="nexus"

V.停止侦听远程连接。

我们需要修改"nexus-default.properties"文件。

vim /opt/nexus/etc/nexus-default.properties

将application-host = 0.0.0.0更改为application-host = 127.0.0.1.

更改应用程序主机

VI。
配置Nexus用户的打开文件限制。

vim /etc/security/limits.conf

将以下值添加到文件中。

nexus - nofile 65536

保存和退出文件。

4.将Nexus设置为系统服务

在"/etc/systemd/system/system /"中创建系统服务文件。

vim /etc/systemd/system/nexus.service

将以下内容添加到文件中。

[Unit]
Description=Nexus Service
After=syslog.target network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Group=nexus
Restart=on-failure
[Install]
WantedBy=multi-user.target

重新加载SystemCtl。

systemctl daemon-reload

启用系统启动服务。

systemctl enable nexus.service

开始服务。

systemctl start nexus.service

监视日志文件。

tail -f /opt/nexusdata/nexus3/log/nexus.log

检查服务端口。

netstat -tunlp | grep 8081

5.设置nginx

设置epel存储库。

yum install -y epel-release

列出存储库。

yum repolist

安装nginx。

yum install nginx

在系统启动时设置nginx

systemctl enable nginx

检查nginx的状态,如果服务未运行,请启动服务。

systemctl status nginx
systemctl start nginx

6.为服务器设置DNS记录。

然后转到DNS管理器并为服务器添加记录。

A Domain Name Server IP

其中我们使用了AWS路线53来设置DNS。

7.使用CESTBOT配置SSL

I.首先安装CERTBOT包。

yum install certbot python2-certbot-nginx

II。
安装证书。

certbot --nginx

它会提出一些问题并输入电子邮件,域名,并如下所需的输入。

生成SSL.

安装完成后,打开nginx.conf。

vim /etc/nginx/nginx.conf

我们可以看到Certbot SSL配置。

III。
添加代理通行证

将以下内容添加到位置块。

location/{
      proxy_pass "http://127.0.0.1:8081";
      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
      proxy_set_header        X-Forwarded-Ssl on;
      proxy_read_timeout      300;
      proxy_connect_timeout   300;
 }

代理通行证

保存并退出文件。

检查nginx语法:

nginx -t

重新启动nginx:

systemctl restart nginx

8.设置防火墙规则

现在使HTTPS访问特定的公共IP。
运行以下命令。

firewall-cmd --permanent --zone=public --add-rich-rule='
rule family="ipv4"
source address="123.44.8.180/32"
port protocol="tcp" port="443" accept'

如果我们需要将HTTPS打开到公共运行以下命令:

firewall-cmd --zone=public --permanent --add-service=https

重新加载防火墙。

firewall-cmd --reload

9.为nginx设置selinux策略

setsebool -P httpd_can_network_connect 1

10.使用域名浏览

eg: https://nexusrepo.theitroad.com/

浏览URL.

11.登录服务器

使用默认用户名作为"admin"登录。
在服务器中运行以下命令并获取密码。

cat /opt/nexusdata/nexus3/admin.password

首次登录后,我们应该看到类似的窗口,如下所示。

点击下一步并为管理员用户设置新密码。

再次单击"下一步",我们应该看到"配置匿名访问"窗口。
不要启用匿名访问。

单击"下一步"按钮,我们可以看到完整的设置。

点击完成。