关于maven的原理,详见:https://my.oschina.net/adailinux/blog/2247017html
在centos7系统安装maven很简单,直接使用yum安装就能够,不过在安装maven以前首先要配置系统的 JDK (java)环境。春雨使用ansible进行部署,对应的role是 maven 。java
playbook:node
$ cat maven.yml --- - hosts: ucloud gather_facts: False roles: - role: maven
使用方法:linux
$ ansible-playbook maven.yml
官方建议 服务器硬件配置:git
Java和maven在上面的过程已安装,接下来只须要安装npm,步骤以下:web
# 安装以前先建立对应的目录 $ mkdir /home/node $ cd /home/node # 使用nodejs管理npm $ wget https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.xz # 解压 $ tar Jxvf node-v8.12.0-linux-x64.tar.xz $ mv node-v8.12.0-linux-x64 nodejs # 加入系统环境 $ ln -s /home/node/nodejs/bin/node /usr/bin/node $ ln -s /home/node/nodejs/bin/npm /usr/bin/npm # 升级npm $ npm install npm@latest -g
# 建立安装目录 $ mkdir /home/sonatype $ cd /home/sonatype $ wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz $ tar zxvf latest-unix.tar.gz $ [root@host1 sonatype]# ls nexus-3.13.0-01 sonatype-work ## nexus-3.13.0-01 应用文件目录 ## sonatype-work 数据文件目录 # 进入应用文件目录 $ cd /home/sonatype/nexus-3.13.0-01 # 运行sonatype $ ./bin/nexus run ## 输出 Started Sonatype Nexus 表示启动成功! ## 后续会加入systemd管理
启动成功后在浏览器访问(localhost:8081):http://192.168.228.128:8081/ ,进入web界面npm
使用管理员用户登陆,帐号:admin 密码:admin123。若是使用sonatype管理用户和密码,能够经过设置——change password来更改密码,若是集成了ldap用户,则没法经过此方法更改密码。json
系统优化: vim
sonatype须要配置系统文件描述符数量为 65536,配置方法以下:centos
# 查看当前系统可打开文件描述符数量 $ ulimit -n # 修改文件描述符数量 ## 临时修改 $ ulimit -n 65535 ## 永久修改 $ vim /etc/security/limits.conf nexus - nofile 65536
若是 加入了systemd管理 nexus,上述方法是不生效的,配置方法以下:
$ vim /usr/lib/systemd/system/nexus.service [Unit] Description=nexus service After=network.target [Service] Type=forking LimitNOFILE=65536 ExecStart=/home/sonatype/nexus-3.13.0-01/bin/nexus start ExecStop=/home/sonatype/nexus-3.13.0-01/bin/nexus stop User=nexus Restart=on-abort [Install] WantedBy=multi-user.target $ systemctl daemon-reload $ useradd nexus $ chown -R nexus:nexus /home/sonatype $ systemctl start nexus
更改maven配置 编辑maven的settings.xml文件,更改mirror、profile、activeProfiles模块的内容以下:
$ vim /etc/maven/settings.xml <settings> <mirrors> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/repository/maven-proxy/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
配置Nexus,到web端配置:
配置repository:
选择maven2(proxy):
点击“Create repository”
建立 POM file (pom.xml)内容以下:
$ vim /etc/maven/pom.xml <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>nexus-proxy</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> </dependencies> </project>
构建maven-proxy:
# 构建以前须要先配置一下java环境(mvn命令默认使用/usr/java/latest/bin/java) $ ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java /usr/java/latest/bin/java # 开始构建 $ mvn package [INFO] Building jar: /etc/maven/target/nexus-proxy-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:27.411s [INFO] Finished at: Tue Oct 09 13:21:33 CST 2018 [INFO] Final Memory: 8M/20M [INFO] ------------------------------------------------------------------------ # 构建完成!
构建过程能够在web界面查看,点击 ——点击Components——选择对应的仓库名称(maven-proxy)。
备份已有npm配置文件(.npmrc),若是没有,忽略此步骤;
进入web端,配置Nexus:
配置repository:
选择npm(proxy):
点击“Create repository”
进入命令行,配置npm:
$ npm config set registry http://localhost:8081/repository/npm-proxy $ vim package.json { "name": "npm-proxy", "version": "0.0.1", "description": "Test Project 1", "dependencies" : { "commonjs" : "0.0.1" } }
构建npm-proxy:
$ npm install