搭建maven私服
安装Nexus
的前提是已经安装JDK,JDK的安装这里就不再赘述,安装JDK-1.7
版本,JDK版本过低在启动Nexus的时候会报错.
下载与启动
下载链接为http://www.sonatype.org/nexus/go/ 最新版本为 nexus-2.11.4-01
,我们下载NEXUS OSS(TGZ)
. 得到nexus-2.11.4-01-bundle.tar.gz
- 将
nexus-2.11.4-01-bundle.tar.gz
复制到/usr/local
目录下
sudo cp nexus-2.11.4-01-bundle.tar.gz /usr/local
cd /usr/local
- 解压
nexus-2.11.4-01-bundle.tar.gz
,得到nexus-2.11.4-01
和sonatype-work
两个文件夹,为了以后操作方便,我们将创建软链接nexus
指向nexus-2.11.4-01
sudo tar -zxvf nexus-2.11.4-01-bundle.tar.gz
sudo ln -s nexus-2.11.4-01 nexus
- 启动
Nexus
cd nexus
sudo bin/nexus
输出:
Usage: bin/nexus { console | start | stop | restart | status | dump }
根据英文即可知道每个命令的意思,现在启动Nexus
sudo 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.
此时修改bin/nexus
文件设置RUN_AS_USER
sudo vim bin/nexus
将 #RUN_AS_USER=
改成 RUN_AS_USER=root
重新启动Nexus
sudo bin/nexus start
输出:
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
打开localhost:8081/nexus
进行查看,启动成功.如果打不开怎么办? 查看日志
vim logs/wrapper.log
根据错误提示来修改配置文件.
- 修改
nexus
的端口
sudo vim conf/nexus.properties
将application-port=8081 改成你想设置的端口,例如9000.
nexus.properties
文件中的nexus-work
:指定构件库的存储位置
将Nexus设置为系统自启动服务
- 复制
/usr/local/nexus/bin/nexus
文件到/etc/init.d/
sudo cp /usr/local/nexus/bin/nexus /etc/init.d/
- 修改
/etc/init.d/nexus
sudo vim /etc/init.d/nexus
添加修改以下变量:
NEXUS_HOME="/usr/local/nexus"
RUN_AS_USER=root
PIDDIR="/var/run"
- 启动
nexus
服务
sudo service nexus start #启动
sudo service nexus stop #停止服务
sudo service nexus status #查看服务状态
启动之后,跟之前所述一样,打开http://localhost:8081/nexus
即可.
提示
默认登录用户名为admin,密码admin123
使用nginx
nginx是一个非常轻量级的HTTP服务器,nginx,它的发音为“engine X”, 是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器。
-
nginx
安装
sudo apt-get install nginx
默认nginx
安装,所有的配置文件都在/etc/nginx
下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available
下, 启动程序文件在/usr/sbin/nginx
,日志放在了/var/log/nginx
中,分别是access.log
和error.log
,并已经在/etc/init.d/
下创建了启动脚本nginx
,默认的虚拟主机的目录设置在了/usr/share/nginx/www
安装过之后,默认已经启动.查看是否启动:
sudo service nginx status #查看状态
sudo service nginx stop #停止服务
sudo service nginx start #启动服务
启动之后,打开http://localhost/
即可.如果不能访问,先不要继续,看看是什么原因,解决之后再继续。
- 配置
nginx
cd /etc/nginx/conf.d
sudo vim nexus.conf
将下列内容复制进去
#
# The default server
#
server {
listen 80 ;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
# Load configuration files for the default server block.
location /nexus {
proxy_set_header Via "nginx";
proxy_read_timeout 120;
proxy_send_timeout 120;
proxy_connect_timeout 120;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8081/nexus;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
重启nginx
sudo service restart nginx
如果你的机器同时安装了Apache
,此时nginx
都可能启动不了,这是因为它们都是用了80
这个端口。两种方法:停止apache
或者将nginx的端口修改为8080
,将nexus.conf
配置文件中的 listen 80
改为listen 8080
启动成功之后,访问http://127.0.0.1/nexus
即可.
配置nexus
- 配置
nexus
开启远程索引 新搭建的neuxs
环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus
默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus
系统,默认用户名密码为admin/admin123
。
点击左侧的Views/Repositories
,下拉菜单中有Repositories
选项,点击Repositories
,找到右边仓库列表中的三个仓库Apache Snapshots
,Codehaus Snapshots
和Central
,然后在这三个仓库的configuration
下把Download Remote Indexes
修改为true
。然后在这三个仓库上分别右键,选择Repair Index
,这样nexus
就会去下载远程的索引文件。
-
建立内部仓库 新建公司的内部仓库,步骤为页面上部的
Add –> Hosted Repository
,在页面的下半部分输入框中填入Repository ID
和Repository Name
即可,比如分别填入myrepo
和my repository
,另外把Deployment Policy
设置为Allow Redeploy
,点击save
就创建完成了. -
修改
neuxs
仓库组nexus
中仓库组的概念是Maven
没有的,在Maven
看来,不管你是hosted
也好,proxy
也好,或者group
也好,对我都是一样的,我只管根据groupId
,artifactId
,version
等信息向你要构件。为了方便Maven
的配置,nexus
能够将多个仓库,hosted
或者proxy
合并成一个group
,这样,Maven
只需要依赖于一个group
,便能使用所有该group
包含的仓库的内容。
neuxs
中默认自带了一个名为Public Repositories
组,点击该组可以对他保护的仓库进行调整。同时创建一个Group ID
为public-snapshots
、Group Name
为Public Snapshots Repositories
的组,把Apache Snapshots
、Codehaus Snapshots
和Snapshots
加入其中。
到这里neuxs
的安装配置就完成了.
二、
1
2
3
|
[root@MiWiFi-R1CM-srv src] # wget
[root@MiWiFi-R1CM-srv src] # tar -zxf nexus-2.9.0-bundle.tar.gz -C /usr/local/
[root@MiWiFi-R1CM-srv src] # mv /usr/local/nexus-2.9.0-bundle /usr/local/nexus
|
1
|
sed -i 's/application-port=8081/application-port=8088/g' nexus /conf/nexus .properties
|
1
2
3
4
|
[root@MiWiFi-R1CM-srv ~] # echo -e '#!/bin/bash\nexport NEXUS_HOME=/usr/local/nexus\nexport PATH=$PATH:$NEXUS_HOME/bin\nexport RUN_AS_USER=root' >/etc/profile.d/nexus.sh
[root@MiWiFi-R1CM-srv ~] # source /etc/profile.d/nexus.sh
[root@MiWiFi-R1CM-srv local ] # /usr/local/nexus/bin/nexus start
[root@MiWiFi-R1CM-srv local ] # netstat -tlunp |grep 8088
|
1
2
|
[root@MiWiFi-R1CM-srv local ] # cd /usr/local/nexus/
[root@MiWiFi-R1CM-srv nexus] # cp bin/jsw/linux-x86-64/nexus /etc/init.d/
|
1
|
[root@MiWiFi-R1CM-srv nexus] # vim /etc/init.d/nexus
|
1
2
3
4
5
6
|
# chkconfig: 2345 66 39 # description: running&stop nexus service. RUN_AS_USER=root NEXUS_HOME= /opt/pht/nexus-2 .5.1-01
PLATFORM=linux-x86-64 PLATFORM_DIR= "${NEXUS_HOME}/bin/jsw/${PLATFORM}"
|
1
2
3
|
WRAPPER_CMD= "${PLATFORM_DIR}/wrapper"
WRAPPER_CONF= "${PLATFORM_DIR}/../conf/wrapper.conf"
PIDDIR= "${NEXUS_HOME}"
|
1
|
[root@MiWiFi-R1CM-srv nexus] # vim /usr/local/nexus/bin/jsw/linux-x86-64/../conf/wrapper.conf
|
1
|
wrapper.java. command =java
|
1
|
wrapper.java. command = /usr/jdk1 .7.0_67 /bin/java
|
1
|
[root@MiWiFi-R1CM-srv nexus] # chmod +x /etc/init.d/nexus
|
1
|
[root@MiWiFi-R1CM-srv nexus] # chkconfig --add nexus
|
1
|
[root@MiWiFi-R1CM-srv nexus] # service nexus start
|
1
2
|
[root@MiWiFi-R1CM-srv nexus] # ps -ef |grep nexus
root 12762 34939 0 10:08 pts /2 00:00:00 grep nexus
|
1
2
|
[root@MiWiFi-R1CM-srv nexus] # netstat -tlun |grep 7777
[root@MiWiFi-R1CM-srv nexus] #
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
wrapper | --> Wrapper Started as Daemon wrapper | Launching a JVM... wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
jvm 2 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
jvm 3 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
jvm 4 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
jvm 5 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
wrapper | There may be a configuration problem: please check the logs. wrapper | <-- Wrapper Stopped |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
wrapper | --> Wrapper Started as Daemon wrapper | Launching a JVM... wrapper | Unable to start JVM: Permission denied (13) wrapper | JVM exited while loading the application.
wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: Permission denied (13) wrapper | JVM exited while loading the application.
jvm 2 | wrapper | Unable to start JVM: Permission denied (13) wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: Permission denied (13) wrapper | JVM exited while loading the application.
jvm 3 | wrapper | Unable to start JVM: Permission denied (13) wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: Permission denied (13) wrapper | JVM exited while loading the application.
jvm 4 | wrapper | Unable to start JVM: Permission denied (13) wrapper | Reloading Wrapper configuration... wrapper | Launching a JVM... wrapper | Unable to start JVM: Permission denied (13) wrapper | JVM exited while loading the application.
jvm 5 | wrapper | Unable to start JVM: Permission denied (13) wrapper | There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
wrapper | There may be a configuration problem: please check the logs. wrapper | <-- Wrapper Stopped |
推荐阅读
-
利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一)
-
从0到1搭建element后台框架优化篇(打包优化)
-
利用ASP.NET MVC+Bootstrap搭建个人博客之修复UEditor编辑时Bug(四)
-
利用ASP.NET MVC+Bootstrap搭建个人博客之打造清新分页Helper(三)
-
利用ASP.NET MVC+Bootstrap搭建个人博客之praise.js点赞特效插件(二)
-
搭建简单的nodejs http服务器详解
-
使用IDEA配置Maven搭建开发框架ssm教程
-
vue.js 2.*项目环境搭建、运行、打包发布的详细步骤
-
vue 搭建后台系统模块化开发详解
-
安卓开发环境配置有哪些方法,android开发环境的搭建步骤