docker安装minio
项目调试需要本地搭建一个minio,记录一下docker命令
docker run -d -p 9000:9000 -p 9001:9001 \--net=els \--name minio \-e "MINIO_ROOT_USER=minio" \-e "MINIO_ROOT_PASSWORD=minio123" \-v /Users/zhangyuhan/Work/dev-env/minio/data:/data \-v /Users/zhangyuhan/Work/dev-env/minio/config:/root/.minio \minio/minio server /data --console-address ":9001" -address ":9000"
java:Path与Files类
jDK1.7引入了新的IO操作类,java.nio.file包下的Path接口和Files类。然而网上的好多教程仍然用着比较老旧的File类。这里整理一下新的用法。
创建文件和目录创建文件和目录非常简单。我们可以使用Files类的createFile()方法和createDirectory()方法来创建文件和目录
import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import java.io.IOException;public class CreateFileAndDirectory { public static void main(String[] args) throws IOException { //文件 Path pathToFile = Paths.get("example.txt"); //目录 Path pathToDir = Paths.get(" ...
java split()方法输出示例
在java里,split()方法如果只传入分割字符,那么会自动去除结尾的空字符串。
以前一直不知道,到底写了多少隐藏的bug,ヽ(゜ロ゜;)ノ
情况1String str = "6000,5000";String[] s = str.split(",");System.out.println(Arrays.toString(s));// [6000, 5000]System.out.println(s.length);// 2
情况2String str = "6000,5000";String[] s = str.split(",", -1);System.out.println(Arrays.toString(s));// [6000, 5000]System.out.println(s.length);// 2
情况3String str = "6000,";String[] s = str.split(",");System.out.println(Array ...
配置ssl证书示例
server { listen 443 ssl; #修改端口号增加ssl server_name xxxx.cn; # 该域名必须对应当前nginx所在的服务器(通过dns解析的ip和nginx服务器的公网ip相同) #server_name _; #ssl on; #注释或删除ssl on ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置 ssl_prefer_server_ciphers on; #指定PEM格式的证书文件 ssl_certificate xxxx.pem; #指定PEM格式的私钥文件 ssl_certificate_key xxxx.key; location / { proxy_set_head ...
docker安装redis
docker pull redis:7.2docker run \-p 6379:6379 \--name redis-7.2 \--restart=always \--network=els \-d redis:7.2
m1,docker安装rabbitmq
基本安装# 拉镜像docker pull rabbitmq:3-management# 运行容器。# 项目用到mqtt,所以额外开启了一个mqtt插件# 可以把--network去掉,或者自己建个自定义网络elsdocker run -d --name rabbitmq-3 --network els -p 5672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=123456 -e RABBITMQ_PLUGINS_ENABLE=rabbitmq_mqtt rabbitmq:3-management
开启延时插件首先下载并启动镜像
docker pull rabbitmq:3.10.6-managementdocker run -d \--name rabbitmq \-e RABBITMQ_DEFAULT_USER=admin \-e RABBITMQ_DEFAULT_PASS=admin \-p 15672:15672 -p 5672:5672 -p 25672:25672 ...
m1,docker安装mysql5.7
mysql5.7版本没有适合arm架构的docker镜像但是网上大佬说x86镜像的mysql5.7一样能在macbook m1上运行自己试验了,果然可以。整理一下
# 拉取镜像(--platform linux/x86_64一定要加,要不然会报错,提示搜不到适合arm架构的mysql:5.7镜像)docker pull --platform linux/x86_64 mysql:5.7# 建立目录mkdir /Users/zhangyuhan/Work/dev-env/mysql-5.7/logmkdir /Users/zhangyuhan/Work/dev-env/mysql-5.7/datamkdir /Users/zhangyuhan/Work/dev-env/mysql-5.7/conf# 建立配置文件vim /Users/zhangyuhan/Work/dev-env/mysql-5.7/conf/my.cnf# 归纳整理mysql:5.7的一些通用配置[client]default-character-set=utf8mb4[mysql]default-character- ...
docker安装nginx
# 拉取镜像# 本文章以1.24为例,读者可以自行替换为其他的版本,流程基本不变。docker pull nginx:1.24# 运行容器,该容器只为复制配置文件,后续会删除docker run -p80:80 --name nginx-1.24 -d nginx:1.24# 得到容器id:e6c27ac9bc13# 创建映射目录# 所有的映射目录根目录为/Users/zhangyuhan/Work/dev-env/nginx-1.24,可自行替换mkdir /Users/zhangyuhan/Work/dev-env/nginx-1.24cd /Users/zhangyuhan/Work/dev-env/nginx-1.24mkdir confmkdir htmlmkdir logs# 将容器内的nginx配置文件夹拷贝到conf文件下docker cp e6c27ac9bc13:/etc/nginx /Users/zhangyuhan/Work/dev-env/nginx-1.24/conf# 此时目录结构为conf/nginx/一堆配置文件,所以需要将所有的配置文件拷贝conf下 ...
elasticsearch通过docker在mackbook m1安装
主要目的:安装elasticsearch和kibana,解决kibana无法连接elasticsearch导致server is not ready yet的问题
建立docker网络els# 建立docker network create els# 查看:有name:els,成功docker network lsNETWORK ID NAME DRIVER SCOPE12f31e2d6df1 bridge bridge local4e3cc13000ef els bridge locale0cb50b3dee5 host host local18f13202e657 none null local
安装elasticsearch# 建立映射文件夹mkdir /Users/zhangyuhan/Work/dev-env/elasticsearch-7.16.2/configmkdir /Users/zhangyuhan/Work/dev-env/elasticsearch-7. ...
redis主从、哨兵、集群搭建
博客参考
引申:如何给redis主从、哨兵模式添加认证密码
注意:如果三台服务器已经启动了主从和哨兵,那么需要先在三台服务器上关闭所有的哨兵,再在三台服务器上关闭所有的主从
服务器关闭顺序要求:先关从节点(从节点之间不分顺序),再关主节点
如果不知道哪个是主节点,可以通过redis-cli进入redis控制台输入info replication查看主节点的ip
#查看redis服务和哨兵的进程命令:ps -ef|grep redis
redis服务的关闭命令如下:
./redis-cli shutdown
redis哨兵的关闭命令如下
kill -9 哨兵进程
配置认证密码在上面博客配置的基础上执行如下步骤:
三台服务器的redis.conf添加如下配置
requirepass "123456"masterauth "123456"
三台服务器sentinel.conf添加如下配置
# 在上面博客里已经配置了sentinel monitor mymaster 10.13.181.97 6379 2# 新增的配置,要求写在上面配置的 ...
redis哨兵模式在springboot下的配置
springboot连接单体的redis配置如下
spring: redis: database: 0 host: 127.0.0.1 port: 6379 password:
但是如果是redis哨兵模式,那么上述配置会报错,无法连接redis。
正确连接redis哨兵模式在springboot中的配置如下
# Redis连接信息spring: redis: database: 0 # Redis数据库索引(默认为0) password: # timeout: 5000 # Redis超时时间(单位:毫秒) sentinel: master: mymaster # Sentinel主节点名称 nodes: 192.168.10.11:26379,192.168.10.12:26379,192.168.10.13:26379 # Sentinel节点地址列表 # 注意端口是26379,即哨兵模式的端口,不是6379,redis服务的端口
公网nfs配置踩坑
背景最近需要迁移一个老的单体项目到私有云环境做集群,之前的上传文件都是直接存储在磁盘上,而且体积超大,而且项目架构又从单体过渡到多个实例集群。为了能够读取到之前的上传文件,采用nfs将原先服务器上存储文件的路径挂载到新的私有云环境的多个集群服务器上。网上有很多关于nfs的配置讲解,但是大多是局域网。我这里因为两个环境都是独立封闭,只通过堡垒机提供外部访问,因此需要配置公网的nfs,踩了不少坑。在这里总结一下相关经验。
安装nfs安装的过程实际上很简单。我参考的这篇博客Centos7 NFS服务的安装以及使用
唯一值得注意的是,私有云环境不能用yum,因此我是上传的多个rpm包来手动执行的安装,这里是参考的这篇博客nfs无网络条件rpm安装
如果需要nfs的整合rpm包的话,可以发邮件给我
配置配置这里是踩坑最多的地方,内网的环境下大可以关闭防火墙,而外网环境下不可能对外暴漏所有的端口,因此要搞明白nfs到底配置那些端口开放才能让客户端成功挂载。我这里也是和同事不断的查资料,并且试错最后才成功的。👏🏻👏🏻👏🏻👏🏻👏🏻👏🏻
服务端还要额外配置5个端口# 修改vim ...
mysqldump定时备份
创建脚本创建一个新的Shell脚本文件,比如backup_mysql.sh
#!/bin/bash# MySQL数据库连接信息DB_USER="your_username"DB_PASSWORD="your_password"DB_NAME="your_database"# 备份保存路径BACKUP_DIR="/path/to/backup/directory"# 创建备份文件名,格式为:数据库名_年月日时分秒.sqlBACKUP_FILE="$BACKUP_DIR/$DB_NAME_$(date +%Y%m%d%H%M%S).sql"# 使用mysqldump命令备份数据库mysqldump -u$DB_USER -p$DB_PASSWORD $DB_NAME > $BACKUP_FILE# 检查备份是否成功if [ $? -eq 0 ]; then echo "MySQL backup completed successfully. Backup saved t ...
js获取当前页面的地址
例1
// 地址:http://www.php230.com/fisker/post/0703/window.location.html?ver=1.0&id=6#imherewindow.location.host // URL 的主机部分:www.php230.com,如果没有域名会返回192.168.0.1:8080window.location.protocol// URL 的协议部分:http:window.location.pathname// URL 的路径部分(就是文件地址):/fisker/post/0703/window.location.htmlwindow.location.search// 查询(参数)部分:?ver=1.0&id=6
例2
window.location.href → 'https://www.jianshu.com/search?q=JS#comments' .origin → 'https://www.jianshu.com' ...
动态sql常用总结
动态 SQL 是 MyBatis 的强大特性之一。在 JDBC 或其它类似的框架中,开发人员通常需要手动拼接 SQL 语句。根据不同的条件拼接 SQL 语句是一件极其痛苦的工作。例如,拼接时要确保添加了必要的空格,还要注意去掉列表最后一个列名的逗号。而动态 SQL 恰好解决了这一问题,可以根据场景动态的构建查询。
动态SQL(code that is executed dynamically),它一般是根据用户输入或外部条件动态组合的SQL语句块。动态SQL能灵活的发挥SQL强大的功能、方便的解决一些其它方法难以解决的问题。相信使用过动态SQL的人都能体会到它带来的便利,然而动态SQL有时候在执行性能 (效率)上面不如静态SQL,而且使用不恰当,往往会在安全方面存在隐患 (SQL 注入式攻击)。
MyBatis动态 sql 的特性Mybatis 动态 sql 是做什么的?Mybatis 动态 sql 可以让我们在 Xml 映射文件内,以标签的形式编写动态 sql,完成逻辑判断和动态拼接 sql 的功能。
Mybatis 的 9 种 动 态 sql 标 签有哪些?
动态 sql 的执行原 ...
event.path过期
起因是 chromium 开发团队认为 Event.path 属于非标准 API,会导致 Firefox 等其他浏览器的兼容性问题,于是他们决定将其删除。目前这个变更在 chrome 108 属于灰度阶段,在chrome 109 上会全面应用,webview 则是从 109 版本开始逐步禁用
在chrome浏览器中,event.path表示触发Dom事件的元素一路冒泡到window的所有元素但是在在Firefox、Safari、以及Chrome dev浏览器中,event中并没有path这个属性。在Firefox、Safari、以及Chrome dev浏览器中可以通过event.composedpath()获取
// 旧的写法let evt = event || window.event;let path = evt.path // 此时path为undefined// 新的写法(兼容所有主流浏览器)var evt = event || window.event;let path = evt.path || (evt.composedPath && evt.compos ...
GROUP_CONCAT()函数的说明
首先我们来建立一个测试的表和数据,代码如下
CREATE TABLE `per` ( `id` int(11) NOT NULL AUTO_INCREMENT, `pname` varchar(50) DEFAULT NULL, `page` int(11) DEFAULT NULL, `psex` varchar(50) DEFAULT NULL, `paddr` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;INSERT INTO `per` VALUES ('1', '王小华', '30', '男', '北京');INSERT INTO `per` VALUES ('2', '张文军', '24', '男', '上海' ...
jQuery选择器赋值与取值
单选框radio<input type="radio" name="jclx" value="1" title="当前期次" checked><input type="radio" name="jclx" value="2" title="当前月份">
// 获取radio选中的值$("input[name='jclx']:checked").val()// 设置radio选中的值$("input[name='jclx'][value='1']").prop("checked", true)// 或者$("input[name=jclx]").attr("checked",'2');// 设置value=2的项目为当前选中项 / ...
table动态纵向合并单元格
需求:点击layui动态表格的某一行,给这行添加一个背景颜色,用来标识行已被点击
.table-tr-selected-bg { background-color: #6189a7 !important; color: #FFF;}
<table id="table1" lay-filter="table1"></table>
// 渲染表格table.render({ elem: '#table1' , height: 415 , page: false , url: Hussar.ctxPath + "/getData" , cols: [[ {field: 'field0', title: '字段0', align: "center",}, , {field: 'field1 ...
mysql的递归查询
本篇博客的目的旨在不用写存储过程,不用建数据库函数,一段sql实现递归查询功能
查询某个父节点下的所有层级的子节点SELECT ID.temp_level, DATA.* FROM ( SELECT @ids AS _ids, ( SELECT @ids := GROUP_CONCAT( region_id ) FROM region WHERE FIND_IN_SET( parent_id, @ids ) ) AS cids, @l := @l + 1 AS temp_level FROM region, ( SELECT @ids := 3, @l := 0 ) b WHERE @ids IS NOT NULL ) ID, region DATA WHERE FIND_IN_SET( DATA.region_id, ID._ids ) ORDER BYtemp_level
注意:
上面sql的两个region要替换为自己表名
上面sql的两个region_id要替换为自己的主键id
上面sql的一个parent_id要替 ...