1. 程式人生 > >Linux伺服器搭建概要(三)

Linux伺服器搭建概要(三)

環境資訊

centos7.2

安裝目錄

Nexus下載與安裝

Nexus下載與安裝

1. 安裝前工作

下載nexus傳送門

下載與安裝

下載
wget "https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.3-02-bundle.tar.gz"
解壓
[[email protected] installPath]# tar -zxvf nexus-2.14.3-02-bundle.tar.gz
移動並且改名
[[email protected] installPath]# mv nexus-2.14.3-02 ./../nexus-2.14.3
進入解壓的檔案並檢視位置
[
[email protected]
nexus-2.14.3]# pwd /usr/local/java/nexus-2.14.3

基礎的命令說明

進入bin目錄執行以下命令
啟動
[[email protected] bin]# ./nexus start
關閉
[[email protected] bin]# ./nexus stop
重啟
[[email protected] bin]# ./nexus restart

啟動出現的問題

[[email protected] bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.


預設情況下,不建議以root使用者執行Nexus,可以修改bin/nexus中的配置跳過警告(修改RUN_AS_USER=root)

解決方案:
    vi nexus
        # NOTE - This will set the user which is used to run the Wrapper as well as
        #  the JVM and is not useful in situations where a privileged resource or
        #  port needs to be allocated prior to the user being changed.
        #RUN_AS_USER=
    修改為
        # NOTE - This will set the user which is used to run the Wrapper as well as
        #  the JVM and is not useful in situations where a privileged resource or
        #  port needs to be allocated prior to the user being changed.
        RUN_AS_USER=root
    重新啟動

修改埠

注:Nexus預設埠8081,如果想修改埠。修改/conf/nexus.properties檔案

訪問資訊

埠預設為8081
http://ip:port/nexus/


賬號-密碼(預設)
admin/admin123

修改配置

1: 點選views/Repositories下面的Repositories,將列表中所有Type為proxy 的專案的 Configuration 中的 Download Remote Indexes 設定為True
2: 將Releases倉庫專案中 Configuration的Deployment Policy設定為 Allow ReDeploy
3: 當然我們也避免不了會使用到一些第三方的 jar ,而這些jar包也不存在於網際網路上的maven中央倉庫中,這時我們可以手工新增jar 到我們的私服中。
      新增第三方 jar 如下:
        ①:選擇倉庫-3rd party然後選擇其下面的artifact upload選項,然後可以進行上傳。
        ②:填寫完必選欄位,點選Upload Artifact(s)按鈕即可

配置本地專案引用私服

    
自動釋出構件到遠端倉庫,在工程pom.xml中新增(就是釋出到中央倉庫中)
<distributionManagement>
    <repository>
        <id>releases</id><!--這個ID需要與你的release倉庫的Repository ID一致-->
        <url>http://ip:port/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id><!--這個ID需要與你的snapshots倉庫的Repository ID一致-->
        <url>http://ip:port/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

修改本地$MAVEN_HOME\conf目錄下的settings.xml配置檔案,新增如下配置(釋出時候用到的賬號密碼)

可以有多個server項
<servers>
    <server>
    	<!--這個要與distributionManagement中的repository的id相同(其實就是這個ID需要與你的release倉庫的Repository ID一致),-->
        <id>releases</id>
        <username>xxx</username>
        <password>xxxxx</password>
    </server>
    <server>
        	<!--這個要與distributionManagement中的repository的id相同(其實就是這個ID需要與你的release倉庫的Repository ID一致),-->
        <id>snapshots</id>
        <username>xxx</username>
        <password>xxxxx</password>
    </server>
</servers>


在本地工程目錄下執行以下命令進行釋出
mvn deploy

配置Maven從Nexus下載構件
在POM中配置Nexus私服,這樣的配置只對當前的Maven專案有效。

在settings.xml中配置profile元素,這樣就能讓本機所有的Maven專案都使用自己的Maven私服。

可以有多個profile項
<profiles>
    <profile>
    <!--這個無所謂,可以自定義,下面activeProfile選項可以啟用此id-->
			<id>nexus</id>
			<repositories>
				<repository>
<!--這個要與servlet上的id一致(其實就是這個ID需要與你的release倉庫的Repository ID一致),-->
					<id>snapshots</id>
					<url>http://ip:port/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<!--指定Nexus的外掛倉庫-->
			<pluginRepositories>
				<pluginRepository>
					<id>snapshots</id>
					<url>http://ip:8081/nexus/content/groups/public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
  </profiles>

啟用預設配置(settings.xml)
最下面啟用要使用的項

<activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>aliyun</activeProfile>
  </activeProfiles>

可以新增幾個代理等倉庫地址

點選新增倉庫,選擇proxy
    ①:新增1:aliyun
        地址:http://maven.aliyun.com/nexus/content/groups/public
        其他的預設即可
    ②:新增2:apache_release
        地址:https://repository.apache.org/content/repositories/releases/
        其他的預設即可
    ③:新增3:apache_snapshot
        地址:https://repository.apache.org/content/repositories/snapshots/
        其他的預設即可