eth的gas估算

eth平台消耗的Gas满足如下公式$cost = gasUsage * gasPrice $

  • $gasUsage为gas的消耗量$
  • $gasPrice为gas的单价,与交易打包确认时间负相关$

由于gasPrice主要影响交易等待打包确认时间,由eth平台繁忙程度所影响,可以查看参考链接中关于gasPrice 和交易等待时间的影响结合自身的业务决定,故本文只着重介绍普通交易和智能合约运行所需的gasUsage的估算,在计算最终cost时,统一采用$gasPrice = 1 Gwei$

普通交易所需的Gas

eth平台执行普通的交易转账需要消耗gas,消耗的gas 满足一下公式:

$cost = gasUsage * gasPrice = (账户发起者减少的资产 - 账户接收者增加的资产)$

  • 其中$gasUsage为固定值=21000$
  • $gasPrice为gas的单价,与交易打包确认时间负相关$

智能合约所需的Gas

普通转账交易所需的gas固定值为21000,调用智能合约方法所需要的gas并不一定,主要由占用的资源(cpu,内存等)决定(计算量影响cpu),占用的资源越多,所需要的gas也越多。我们主要分析两个智能合约的gas消耗估算:

  • 智能合约token转账

    采用truffle demoMetaCoin.sol进行智能合约的测试,合约内容如下:

    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
    28
    pragma solidity ^0.4.2;
    import "./ConvertLib.sol";

    contract MetaCoin {
    mapping (address => uint) balances;

    event Transfer(address indexed _from, address indexed _to, uint256 _value);

    function MetaCoin() {
    balances[tx.origin] = 10000;
    }
    // 转账逻辑
    function sendCoin(address receiver, uint amount) returns(bool sufficient) {
    if (balances[msg.sender] < amount) return false;
    balances[msg.sender] -= amount;
    balances[receiver] += amount;
    Transfer(msg.sender, receiver, amount);
    return true;
    }

    function getBalanceInEth(address addr) returns(uint){
    return ConvertLib.convert(getBalance(addr),2);
    }

    function getBalance(address addr) returns(uint) {
    return balances[addr];
    }
    }

    使用以上智能合约,进行一次转账操作(Send Meta Token,发送的token数量为1):

    1
    2
    3
    4
    Transaction: 0xc3591a4a8614721ce176f58782455b127d1946dbcf10876c7e7c4fa169da849b
    Gas usage: 36050
    Block Number: 7
    Block Time: Fri Jun 15 2018 11:05:41 GMT+0800 (CST)

    通过testrpc日志可以看到Gas usage36050

  • 智能合约存储

    测试一下简单的智能合约SimpleStorage.sol

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    pragma solidity ^0.4.2;  
    contract SimpleStorage {
    string storedData;

    function set(string x) {
    storedData = x;
    }

    function get() constant returns (string) {
    return storedData;
    }
    }

    truffle console执行智能合约contract.set('8DFCB2DA63B35B9DAA0906FCA18053FD')存入32 ASCII Character

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    { tx: '0xb49d7d757920514d5ef9f2bbb5c1171d76d9bcfa8e4633f05f73c718164812f3',
    receipt:
    { transactionHash: '0xb49d7d757920514d5ef9f2bbb5c1171d76d9bcfa8e4633f05f73c718164812f3',
    transactionIndex: 0,
    blockHash: '0x84f864f4999edd4278a714af9ba3c6ea99010c8ef2ce45551e93ad019ae4c03d',
    blockNumber: 8,
    gasUsed: 64764,
    cumulativeGasUsed: 64764,
    contractAddress: null,
    logs: [],
    status: 1 },
    logs: [] }

    通过testrpc日志可以看到Gas usage64764(不同的机器环境会有些误差)

单位换算

$ 1eth = 10^9 Gwei = 10^{18} wei = $ $508.08

比如普通转账的gas估算:

  • $gasPrice = 1Gwei$

  • $gasUsage = 21000$

cost = gasUsage * gasPrice = 21000 * 1Gwei / 10 ^{18}wei = 2.1 * 10 ^ {-5}eth = $ 0.01

参考链接

分享到

aws配置eb-cli

EB CLI 是 Elastic Beanstalk 的命令行界面,它提供了可简化从本地存储库创建、更新和监控环境的交互式命令。将 EB CLI 用作每日开发和测试周期的一部分,取代 AWS 管理控制台。

Prerequisites

  • Larger than Python 2.7 or Python3.4

安装EB CLI

1
2
3
4
5
6
7
# 可选参数 --upgrade更新依赖组件 --user安装到用户子目录
pip install awsebcli
# 设置Env, eg: LOCAL_PATH=~/.local/bin
export PATH=LOCAL_PATH:$PATH
source ~/.bashrc
# Check eb version
eb --version

配置 EB CLI

1
2
3
4
5
6
7
8
9
10
11
12
13
# Maven package 激活pro的profile打入ebextensions的nginx配置
cd my-app && mvnw clean package -Dmaven.test.skip=true
# EB init
eb init
# EB create env profile
eb create
# EB deploy
eb deploy
# EB logs
eb logs
# 登录 EB Instance 检查详细日志
# eb ssh
# tailf /var/log/nginx/access.log

配置示例(cat .elasticbeanstalk/config.yml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
branch-defaults:
master:
environment: my-app-dev
group_suffix: null
release:
environment: my-app-dev
group_suffix: null
deploy:
# 需要上传java包的路径
artifact: target/my-app.war
global:
application_name: my-app
branch: null
default_ec2_keyname: mypem
default_platform: Java 8
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: git
workspace_type: Application

反向代理配置

1
2
3
4
5
6
7
8
9
10
#### Nginx配置如何生效
- 目录结构如下:
my-app.war
|-- .ebextensions
| `-- nginx
| `nginx.conf
| `agent_deny
`-- org
`--META-INF
`--WEB-INF

Pom.xml

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
<!--maven package springboot war-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/ebextensions</directory>
<targetPath>.ebextensions</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>

参考链接

分享到

nginx反爬策略配置

网站部署上线后,为了防止爬虫的侵扰,一般会进行反爬策略限制。在Web开发中Nginx一般作为Gateway和Router,本文主要介绍如何使用Nginx进行User-Agent和RateLimit两个方面来进行反爬

User-Agent

cat /etc/nginx/agent_deny

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}

#禁止指定UA及UA为空的访问
if ($http_user_agent ~* "FeedDemon|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" ) {
return 403;
}

#禁止非GET|POST方式的抓取
if ($request_method !~ ^(GET|POST)$) {
return 403;
}

RateLimit

RateLimit传统的算法主要分为token bucket和leaky bucket,nginx和传统的leaky bucket算法略微有些区别,leaky bucket算法主要处理方式Traffic Shaping和Traffic Policing,Traffic Shaping的核心理念是”等待”,Traffic Policing的核心理念是”丢弃”,在bucket满后,常见的处理方式为:

  • 暂时拦截住上方水的向下流动,等待桶中的一部分水漏走后,再放行上方水
  • 溢出的上方水直接抛弃
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Rate Limit
# 此设置只能放在 http 节点下
limit_req_zone $binary_remote_addr zone=ratelimit:10m rate=2r/s;
# 默认为503 Service Unavailable,返回429 Too Many Request更为合适
limit_req_status 429;

# Server
server {
listen 80;
server_name localhost;
charset utf-8;

location / {
# 此设置在 http, server, location 节点都可以设置;设置了 nodelay 将不会等待
limit_req zone=ratelimit burst=20 nodelay;
include agent_deny;
proxy_pass http://127.0.0.1:8080/java-web;
}
}

参考链接

分享到

nginx的https配置

在web开发中,一般使用nginx作为网关,本文介绍nginx下的https的配置

证书申请

主要介绍阿里云免费SSL证书申请

  • 购买SSL证书:阿里云免费SSL地址
  • 修改CNAME配置:SSLDNS验证需要在DNS解析规则添加TXT记录,需要删除CNAME或者改为A记录
  • 补全信息:一个免费SSL证书只能绑定一个域名,选择DNS验证

Nginx配置

  • 创建证书目录:mkdir /etc/nginx/cert

  • 进行https配置vim /etc/nginx/sites-available/ssl

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    server {
    listen 443;
    server_name your.domain.com;
    root /var/www/html;
    index index.html index.htm;
    ssl on;
    ssl_certificate cert/cert.pem;
    ssl_certificate_key cert/cert.key;
    ssl_session_timeout 5m;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers on;
    location / {
    try_files $uri $uri/ =404;
    }
    }
  • 配置http重定向到https

    1
    2
    3
    4
    5
    6
    7
    8
    # HTTP server
    server {
    listen 80;
    server_name your.domain.com;

    #rewrite ^(.*)$ https://$host$1 permanent; # Nginx 旧写法,$1匹配()的内容
    return 301 https://$host$request_uri; # Nginx 新写法
    }

参考链接

分享到

nginx反向代理配置

在web开发中,nginx一般被用作网关,配置路由功能,在使用nginx进行反向代理的过程中,碰到一些配置问题,特此文记录

由于项目中涉及到phpjavaweb服务,在使用nginx进行转发过程中,需要通过rewritelocation配合反向代理,配置略微繁琐,废话不多说直接上nginx的配置。

Nginx的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
location / {
# Filename Not Found
if (!-e $request_filename) {
rewrite "^/(.*)$" /index.php last;
}
# Uri contains php-web url
if ( $uri ~ /php-web ) {
rewrite ^/$/index.php last;
}
# Uri not contains php-web url
if ( $uri !~ /php-web ) {
rewrite / /java-web last;
}
try_files $uri $uri/ /index.php;
}
# Filter java-web uri
location ^~ /java-web {
proxy_pass http://ip:port/java-web;
}

由于nginx没有if else之类的结构,通过多个if结构进行过滤,上述配置的项目实现了:

  • 如果请求的uri中含有php-web将进行php web处理
  • 如果请求的uri中不含有php-web将进行java web处理

参考链接

分享到

jenkins自动化部署

目前在部署blog之类的静态网站,每次修改完毕后重新部署,略显繁琐,决定通过jenkins+gitlab来进行自动化部署,至于如何安装jenkins+gitlab不是本文重点,可参考我之前的安装博文

实现自动化的部署原理:jenkins通过捕获gitlabpush event来进行自动部署

JenkinsGitlab配置

  • 配置gitlab认证:

    • 路径:Jenkins-->Credentials-->System-->Global credentials(unrestricted)-->Add Credentials
    • Kind选择Gitlab API token
    • 其中API token填写gitlab中有指定仓库权限的账号
    • ID填写用户账号

    Jenkins配置gitlab认证

    Gitlab API token生成

  • Jenkins配置gitlab连接

    • 路径:系统管理—>系统设置
    • 填写连接名,自定义
    • 填写gitlab访问URL
    • 选择gitlab认证
    • 测试连接

    Jenkins配置gitlab连接

  • Jenkins任务配置

    • General配置:
      • 选择Gitlab connectiongitlab(上面步骤配置gitlab连接的连接名)
      • Gitlab connection填入group/repository name
    • 构建触发器配置:
      • 勾选Build when a change is pushed to GitLab. GitLab CI Service URL:http://ip:port/jenkins/project/repository name
      • 选择push events 事件触发构建
      • 选择分支过滤(此处可以根据不同的需求来使用过滤功能)
      • secret token后面将会填入Gitlab项目中的webhook

    General配置

    构建触发器配置

  • 添加Gitlab webhook

    • gitlab中找到项目—>setting—>Integrations配置
    • URL:填入触发器中配置的GitLab webhook URL
    • Secret Token:构建器中生成的Secret Token
    • 点击Add webhook
    • 点击test—>选择push event进行测试:Hook excuted successfully:HTTP 200即为成功

    Gitlab Add webhook

  • 构建配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #!/usr/bin/env bash
    echo ${WORKSPACE}

    HTML_PATH=/var/www/html
    NGINX_USER=www-data
    NGINX=/usr/sbin/nginx

    # Git archive zip
    cd ${WORKSPACE} && git archive --format zip --output "./output.zip" -0 HEAD

    # Delete older and copy newer
    sudo rm -rf ${HTML_PATH} && sudo mkdir -p ${HTML_PATH} && sudo mv ${WORKSPACE}/output.zip ${HTML_PATH}

    # Unzip
    cd ${HTML_PATH} && sudo unzip output.zip && sudo chown -R $NGINX_USER:$NGINX_USER $HTML_PATH

    # Nginx
    sudo $NGINX -s reload

    # Clean
    sudo rm -rf ${HTML_PATH}/output.zip ${HTML_PATH}/reload-nginx.sh

参考链接

分享到

mybatis多数据源

对于多数据源,一般都是问了解决主从模式或者业务相对复杂需要分库来支持业务的场景。搜索解决方案,要么是采用spring多数据源的方案,要么是利用aop动态切换,感觉有点小复杂,本文采用一种相对简单的解决方案,配置过程中遇到一些问题,特以此文记录

配置yml

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
28
29
30
31
32
33
34
35
36
37
38
39
############################# Multiple DataSource
multi:
datasource:
enabled: true #控制是否开启多数据源
druid:
master:
url: jdbc:mysql://ip:port/master?useUnicode=true&characterEncoding=utf-8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
slave:
url: jdbc:mysql://ip:port/slave?useUnicode=true&characterEncoding=utf-8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
mybatis:
master:
base-packages: com.fly.mapper.master
mapper-locations: classpath:mapper/master/*.xml
slave:
base-packages: com.fly.mapper.slave
mapper-locations: classpath:mapper/slave/*.xml

################################## mybaits
mybatis:
type-aliases-package: com.fly.bean.mysql
# 配置
configuration:
cache-enabled: true # 全局映射器启用缓存
lazy-loading-enabled: true # 查询时,关闭关联对象即时加载以提高性能
aggressive-lazy-loading: false # 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指定),不会加载关联表的所有字段,以提高性能 -->
multiple-result-sets-enabled: true # 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
use-column-label: true # 允许使用列标签代替列名 -->
use-generated-keys: true # 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
auto-mapping-behavior: full # 给予被嵌套的resultMap以字段-属性的映射支持 -->
default-executor-type: batch # 对于批量更新操作缓存SQL以提高性能 -->
default-statement-timeout: 25000 # 数据库超过25000秒仍未响应则超时 -->
mapUnderscoreToCamelCase: true # mybatis 驼峰命名 -->
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 命令行输出 -->

配置数据源

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* 多数据源
* 1. mybatis-spring-boot-starter的MybatisAutoConfiguration不支持Multiple DataSource
* 仅支持Single DataSource或@Primary DataSource生效
* 2. 多数据源的配置必须要配置主库@Primary否则报错
* 或者@EnableAutoConfiguration(exclude = MybatisAutoConfiguration.class)禁止AutoConfig
* 3. 多数据源采用主,副库的配置方式,通过不同包进行隔离
*/
@org.springframework.context.annotation.Configuration
@ConditionalOnProperty(name = "multi.datasource.enabled", havingValue = "true")
public class MultiDataSourceConfig {
/**
* *******************************************************************
* 主数据源配置 @Primary
* *******************************************************************
*/
@org.springframework.context.annotation.Configuration
@ConditionalOnProperty(name = "multi.datasource.enabled", havingValue = "true")
@MapperScan(
basePackages = "com.fly.mapper.master",
sqlSessionFactoryRef = "masterSqlSessionFactory"
)
@Getter
@Setter
@ConfigurationProperties(
prefix = "multi.datasource.mybatis.master"
)
static class MasterDataSourceConfig {

@javax.annotation.Resource
MybatisConfigurationSupport support;

private String[] mapperLocations;

/**
* Primary Druid DataSource
* @return
*/
@ConfigurationProperties(
prefix = "multi.datasource.druid.master"
)
@Primary
@Bean
public DataSource masterDataSource() {
return DruidDataSourceBuilder
.create()
.build();
}

@Bean
@Primary
public SqlSessionFactoryBean masterSqlSessionFactory(
@Qualifier("masterDataSource") DataSource dataSource
) throws Exception {
return support.createSqlSessionFactoryBean(dataSource, mapperLocations);
}

}

/**
* *******************************************************************
* 从数据源配置
* *******************************************************************
*/
@org.springframework.context.annotation.Configuration
@ConditionalOnProperty(name = "multi.datasource.enabled", havingValue = "true")
@MapperScan(
basePackages = "com.fly.mapper.slave",
sqlSessionFactoryRef = "slaveSqlSessionFactory"
)
@Getter
@Setter
@ConfigurationProperties(
prefix = "multi.datasource.mybatis.slave"
)
static class SlaveDataSourceConfig {
private String[] mapperLocations;

@javax.annotation.Resource
MybatisConfigurationSupport support;

/**
* Slave Druid DataSource
* @return
*/
@ConfigurationProperties(
prefix = "multi.datasource.druid.slave"
)
@Bean
public DataSource slaveDataSource() {
return DruidDataSourceBuilder
.create()
.build();
}

@Bean
public SqlSessionFactoryBean slaveSqlSessionFactory(
@Qualifier("slaveDataSource") DataSource dataSource
) throws Exception {
return support.createSqlSessionFactoryBean(dataSource, mapperLocations);
}
}

/**
* *******************************************************************
* 用于简化MybatisProperties的配置
* *******************************************************************
*/
@Component
@ConditionalOnProperty(name = "multi.datasource.enabled", havingValue = "true")
static class MybatisConfigurationSupport {
private final MybatisProperties properties;
private final ResourceLoader resourceLoader;

public MybatisConfigurationSupport(
MybatisProperties properties,
ResourceLoader resourceLoader) {
this.properties = properties;
this.resourceLoader = resourceLoader;
}

/**
* 创建SqlSessionFactoryBean
* @param dataSource
* @param mapperLocations
* @return
*/
public SqlSessionFactoryBean createSqlSessionFactoryBean(DataSource dataSource, String[] mapperLocations) {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
factory.setVfs(SpringBootVFS.class);

/**
* 处理Configuration
* 必须Copy否则会抛出配置多个分页插件的异常
*/
Configuration configuration = new Configuration();
if (properties.getConfiguration() != null) {
// 必须Copy否则会抛出配置多个分页插件的异常
BeanUtils.copyProperties(properties.getConfiguration(), configuration);
}
factory.setConfiguration(configuration);

// 处理MapperLocations
if (!ObjectUtils.isEmpty(mapperLocations)) {
factory.setMapperLocations(resolveMapperLocations(mapperLocations));
}

// if (StringUtils.hasLength(properties.getTypeAliasesPackage())) {
// factory.setTypeAliasesPackage(properties.getTypeAliasesPackage());
// }

return factory;
}

/**
* MapperLocations 转化为Resource[]
* @param mapperLocations
* @return
*/
public Resource[] resolveMapperLocations(String[] mapperLocations) {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<Resource> resources = new ArrayList<>();
if (mapperLocations != null) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException ignore) {
// ignore
ignore.printStackTrace();
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
}
}

参考链接

分享到

爬虫设计

一个设计良好的爬虫必须满足如下需求:

  • 分布式:多机分布式执行
  • 可伸缩性:爬虫结构能够通过额外的机器和带宽来提交爬虫速度
  • 性能和有效性:爬虫系统必须有效使用各种系统资源,例如Cpu,内存和网络IO
  • 更新:因为数据来源经常更新,爬虫应该取得已经获取数据的新的拷贝
  • 可扩展性:为了能够支持新的数据格式和新的抓取协议,爬虫架构应该设计成模块化的形式

爬虫模块

  • URL Frontier(url队列)
  • DNS模块
  • 获取模块(使用http协议获取url代表的数据或页面)
  • 解析模块提取api数据
  • 重复消除模块决定一个解析出来的链接是否已经在URL Frontier或者最近下载过

爬虫设计

分享到

nexus的npm配置

nexus是可以搭建maven,npm,docker,pypi私有仓库的工具,本文记录npm的安装配置

配置nexus的npm

  • 添加认证:按图示进入realms设置页,将npm Bearer Token Realm加入active即可。

    npm添加认证

  • npm-taobao-proxy

    1
    2
    3
    Remote storage:https://registry.npm.taobao.org/
    Use the Nexus truststore:勾选
    Blob store:npm
  • npm-3rd-hosted

    1
    2
    Blob store:npm
    Deployment policy: Allow redeploy
  • npm-group(注意Members顺序)

    1
    2
    3
    4
    Blob store:npm
    Members:
    - npm-3rd-hosted
    - npm-taobao-proxy

配置本地npm

  • 用户级别配置

  • ~/.npmrc(若没有需要新建)

  • .npmrc配置如下:

    1
    registry = http://ip:port/nexus/repository/npm-group/

参考链接

分享到

nexus的maven配置

nexus是可以搭建maven,npm,docker,pypi私有仓库的工具,本文记录maven的安装配置

配置nexus的maven

  • maven-aliyun-proxy

    1
    2
    Remote storage:http://maven.aliyun.com/nexus/content/groups/public
    Blob store:maven
  • maven-cloudera-proxy

    1
    2
    Remote storage:https://repository.cloudera.com/artifactory/cloudera-repos/
    Blob store:maven
  • maven-hosted-snapshots

    1
    2
    3
    Version policy: Snapshot
    Blob store:maven
    Deployment policy: Allow redeploy
  • maven-hosted-releases

    1
    2
    3
    Version policy: Release
    Blob store:maven
    Deployment policy: Allow redeploy
  • maven-times-group(注意Members顺序)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Blob store:maven
    Members:
    - maven-aliyun-proxy
    - maven-cloudera-proxy
    - maven-hosted-releases
    - maven-hosted-snapshots
    - maven-central
    - maven-releases
    - maven-snapshots

配置本地maven

  • 全局配置

    • mac下brew的配置:/usr/local/Cellar/maven/3.5.2/libexec/conf/settings.xml
    • linux下的配置:$MAVEN_HOME/conf/settings.xml
  • 用户级别配置

    • ~/.m2/settings.xml(若没有需要新建)
  • settings.xml配置如下:

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <settings>
    <mirrors>
    <mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://ip:port/nexus/repository/maven-times-group/</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>

    <servers>
    <!--server username and password -->
    <server>
    <id>nexus-releases</id>
    <username>admin</username>
    <password>admin123</password>
    </server>
    <server>
    <id>nexus-snapshot</id>
    <username>admin</username>
    <password>admin123</password>
    </server>
    </servers>

    </settings>
  • 发布项目到nexus仓库配置

    在项目的pom.xml如下配置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <!--nexus 设置-->
    <distributionManagement>
    <repository>
    <id>nexus-releases</id>
    <name>Nexus Release Repository</name>
    <url>http://ip:port/nexus/repository/maven-hosted-releases/</url>
    </repository>
    <snapshotRepository>
    <id>nexus-snapshot</id>
    <name>Nexus Snapshot Repository</name>
    <url>http://ip:port/nexus/repository/maven-hosted-snapshots/</url>
    </snapshotRepository>
    </distributionManagement>
分享到