aliyun在docker容器服务里配置elasticsearch5

第一步,制作镜像。官方镜像没有x-pack。

FROM kibana:5.6.3
ENV TIME_ZONE Asia/Shanghai
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "${TIME_ZONE}" > /etc/timezone
RUN kibana-plugin install x-pack
EXPOSE 5601

第二部,多节点发布
这里举例发布一个主节点,一个数据节点。
aliyun的容器里配置

elasticsearch:
      container_name: elasticsearch
      restart: always
      environment:

        - LANG=C.UTF-8
        - JAVA_HOME=/docker-java-home/jre

        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      expose:
        - '9200:9200/tcp'
        - '9300:9300/tcp'
      memswap_limit: 0
      labels:
        aliyun.scale: '1'
      command:

        - elasticsearch 
        - '-E'
        - cluster.name=searcher #所有节点设置成一样的
        - '-E'
        - node.master=true #主节点true,数据节点false
        - '-E'
        - node.name=elasticsearch #节点名不能一样
  
        - '-E'
        - network.host=172.19.0.27#这里需要些容器的ip否则互相找不到,而且不能加引号
        - '-E'
        - discovery.zen.ping.unicast.hosts=172.19.0.32:9300 #互相发现的节点和ip
      shm_size: 0
      #image: 'elasticsearch:5.6.3' #如果不装或手动装xpack的话可以用官方镜像。官方镜像安装xpack比较消内存,可能因内存不足提示killed安装失败。
      image: 'xx[这里是你的镜像]x/elastic_search:0.1.0'
      memswap_reservation: 0
      volumes:
        - esdata1:/usr/share/elasticsearch/data
      kernel_memory: 0
      mem_limit: 0

swagger-ui在spring-cloud里无法设置basepath的坑

在springcloud里网关做的路由,隐藏了微服务的名称。
单发现无论怎么设置host和basepath都没效果,结果发现是版本的坑
用2.6.1是可以的2.7设置无效。

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>


	

springcloud中缓存的小坑坑

在springboot中使用缓存是很随意的,dao中能加缓存 service中能加缓存,crontroller中都能加缓存。
但如果把springcloud包引入后会发现缓存不能随便用了,只能在dao层中使用
别的层如果还想用缓存注解尝试过把核心库中一个jar换成早期测试版可以办到。。。但这样会让微服务间无法正常请求数据。

目前只能在dao中使用缓存
参数设置方式只能是root.args[0],root.args[0].id 这种,不能用其他的别名

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command config

在阿里云部署springboot项目发现异常。在测试服是正常的,正式服使用了aliyun的redis服务

异常:
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command config

应该是阿里云对redis进行了限制

需要增加:
@Configuration
public class RedisConfig {
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}

传base64png图片到AliyunOSS

使用场景是想做图片裁剪,直接传oss

基本步骤:
1,图片裁剪,产生base64字符串,略
2,base64转blob
3,blob添加到表单
4,ajax上传

具体:

/**
     * 将以base64的图片url数据转换为Blob
     * @param urlData
     *            用url方式表示的base64图片数据
     */
    function convertBase64UrlToBlob(urlData){
        var bytes=window.atob(urlData.split(',')[1]);        //去掉url的头,并转换为byte
        //处理异常,将ascii码小于0的转换为大于0
        var ab = new ArrayBuffer(bytes.length);
        var ia = new Uint8Array(ab);
        for (var i = 0; i < bytes.length; i++) {
            ia[i] = bytes.charCodeAt(i);
        }
        return new Blob( [ab] , {type : 'image/png'});
    }

3添加到表单:

 var formParam = new FormData();
formParam.append("file",convertBase64UrlToBlob(base64Codes));

4,ajax提交:

$.ajax({
            type: 'POST',
            url: host ,
            data:formParam ,
...

OSS需要额外增加授权:具体参考官方例子
额外传这些参数:

 formParam.append("key",g_object_name);
        formParam.append("policy",policyBase64);
        formParam.append("OSSAccessKeyId",accessid);
        formParam.append("success_action_status",'200');
        formParam.append("signature",signature);

phabricator 无法安装在阿里云rds上

phabricator 报如下错误
Replicating Master
Database host “[数据库地址]” is configured as a master, but is replicating another host. This is dangerous and can mangle or destroy data. Only replicas should be replicating. Stop replication on the host or reconfigure Phabricator.

然后发现原因是RDS自动做了主从备份,据说还是双向,而且无法关闭。
只能从程序下手了,搜索代码发现在

switch ($ref->getReplicaStatus()) {
      case PhabricatorDatabaseRef::REPLICATION_MASTER_REPLICA:
     break;<----新增的
        $message = pht(
          'Database host "%s" is configured as a master, but is replicating '.
          'another host. This is dangerous and can mangle or destroy data. '.
          'Only replicas should be replicating. Stop replication on the '.
          'host or reconfigure Phabricator.',
 $ref->getRefKey());

https://secure.phabricator.com/source/phabricator/browse/master/src/applications/config/check/PhabricatorDatabaseSetupCheck.php;326d5bf8004ece51fbb44146766f5ddf765f1159
这个文件的174行左右判断验证了

然后我在case后直接写了个break,绕过了验证,反正是可以用了

springboot 使用druid做连接池 sql统计不显示等问题

参考 http://www.tuicool.com/articles/QRRJz2J
就是网上50%的转载帖都没写需要自己写个
public DataSource dataSource(){}
方法。不写的结果是 application.properties中的连接池配置数据都没生效!

@Component
@ConfigurationProperties(prefix = "spring.datasource")
public class DruidConfig {
    private String url;

    private String username;

    private String password;

    private String driverClassName;

    private int initialSize;

    private int maxActive;

    private int minIdle;

    private int maxWait;

    private long timeBetweenEvictionRunsMillis;

    private long minEvictableIdleTimeMillis;

    private String validationQuery;

    private boolean testWhileIdle;

    private boolean testOnBorrow;

    private boolean testOnReturn;

    private boolean poolPreparedStatements;

    private int maxPoolPreparedStatementPerConnectionSize;

    private String filters;

    public DruidConfig() {
    }

    public DruidConfig(String url, String username, String password, String driverClassName, int initialSize, int maxActive, int minIdle, int maxWait, long timeBetweenEvictionRunsMillis, long minEvictableIdleTimeMillis, String validationQuery, boolean testWhileIdle, boolean testOnBorrow, boolean testOnReturn, boolean poolPreparedStatements, int maxPoolPreparedStatementPerConnectionSize, String filters) {
        this.url = url;
        this.username = username;
        this.password = password;
        this.driverClassName = driverClassName;
        this.initialSize = initialSize;
        this.maxActive = maxActive;
        this.minIdle = minIdle;
        this.maxWait = maxWait;
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
        this.validationQuery = validationQuery;
        this.testWhileIdle = testWhileIdle;
        this.testOnBorrow = testOnBorrow;
        this.testOnReturn = testOnReturn;
        this.poolPreparedStatements = poolPreparedStatements;
        this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
        this.filters = filters;
    }

    @Bean
    @Primary
    public DataSource dataSource() throws Exception{
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl(this.url);
        druidDataSource.setUsername(this.username);
        druidDataSource.setPassword(this.password);
        druidDataSource.setDriverClassName(this.driverClassName);
        druidDataSource.setInitialSize(this.initialSize);
        druidDataSource.setMaxActive(this.maxActive);
        druidDataSource.setMinIdle(this.minIdle);
        druidDataSource.setMaxWait(this.maxWait);
        druidDataSource.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis);
        druidDataSource.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis);
        druidDataSource.setValidationQuery(this.validationQuery);
        druidDataSource.setTestWhileIdle(this.testWhileIdle);
        druidDataSource.setTestOnBorrow(this.testOnBorrow);
        druidDataSource.setTestOnReturn(this.testOnReturn);
        druidDataSource.setPoolPreparedStatements(this.poolPreparedStatements);
        druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(this.maxPoolPreparedStatementPerConnectionSize);
        druidDataSource.setFilters(this.filters);
        try {
            if(null != druidDataSource) {
                druidDataSource.setFilters("wall,stat");
                druidDataSource.setUseGlobalDataSourceStat(true);
                druidDataSource.init();
            }
        } catch (Exception e) {
            throw new RuntimeException("load datasource error, dbProperties is :", e);
        }

        return druidDataSource;
    }
...set get
}

主机重置造成的面登录验证失效REMOTE HOST IDENTIFICATION HAS CHANGED!

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
2b:2c:dd:99:a8:1f:a6:e2:b1:59:0d:5d:40:04:df:21.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:4
RSA host key for videoapi3 has changed and you have requested strict checking.
Host key verification failed.

videoapi3代表主机名
简单的解决办法 :
删除/root/.ssh/known_hosts 中对应的主机记录,重新用ssh连接下就可以了