月度归档:2025年06月

Jenkins 脚本命名行

清理构建历史

1、删除 历史构建


//项目名称
def jobName = "you-job-name"
//删除小于等于64的构建历史
def maxNumber = 40
Jenkins.instance.getItemByFullName(jobName).builds.findAll {
  it.number <= maxNumber
}.each {
  it.delete()
}

2、清空所有构建

//项目名称
def jobName = "geostar-xuncha-portal-fat"
def item = Jenkins.instance.getItemByFullName(jobName);
item.builds.each {
  it.delete()
}
// 更新构建Number
item.updateNextBuildNumber(1)

centos 升级PHP版本到7.3

服务器PHP版本从7.2升级到7.3过程,其实只需要很简单的步骤

  • 停止PHP服务
  • 移除旧版PHP
  • 设置新版本rpm库
  • 下载安装新版并重启服务

移除旧版

# 停止当前服务
systemctl stop php-fpm
# 停止Nginx服务
systemctrl stop nginx
# 查看已安装的PHP版本
yum list installed |grep php

查看已安装的版本

请务必找个地方记录已经安装的模块

后续重新安装的时候也要把这些模块安装上

[root@long ~]# yum list installed |grep php
Failed to set locale, defaulting to C
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
mod_php72w.x86_64                   7.2.17-1.w7                        @webtatic
php72w-cli.x86_64                   7.2.32-1.w7                        @webtatic
php72w-common.x86_64                7.2.32-1.w7                        @webtatic
php72w-devel.x86_64                 7.2.32-1.w7                        @webtatic
php72w-fpm.x86_64                   7.2.32-1.w7                        @webtatic
php72w-gd.x86_64                    7.2.32-1.w7                        @webtatic
php72w-mbstring.x86_64              7.2.32-1.w7                        @webtatic
php72w-mysqlnd.x86_64               7.2.32-1.w7                        @webtatic
php72w-pdo.x86_64                   7.2.32-1.w7                        @webtatic
php72w-xml.x86_64                   7.2.32-1.w7                        @webtatic

移除版本

# 移除所有PHP
yum remove php*
# 查看是否清除干净了
yum search php

安装新版

# EPEL源
yum install epel-release

# REMI源,centos7的使用下面的地址,其他版本自行去官网查看
# 这里下载的时候会很慢,要耐心等待,如果下载不了就要自行找镜像了
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

# 更新一下库
yum update

# Yum 源工具
yum install yum-utils

# 查看是否有出现php73的版本了
yum search php73

# 如果出现这样的说明Yum还是没有设置正确,需要重新设置一下
[root@long ~]# yum search php73
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
 * webtatic: us-east.repo.webtatic.com
Warning: No matches found for: php73
No matches found

开始安装

装回上面记录已经卸载的版本

yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml

重启服务

# 默认安装后的命令叫php73,我们需要改为php,这样composer才能正常工作
cp /usr/bin/php73 /usr/bin/php

# 查看PHP版本
php -v

# 重启服务
systemctl enable php73-fpm
systemctl start php73-fpm
systemctrl start nginx

最后查看自己的PHP程序是否都正常了

Jenkins 构建时出现Room数据库Each bind variable in the query must have a matching method parameter. Cannot find method parameters for

在Jenkins构建时候发现这样的一般报错信息:

warning: Current JDK version 1.8.0_242-b08 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.
error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :xMax, :yMax. - com.geostar.android.sdk.common.dao.IMediaDao.queryMedias(double, double, double, double)
error: Unused parameters: arg2,arg3 - com.geostar.android.sdk.common.dao.IMediaDao.queryMedias(double, double, double, double)
2 errors
1 warning

问题很明显了,使用Room插件的时候生成的参数被替换成arg2arg3 导致无法绑定参数信息。

项目中使用的room插件是版本是2.3.0,如果是低于这个版本的还是没有提示这一行信息的:warning: Current JDK version 1.8.0_242-b08 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.

这样提示就很明显了,Jenkins是使用docker来搭建的,那么只需要将JDK升级到11即可,可以再docker中使用JAVA_HOME的环境变量。

使用的docker-compose文件来搭建,所以只需要指定一下环境参数即可,其他的方法可以找网上参考。

指定environment环境变量

version: '3'
services:
    jenkins:
        hostname: jenkins
        container_name: jenkins
        image: jenkins/jenkins
        restart: always
        environment:
            JAVA_HOME: /var/jenkins_home/tools/jdk/jdk-11/
        ports:
            - "8080:8080"
        volumes:
            - /data/docker/jenkins/:/var/jenkins_home
        networks:
            - app_net

networks:
  app_net:
    driver: bridge
    ipam:
      config:
        - subnet: 10.10.0.0/16

Java 等分数组

将一个数组分割成相等的数组。
如将1234567等分以3个为一组等分,结果为[123]、[456]、[7]

实现算法如下

 /**
     * 等分数组
     * @param source 来源
     * @param size 切分数量
     * @param <T> 类型
     * @return 等分后的结果
     */
    public static <T> List<List<T>> divide(List<T> source, int size) {
        if (size <= 0) {
            throw new IllegalArgumentException("等分大小必须大于0");
        }
        if (source == null || source.size() <= 0) {
            return null;
        }
        List<List<T>> result = new ArrayList<>();
        int cursor = 0;
        int total = source.size();
        while (cursor < total) {
            int index = Math.min(cursor + size, total);
            List<T> item = source.subList(cursor, index);
            result.add(item);
            cursor = index;
        }
        return result;
    }

docker 安装SSH

首先,docker并不是虚拟机,一般并不存在用户访问控制,但有些时候想让用户通过密码才能访问虚拟集命令行,则可以通过ssh连接来实现。

但有个前提就是不能让用户直接接触宿主机,因为使用docker execdocker cp等,是可以不需密码直接访问docker内部文件。

下面开始正文为python-slim镜像配置ssh访问

为debian python 镜像安装sshd

启动docker image时可以指定端口映射 docker run -ditp 23:22 [imageID]

安装过程

#!/bin/bash
# 更新安装源
cd /etc/apt/
mv sources.list sources.list.backup
echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > sources.list
echo "deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib" >> sources.list
echo "deb http://mirrors.aliyun.com/debian-security buster/updates main" >> sources.list
echo "deb-src http://mirrors.aliyun.com/debian-security buster/updates main" >> sources.list
echo "deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> sources.list
echo "deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib" >> sources.list
echo "deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> sources.list
echo "deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib" >> sources.list
# 更新软件源
apt-get update
# 安装SSHD
apt-get install openssh-server -y
# 安装完成后启动服务
service ssh start
# 查看是否启动成功
ps -e
# 看看是否出现sshd
# 配置SSH
vim /etc/ssh/sshd_config
# 修改允许root登录
PermitRootLogin yes
# 重启ssh服务
/etc/init.d/ssh restart

# 修改root用户
passwd root

生成docker镜像

配置好环境后,生成自己的镜像文件

# docker commit [容器ID] [名称]:[版本]
docker commit 42ee9eb65dcb jenkins-ssh:1.0

docker 配置开机自动启动脚本

配置脚本

#!/bin/bash
/etc/init.d/ssh start
java -jar /usr/share/jenkins/jenkins.war

配置docker文件


version: '3'
services:
    jenkins:
        hostname: jenkins
        container_name: jenkins-java
        image: jenkins-ssh:1.0
        restart: always
        privileged: true
        user: root
        command: /bin/bash /var/jenkins_home/run.sh
        ports:
            - "8083:8080"
            - "23:22"
        volumes:
            - /data/docker/jenkins-java/:/var/jenkins_home

参考链接:https://blog.csdn.net/xzl9811wl/article/details/107060382

nexus3 启动失败, Cannot open local storage 解决方法

nexus oss 3 一直运行得没什么问题,忽然发现运行特别慢然后到服务器去重启,莫名其妙一直启动失败,查看日志发现如下报错信息:

2021-05-24 08:09:50,048+0000 ERROR [FelixStartLevel]  *SYSTEM org.sonatype.nexus.extender.NexusContextListener - Failed to start nexus
com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage '/nexus-data/db/component' with mode=rw
        DB name="component"
        at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:323)
        at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:259)
        at org.sonatype.nexus.orient.DatabaseManagerSupport.connect(DatabaseManagerSupport.java:178)
        at org.sonatype.nexus.orient.DatabaseManagerSupport.createInstance(DatabaseManagerSupport.java:312)
        at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
        at org.sonatype.nexus.orient.DatabaseManagerSupport.instance(DatabaseManagerSupport.java:289)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
        at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
        at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:401)
        at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734)
        at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159)
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
        at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:650)
        at org.sonatype.nexus.orient.restore.RestoreServiceImpl.doStart(RestoreServiceImpl.java:76)
        at org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.start(StateGuardLifecycleSupport.java:67)
        at org.sonatype.nexus.common.stateguard.MethodInvocationAction.run(MethodInvocationAction.java:39)
        at org.sonatype.nexus.common.stateguard.StateGuard$TransitionImpl.run(StateGuard.java:193)
        at org.sonatype.nexus.common.stateguard.TransitionsInterceptor.invoke(TransitionsInterceptor.java:56)
        at org.sonatype.nexus.extender.NexusLifecycleManager.startComponent(NexusLifecycleManager.java:199)
        at org.sonatype.nexus.extender.NexusLifecycleManager.to(NexusLifecycleManager.java:111)
        at org.sonatype.nexus.extender.NexusContextListener.moveToPhase(NexusContextListener.java:304)
        at org.sonatype.nexus.extender.NexusContextListener.frameworkEvent(NexusContextListener.java:201)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1429)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
        at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.cutTill(ODiskWriteAheadLog.java:919)
        at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.makeFullCheckpoint(OAbstractPaginatedStorage.java:3706)
        at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.recoverIfNeeded(OAbstractPaginatedStorage.java:3937)
        at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:288)
        ... 30 common frames omitted

一开始以为是/nexus-data/db/component 的权限问题,但一直以来启动都没有问题,重新设置 777 权限后仍然没有效果。

解决方法

最后在网上找到了解决方法:把 /nexus-data/db/component 下的出现 0字节wal文件全部删掉,重新启动即可!!

GitHub上的图片显示不出来解决方法

原因是被墙了,在Host文件中添加一下映射就行。


# GitHub Start 
140.82.113.3      github.com
140.82.114.20     gist.github.com

151.101.184.133    assets-cdn.github.com
151.101.184.133    raw.githubusercontent.com
151.101.184.133    gist.githubusercontent.com
151.101.184.133    cloud.githubusercontent.com
151.101.184.133    camo.githubusercontent.com
151.101.184.133    avatars0.githubusercontent.com
199.232.68.133     avatars0.githubusercontent.com
199.232.28.133     avatars1.githubusercontent.com
151.101.184.133    avatars1.githubusercontent.com
151.101.184.133    avatars2.githubusercontent.com
199.232.28.133     avatars2.githubusercontent.com
151.101.184.133    avatars3.githubusercontent.com
199.232.68.133     avatars3.githubusercontent.com
151.101.184.133    avatars4.githubusercontent.com
199.232.68.133     avatars4.githubusercontent.com
151.101.184.133    avatars5.githubusercontent.com
199.232.68.133     avatars5.githubusercontent.com
151.101.184.133    avatars6.githubusercontent.com
199.232.68.133     avatars6.githubusercontent.com
151.101.184.133    avatars7.githubusercontent.com
199.232.68.133     avatars7.githubusercontent.com
151.101.184.133    avatars8.githubusercontent.com
199.232.68.133     avatars8.githubusercontent.com
# GitHub End

laravel出现Too Many Attempts 报错解决方法

这是因为Laravel从5.2开始,增加了一个Throttle的中间件。在app/Http/Kernel.php文件,你就会发现,api路由是默认使用了这个中间件的。
这个中间件的作用是限制同一个Ip访问同一个Api的访问次数,模式是1分钟内只能访问60次,超过60次,则会返回Too Many Attempts 429状态。需要等待1分钟后才可以访问
修改方法:打开app/Http/Kernel.php文件 修改访问次数

 /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            EncryptCookies::class,
            AddQueuedCookiesToResponse::class,
            StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            ShareErrorsFromSession::class,
            VerifyCsrfToken::class,
            SubstituteBindings::class,
        ],

        'api' => [
            'throttle:800,1', // 默认是1分钟60次,这里修改大一点
            'bindings',
        ],
    ];