docker搭建Maven私服

    科技2023-11-01  91

    基于docker安装Maven私服仓库


    yum源安装docker

    查看是否已安装docker列表

    yum list installed | grep docker

    yum安装docker

    yum -y install docker

    启动docker

    systemctl start docker

    查看docker服务状态

    systemctl status docker


    nexus3的镜像

    下载一个nexus3的镜像

    docker pull sonatype/nexus3

    将容器内部/var/nexus-data挂载到主机/root/nexus-data目录。内部和外部端口号8081

    docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3

    查看容器ID

    docker ps

    可以查看正在启动的日志 docker attach + 容器的id

    docker attach xxxx容器IDxxx

    启动成功

    关闭防火墙

    service iptables stop

    访问地址

    http://192.x.x.x:8081

    Maven默认账号密码

    进入到容器中

    docker exec -it xxxx容器IDxxx bash

    进入 admin.password 查看密码

    cat /nexus-data/admin.password

    注意 bash-4.4$ 这个不要复制

    账号:admin 密码:0e54da2c-338a-49f3-abf0-c021a07f33c3

    创建Maven仓库

    正式版本

    控制是否允许对工件进行部署和更新 Controls if deployments of and updates to artifacts are allowed

    配置本地settings.xml

    <servers> <server> <id>admin</id> <username>admin</username> <password>admin</password> </server> </servers>

    项目配置文件

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>tst-xxx</artifactId> <groupId>org.tst</groupId> <version>1.0-RELEASE</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>tst-xxx-xx</artifactId> <packaging>jar</packaging> <description>tst xxx</description> <dependencies> <!-- Hu-tool是一个小而全的Java工具类库 --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> <!-- Http Client --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> </dependencies> <!--注意限定版本一定为RELEASE,因为上传的对应仓库的存储类型为RELEASE --> <!--指定仓库地址 --> <distributionManagement> <repository> <!--此名称要和.m2/settings.xml中设置的ID一致 --> <id>admin</id> <url>http://192.168.203.128:8081/repository/tst-RELEASE/</url> </repository> </distributionManagement> <build> <plugins> <!--发布代码Jar插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> </plugin> <!--发布源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>

    Maven 执行命令 上传jar包即可

    mvn deploy

    注意版本号码一定要是为:release版本 ,否则上传jar报错

    本地项目引入maven私服jar

    <dependencies> <dependency> <groupId>com.tst</groupId> <artifactId>tst-xxx-xx</artifactId> <version>1.0-RELEASE</version> </dependency> </dependencies> <!-- 指定私服仓库地址 --> <repositories> <repository> <id>admin</id> <url>http://192.168.203.128:8081/repository/tst-RELEASE</url> </repository> </repositories>

    如何判断文件是否发生改变

    如何知道一个文件是否改变了呢? 当然是用比较文件hash值的方法,文件hash又叫文件签名,文件中哪怕一个bit位被改变了,文件hash就会不同。比较常用的文件hash算法有MD5和SHA-1。

    Processed: 0.013, SQL: 8