From 84be98ac74e7f0ed332a47ab14098d9ecd84ccf4 Mon Sep 17 00:00:00 2001 From: xking Date: Sun, 28 Aug 2022 09:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Centos搭建activemq.md | 236 ++++++++ JAVA开发环境搭建.md | 85 +++ Linux下打开超大文件方法.md | 32 + README.md | 1 + RabbitMQ非root用户安装(Linux环境).md | 259 +++++++++ S3.md | 167 ++++++ backend-deployment.md | 96 +++ centos 安装 docker.md | 263 +++++++++ centos_防火墙.md | 29 + centos搭建edb12.md | 16 + debian 11 安装 编译nginx.md | 545 +++++++++++++++++ git 删除远端文件.md | 13 + gitea+drone_cicd部署.md | 425 ++++++++++++++ mysql 迁移数据至postgresql.md | 176 ++++++ postgresql 数据备份 .md | 14 + postgresql导入导出.md | 134 +++++ postgresql锁表查询.md | 39 ++ ...ra2pg 将oracle 数据导入 postgresql.md | 548 ++++++++++++++++++ 搭建edb9.6.md | 129 +++++ 腾讯云ip.md | 4 + 20 files changed, 3211 insertions(+) create mode 100644 Centos搭建activemq.md create mode 100644 JAVA开发环境搭建.md create mode 100644 Linux下打开超大文件方法.md create mode 100644 RabbitMQ非root用户安装(Linux环境).md create mode 100644 S3.md create mode 100644 backend-deployment.md create mode 100644 centos 安装 docker.md create mode 100644 centos_防火墙.md create mode 100644 centos搭建edb12.md create mode 100644 debian 11 安装 编译nginx.md create mode 100644 git 删除远端文件.md create mode 100644 gitea+drone_cicd部署.md create mode 100644 mysql 迁移数据至postgresql.md create mode 100644 postgresql 数据备份 .md create mode 100644 postgresql导入导出.md create mode 100644 postgresql锁表查询.md create mode 100644 使用 ora2pg 将oracle 数据导入 postgresql.md create mode 100644 搭建edb9.6.md create mode 100644 腾讯云ip.md diff --git a/Centos搭建activemq.md b/Centos搭建activemq.md new file mode 100644 index 0000000..140497e --- /dev/null +++ b/Centos搭建activemq.md @@ -0,0 +1,236 @@ +### Centos 搭建activemq + + + +### 软件版本 + +centos 7 + +openJDK 8 + +activeMQ 5.16.5 + +### 配置jdk8 + +下载 JDK 8 这里选用openJDK8 + +下载地址 :[Latest releases | Adoptium](https://adoptium.net/temurin/releases/?version=8) + + + +![image-20220810142758573](http://pic.61dz.com/pic/image-20220810142758573.png) + + + +下载后 上传到linux 服务器 + + + +![image-20220810143043537](http://pic.61dz.com/pic/image-20220810143043537.png) + + + +解压 + +``` +tar -zxvf OpenJDK8U-jdk_x64_linux_hotspot_8u345b01.tar.gz` + +mv jdk8u345-b01 /opt/ +``` + +#配置path +`vim vim /etc/profile` + +#按下 `insert` 键 进入编辑模式 + +![image-20220810143710014](http://pic.61dz.com/pic/image-20220810143710014.png) + +#文档最后追加 + +export JAVA_HOME=/opt/jdk8u345-b01 +export PATH=$PATH:/opt/jdk8u345-b01/bin + +#保存更改 并退出 + +按一下 `esc` 再输入`:wq` 保存退出 + + + +![image-20220810144219748](http://pic.61dz.com/pic/image-20220810144219748.png) + + + +刷新配置 + +` source /etc/profile` + + + + + +验证JAVA + +`java version` + +![image-20220810145759688](http://pic.61dz.com/pic/image-20220810145759688.png) + + + + + +## 安装 activemq + + + +下载activemq + +![image-20220810150003323](http://pic.61dz.com/pic/image-20220810150003323.png) + +下载地址 [活动MQ (apache.org)](https://activemq.apache.org/components/classic/download/) + +上传到服务器 + +![image-20220810150037057](http://pic.61dz.com/pic/image-20220810150037057.png) + + + +解压 + +``` +tar -zxvf apache-activemq-5.16.5-bin.tar.gz` + +mv apache-activemq-5.16.5 /opt/ + +``` + +编辑配置文件 + + + +`vim /opt/apache-activemq-5.16.5/conf/jetty.xml` + + + +按下 insert 键 进入编辑模式 + +找到如下配置 将`127.0.0.1` 修改为`0.0.0.0` + +![image-20220810150344489](http://pic.61dz.com/pic/image-20220810150344489.png) + + + +按一下 `esc` 再输入`:wq` 保存退出 + + + +### 创建系统服务 + + + +`sudo vi /usr/lib/systemd/system/activemq.service` + +输入一下内容 + +``` +[Unit] +Description=activemq message queue +After=network.target +[Service] +PIDFile=/opt/apache-activemq-5.16.5/data/activemq.pid +ExecStart=/opt/apache-activemq-5.16.5/bin/activemq start +ExecStop=/opt/apache-activemq-5.16.5/bin/activemq stop +User=root +Group=root +Restart=always +RestartSec=9 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=activemq + +[Install] +WantedBy=multi-user.target +``` + + + +刷新配置文件 + +`systemctl reload` + +启动服务 + +`systemctl start activemq` + +查看状态 + +systemctl status activemq + + + + + + + +### 更改用户账号 + +#### admin ui + +在 mq安装目录/conf/jetty.xml中 + +``` + + + + + +``` + + + + + +在 mq安装目录/conf/jetty-realm.properties中, + +username: password [,rolename ...] + +admin: password,admin + +帐号:admin, + +密码:password + +用户:admin (就是刚刚jetty.xml设定的roles) + +![image-20220810185600622](http://pic.61dz.com/pic/image-20220810185600622.png) + +#### 连接账号密码 + +在ActiveMQ的conf目录的activemq.[xml](https://so.csdn.net/so/search?q=xml&spm=1001.2101.3001.7020)中添加账号密码 + +``` + + + + + + + +``` + + + +![在这里插入图片描述](http://pic.61dz.com/pic/20190207122112367.png) + + + + + +#### 设置控制台 连接账号密码 + +![](http://pic.61dz.com/pic/20190207123921116.png) + + + +访问控制台 iP:8161 + +admin/admin \ No newline at end of file diff --git a/JAVA开发环境搭建.md b/JAVA开发环境搭建.md new file mode 100644 index 0000000..558f206 --- /dev/null +++ b/JAVA开发环境搭建.md @@ -0,0 +1,85 @@ +# JAVA开发环境搭建 + +openJDK+idea+mysql+vue + + + +## openJDK安装 + +### jvm 版本 + +- openJ9 IBM 捐赠给了Eclipse 基金会 + +- hotspot oracle 开源的jvm 和oracle jdk 同款 + +- Temurin (hotspot) + +- 。。。。。。 + + + +#### 下载地址 + +1. Temurin https://adoptium.net/temurin/releases/?version=8 + +2. oracle http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html + + + +### 安装JDK + +这里使用 Temurin 演示 ,选择合适的版本下载 如:windows x64 jdk 8 + +下载后解压至合适的目录 如 Z:\jdk\jdk8 + +#### 设置环境变量 + +用管理员权限启动 cmd + +查看 JAVA_环境变量是否存在 + +``` +echo %JAVA_HOME% +``` + +设置当前用户环境变量 + +``` + setx JAVA_HOME Z:\jdk\jdk8 + + setx -m PATH "%PATH%;%JAVA_HOME%\bin" +``` + +设置系统级环境变量 + +``` + setx /m JAVA_HOME Z:\jdk\jdk8 + + setx -m PATH "%PATH%;%JAVA_HOME%\bin" +``` + +系统变量or 用户环境变量只需要设置 一次 + +#### 验证 + +运行CMD,验证JAVA环境变量 + +``` +java --version +``` + +## tomcat8.5下载与安装 + + 2.1 下载地址:http://tomcat.apache.org/download-80.cgi + + 2.2 安装 + +## eclipse下载 + + 3.1 下载地址:https://www.eclipse.org/downloads/ + +## mySql下载与安装 + + 4.1 下载地址:https://dev.mysql.com/downloads/windows/installer/8.0.html + + 4.2 安装 \ No newline at end of file diff --git a/Linux下打开超大文件方法.md b/Linux下打开超大文件方法.md new file mode 100644 index 0000000..61bbdfd --- /dev/null +++ b/Linux下打开超大文件方法.md @@ -0,0 +1,32 @@ +Linux下打开超大文件方法 + +在Linux下用VIM打开大小几个G、甚至几十个G的文件时,是非常慢的。 + +这时,我们可以利用下面的方法分割文件,然后再打开。 + +1 查看文件的前多少行 + +head -10000 /var/lib/mysql/slowquery.log > temp.log + +上面命令的意思是:把slowquery.log文件前10000行的数据写入到temp.log文件中。 + +2 查看文件的后多少行 + +tail -10000 /var/lib/mysql/slowquery.log > temp.log + +上面命令的意思是:把slowquery.log文件后10000行的数据写入到temp.log文件中。 + +3 查看文件的几行到几行 + +sed -n '10,10000p' /var/lib/mysql/slowquery.log > temp.log + +上面命令的意思是:把slowquery.log文件第10到10000行的数据写入到temp.log文件中。 + + + +4 根据查询条件导出 +cat catalina.log | grep '2017-09-06 15:15:42' > test.log + + +5 实时监控文件输出 +tail -f catalina.out \ No newline at end of file diff --git a/README.md b/README.md index e69de29..5d240c1 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +自用 博客文章备份 \ No newline at end of file diff --git a/RabbitMQ非root用户安装(Linux环境).md b/RabbitMQ非root用户安装(Linux环境).md new file mode 100644 index 0000000..8e4f4b8 --- /dev/null +++ b/RabbitMQ非root用户安装(Linux环境).md @@ -0,0 +1,259 @@ +#### 下载 erlang + +https://www.erlang.org/patches/otp-22.3.4.26 + +### 安装erlang + +检查依赖 + +``` +rpm -qa | grep -E "ncurses-devel*|openssl-devel*" +``` + +安装依赖(root) + +``` +yum install ncurses-devel +yum install openssl-devel + +``` + +配置安装目录 + +``` +cd /app/otp_src_25.3/ +./configure --prefix=/home/test02/erlang/ +``` + +编译安装 + +``` +make && make install +``` + + + +编辑path + +``` +cd ~ +vi .bash_profile + +追加 +export PATH=$PATH:/home/test02/erlang/bin + +刷新 +source .bash_profile +``` + + + + + +验证 + +``` +erl + + +#退出 +halt() +. +``` + + + +### 安装rabbitmq + +https://www.rabbitmq.com/download.html + + + + + +https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.10.6/rabbitmq-server-generic-unix-3.10.6.tar.xz + + + +erlang rabbitma 版本对应关系 + +https://www.rabbitmq.com/which-erlang.html + +解压rabbitmq + +``` +xz -d /home/test02/rabbitmq/rabbitmq-server-generic-unix-3.8.3.tar.xz +tar xvf /home/test02/rabbitmq/rabbitmq-server-generic-unix-3.8.3.tar + +``` + + + +配置rabbitmq + +``` +cd /home/test02/rabbitmq/rabbitmq_server-3.8.3/etc/rabbitmq/ +vim rabbitmq.env.conf + + +#添加内容如下: +#node name +NODENAME=rabbit + +#data dir +MNESIA_BASE=/home/test02/rabbitmq/rabbitmq/data + + +端口设置 +vim rabbitmq.conf + +#添加内容如下: +#listen port +listeners.tcp.default = 5672 + +#log dir +log.dir =/home/test02/rabbitmq/rabbitmq/logs + +#open remote request +loopback_users = none + +``` + +手动创建目录 + +``` +mkdir /home/test02/rabbitmq/rabbitmq/data /home/test02/rabbitmq/rabbitmq/logs -p +``` + + + +配置 path + +``` +vim .bash_profile +#添加内容如下: +# rabbitmq +export PATH=$PATH:/home/test02/rabbitmq/rabbitmq/sbin + + +#刷新 +source .bash_profile +``` + + + + + + + +启动rabbitmq + +``` +rabbitmq-server -detached +``` + + + +启动状态 + +``` +rabbitmqctl status +``` + +停止 + +``` +rabbitmqctl stop +``` + + + +``` + +``` + +启动控制台插件 + +``` +rabbitmq-plugins enable rabbitmq_management +``` + + + + + +创建新用户 + +默认用户guest只能localhost本地登录 + +所以新建用户 供后续使用 + +``` + +rabbitmqctl add_user yiling yiling123456;a +rabbitmqctl set_user_tags yiling administrator +rabbitmqctl set_permissions -p / yiling ".*" ".*" ".*" +``` + + + +修改guest 弱口令 + +![image-20220815105935659](http://pic.61dz.com/pic/image-20220815105935659.png) + +![image-20220815110022686](http://pic.61dz.com/pic/image-20220815110022686.png) + + + +访问控制台 + +ip:15672 + +用刚刚创建的账号(yiling)密码(yiling123456;a)登录。 + + + +![image-20220815102950262](http://pic.61dz.com/pic/image-20220815102950262.png) + + + + + + + + + + + + + +### 回退 + +卸载依赖 + +yum remove ncurses-devel +yum remove openssl-develremove + + + +删除 erlang + +rm -rf /home/test02/erlang + +删除rabbitmq + +rm -rf /home/test02/rabbitmq + + + +修改path + +cd ~ + +vi .bash_profile + +将之前追加的 path 路径删除 +export PATH=$PATH:/home/test02/erlang/bin + +刷新 +source .bash_profile \ No newline at end of file diff --git a/S3.md b/S3.md new file mode 100644 index 0000000..88f6232 --- /dev/null +++ b/S3.md @@ -0,0 +1,167 @@ +### 安装 jdk1.8 (单用户) + +下载 [Latest releases | Adoptium](https://adoptium.net/temurin/releases) + +解压 **tar -zxvf** OpenJDK8U-jdk_x64_linux_hotspot_8u332b09.tar + +设置环境变量 + +在 ~ 目录下 编辑 .bash_profile + + + +添加 修改路径 + +``` +JAVA_HOME=/home/wlf/jdk1.8.0_221 +CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib +PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin +export PATH CLASSPATH JAVA_HOME +``` + + 刷新 source .bash_profile + + + +测试 是否成功 + + + +java -version + + + + + + + +### 安装 zk(单机集群) + +下载 [Index of /apache/zookeeper/zookeeper-3.5.10 (tsinghua.edu.cn)](https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.10/) + + + +- 解压 `apache zookeeper` + +```text +tar -zxvf apache-zookeeper-3.5.10-bin.tar.gz + + +``` + + + + + + + + + + + + + + + + + +### 安装kafka(单机集群) + + + + + +下载 kafka [Apache Kafka](https://kafka.apache.org/downloads) + + + +[10分钟搭建单机Kafka集群 - 知乎 (zhihu.com)](https://zhuanlan.zhihu.com/p/136758040?from_voters_page=true) + + + +### 安装redis + +下载 [Index of /releases/ (redis.io)](http://download.redis.io/releases/) + + + +### 安装 consul + + 下载 [Downloads | Consul by HashiCorp](https://www.consul.io/downloads) + + + +解压 + +```text +unzip consul_1.9.0_linux_amd64.zip + +``` + +### 启动命令 + +zk 启动 + +/home/test02/zookeeper/zookeeper_node1/bin/zkServer.sh start; +/home/test02/zookeeper/zookeeper_node2/bin/zkServer.sh start; +/home/test02/zookeeper/zookeeper_node3/bin/zkServer.sh start; + + + +zk 启动 + +/home/test02/zookeeper/zookeeper_node1/bin/zkServer.sh stop; +/home/test02/zookeeper/zookeeper_node2/bin/zkServer.sh stop; +/home/test02/zookeeper/zookeeper_node3/bin/zkServer.sh stop; + +zk 查看状态 + +/home/test02/zookeeper/zookeeper_node1/bin/zkServer.sh status; +/home/test02/zookeeper/zookeeper_node2/bin/zkServer.sh status; +/home/test02/zookeeper/zookeeper_node3/bin/zkServer.sh status; + + + + + + + + + +kafka 启动 + +nohup /home/test02/kafka/kafka_2.12-2.2.1/bin/kafka-server-start.sh /home/test02/kafka/kafka_2.12-2.2.1/config/server_node3.properties > /home/test02/kafka/log/kafka3-logs/startup.log 2>&1 & +nohup /home/test02/kafka/kafka_2.12-2.2.1/bin/kafka-server-start.sh /home/test02/kafka/kafka_2.12-2.2.1/config/server_node2.properties > /home/test02/kafka/log/kafka2-logs/startup.log 2>&1 & +nohup /home/test02/kafka/kafka_2.12-2.2.1/bin/kafka-server-start.sh /home/test02/kafka/kafka_2.12-2.2.1/config/server_node1.properties > /home/test02/kafka/log/kafka1-logs/startup.log 2>&1 & + + + +kafka 停止(三个节点都停止) + +/home/test02/kafka/kafka_2.12-2.2.1/bin/kafka-server-stop.sh + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend-deployment.md b/backend-deployment.md new file mode 100644 index 0000000..86055b8 --- /dev/null +++ b/backend-deployment.md @@ -0,0 +1,96 @@ +--- +title: 如何部署后端服务 +--- + +[[_TOC_]] + +这里描述如何安装相关软件,增加配置,并部署后端产出物的整个过程。 + +以下以 Ubuntu 18.04 为例,假设访问地址为 `http://dev-app.rqm.yldev.net`。 + +# 准备服务器 +应在 VMware vSphere 创建一(或多)台虚拟机,或由项目方 IT 提供一(或多)台 Linux 服务器。 +- 安装有 OpenSSH Server,用于远程访问。 +- 应仅对 Web 服务器开放 18080 ~ 18100 端口 + +# 安装 OpenJDK 8 +应使用 `apt-get install openjdk-8-jdk` 安装 OpenJDK 8。 + +# 安装业务服务 +后端业务服务应安装为 Systemd 服务,由以下几部分配置组成。在配置完成后,应使用 `systemctl enable xxx` 设置为重启时自动启动。 + +## Systemd 配置 +这里定义某个业务服务的 Systemd 配置,描述相关账户、加载的环境变量,以及执行命令等。 +```bash +# /etc/systemd/system/rqm-prepare.service +[Unit] +Description=rqm-prepare +After=syslog.target + +[Service] +User=nobody # 以非 root 身份运行 +EnvironmentFile=-/etc/default/rqm-prepare # 从此文件加载环境变量 +WorkingDirectory=/opt/rqm/ +ExecStart=/usr/bin/java $LOGGING $JAVA_OPTS -Dserver.port=${PORT} -Djava.security.egd=file:///dev/urandom -jar $BINARY +SuccessExitStatus=143 +Restart=on-failure # 如果是非正常退出则重启服务 +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target +``` + +## 环境变量 +某个服务运行时所需的环境变量均在此文件中配置,包括运行的端口号、可执行文件以及时区等。 + +```bash +# /etc/default/rqm-prepare +PORT=18082 +BINARY=/opt/rqm/rqm-prepare.jar +JAVA_OPTS=-Xms256m -Xmx1024m +TZ=Asia/Shanghai # 指定当前服务运行在东八区 +LOGGING="-Dlogging.config=/etc/rqm/logback.xml" # 按照指定的配置输出日志 +# Service References +RETROFIT_ENDPOINTS_DOCUMENT_BASE_URL=http://127.0.0.1:18083/ # 其他服务的引用地址 +``` + +## 日志配置 +这里定义业务服务输出的日志级别及目标。 + +```xml + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n + + + + udp:graylog.ylops.net + 12201 + 1.1 + true + true + name=${name} + true + yyyy-MM-dd HH:mm:ss,SSSS + + INFO + + + + + + + + +``` + +# 部署产出物 +应从后端版本库 CI 中下载产出物,并拷贝至 `/opt/rqm/` 目录中。 + +# 启动并测试 +可使用 `systemctl start xxx` 启动单个业务服务。使用 `curl http://localhost:18082/` 访问该服务。 diff --git a/centos 安装 docker.md b/centos 安装 docker.md new file mode 100644 index 0000000..dc63f98 --- /dev/null +++ b/centos 安装 docker.md @@ -0,0 +1,263 @@ + + +# Centos 安装 Docker + + + +## 安装脚本 + +一键安装脚本!Linux系统都支持! + +``` + + curl -sSL https://get.docker.com/ | sh + + #国内阿里云镜像 + curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun + + #Azure源(中国区azure) + curl -fsSL https://get.docker.com | bash -s docker --mirror AzureChinaCloud +``` + + + +## 启动服务 + +``` + + # 启动docker服务 + systemctl start docker.service + + # 停止docker服务 + systemctl stop docker.service + + # 重启docker服务 + systemctl restart docker.service + + # 查看docker服务当前状态 + systemctl status docker.service + + # 设置 docker 服务开机自启动 + systemctl enable docker.service + + # 停止 docker 服务开机自启动 + systemctl disable docker.service +``` + + + +## 国内镜像 + +为了加速下载镜像文件,国内服务器可以指定国内的镜像! + +阿里云:https://registry.cn-hangzhou.aliyuncs.com/ + +华为云:https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com/ + +Docker中国:https://registry.docker-cn.com + +网易:http://hub-mirror.c.163.com + +中科大:https://docker.mirrors.ustc.edu.cn + +腾讯云 https://mirror.ccs.tencentyun.com + + + +### 写入配置文件 重启服务 + +``` + + sudo mkdir -p /etc/docker + + sudo tee /etc/docker/daemon.json <<-'EOF' + { + "registry-mirrors": ["https://mirror.ccs.tencentyun.com"] + } + EOF + sudo systemctl daemon-reload + sudo systemctl restart docker +``` + + + + + +## 迁移目录 + +主要是为了不让Docker镜像,容器占用系统盘的容量! + +如果就一块盘或者系统盘容量大,这部分内容可忽略! + +``` + + # 给Docker廋身一下 + #docker system prune + + #停止Docker服务 + systemctl stop docker + + #创建目标目录 + mkdir -p /data/docker/ + + #同步源目录文件 -> 目标目录 + rsync -avz /var/lib/docker/ /data/docker + + #修改Docker配置文件 + vim /etc/docker/daemon.json + + #修改或者新增内容如下 + { + "data-root": "/data/docker" + } + + #启动Docker服务 + systemctl start docker + + # 查看是否修改成功 + docker info | grep "Docker Root Dir" + + #输出:Docker Root Dir: /data/docker 就OK了! + +``` + + + +## 常用命令 + +``` + #下载镜像 + docker pull nginx + #启动容器 + #下面命令为启动一个nginx,将服务器的8080 端口 映射到 容器的80端口,且容器命名为nginx-test + docker run -d -p 8080:80 nginx --name="nginx-test" + + #停止容器 + docker stop xxxx + + 删除容器 + docker rm id + + + -f, --force=false 是否强行终止并删除一个运行中的容器 + -l, --link=false :删除容器的连接 ,但保留容器 + -v, --volumes=false :删除容器挂载的数据卷 + + + + 删除所有镜像 + docker rmi $(docker images -q) + #停止所有容器 + docker stop $(docker ps -a -q) + #删除所有容器 + docker rm $(docker ps -a -q) + #启动所有容器 + docker start $(docker ps -a -q) + + + #进入容器 + docker exec -it jd /bin/bash + docker exec -it jd /bin/sh + docker exec -it jd /bash + docker exec -it jd /sh + + + #宿主往容器中复制文件 + docker cp /etc/apt/sources.list ubuntu:/etc/apt/ + + + #容器中往宿主机复制 + docker cp testtomcat:/usr/local/tomcat/webapps/test/js/test.js /opt + + + #不进入容器 在容器中执行命令 + docker exec ID 命令 + + #查看容器信息 + docker inspect ID + + + #查询部分信息 + docker inspect -f {{.Config.Hostname}} id +``` + + + +## 开发调试 + +### Build Dockerfile + +``` + + + #比如我们要写一个Dockerfile 该怎么调试呢? + docker build -t [命名] [编译的目录] + + #比如:AList目录中有Dockerfile,重新编译镜像,且命名成alist + docker build -t alist ./AList/ + + #启动 alist + docker run alist --name="alist" + +``` + +## 容器目录映射 + +以docker hub的centos:8为研究对象 + +**1、宿主机和容器映射目录都不存在** + +宿主机和容器映射目录都会自动创建,且在一边操作等同于在另一边操作。 + +**2、宿主机目录不存在,容器映射目录为空。容器中/usr/lib/games目录为空** + +宿主机映射目录会自动创建,且在一边操作等同于在另一边操作。 + +**3、宿主机目录不存在,容器映射目录不为空。容器中/usr/lib/locale/C.utf8目录不为空** + +宿主机映射目录会自动创建,容器映射目录中原来的文件都消失了,在一边操作等同于在另一边操作,且操作的是宿主机目录中的文件。 + + + +**4、宿主机映射目录为空,容器映射目录不存在** + +容器映射目录会自动创建,且在一边操作等同于在另一边操作。 + +**5、宿主机和容器映射目录都为空。** + +在一边操作等同于在另一边操作。 + +**6、宿主机映射目录为空,容器映射目录不为空** + +容器映射目录中原来的文件都消失了。在一边操作等同于在另一边操作,且操作的是宿主机目录中的文件。 + +**7、宿主机映射目录不为空,容器映射目录不存在** + +容器映射目录会自动创建,一进去该目录就能看见宿主机映射目录中的文件,且在一边操作等同于在另一边操作。 + +**8、宿主机映射目录不为空,容器映射目录为空** + +一进容器映射目录就能看见宿主机映射目录中的文件,且在一边操作等同于在另一边操作。 + +**9、宿主机和容器映射目录都不为空。** + +容器映射目录中原来的文件都消失了。在一边操作等同于在另一边操作,且操作的是宿主机目录中的文件。 + + + + + + + +## 常见问题 + +容器内没有网 不能解析dns + +创建时添加以下参数 + +``` +--network=host +``` + + + diff --git a/centos_防火墙.md b/centos_防火墙.md new file mode 100644 index 0000000..646e713 --- /dev/null +++ b/centos_防火墙.md @@ -0,0 +1,29 @@ +• 查看防火墙状态:命令执行后,响应结果包含active (running) 表示防火墙是开启状态。如果防火墙没有开启,可以使用后文中的命令开启防火墙。 +\>systemctl status firewalld + +• 查看已开放端口:该命令会列出防火墙所有对外开放访问的端口的信息 +\>firewall-cmd --list-all + + +• 防火墙开放某个端口(如:kafka服务端口为9092) +\>firewall-cmd --zone=public --add-port=9092/tcp --permanent +success + + +命令含义: +–zone: 作用域 +–add-port=9092/tcp: 添加端口,格式为:端口/通讯协议 +–permanent: 永久生效,没有此参数重启后失效 +• 开放端口后需重载防火墙配置,这样新开放的端口才能生效 +\>firewall-cmd --reload +Success + + +• 如果决定收回某些端口的开放权限,执行下列命令 +firewall-cmd --zone=public --remove-port=10050/tcp;firewall-cmd --runtime-to-permanent;firewall-cmd --reload; +• firewalld的linux其他基本操作 +• 启动防火墙: systemctl start firewalld +• 关闭防火墙: systemctl stop firewalld +• 查看防火墙状态: systemctl status firewalld +• 开机禁用 : systemctl disable firewalld +• 开机启用 : systemctl enable firewalld \ No newline at end of file diff --git a/centos搭建edb12.md b/centos搭建edb12.md new file mode 100644 index 0000000..d4b960f --- /dev/null +++ b/centos搭建edb12.md @@ -0,0 +1,16 @@ + + + + + + +``` +PGSETUP_INITDB_OPTIONS="-E UTF-8 -D 数据路径" /usr/edb/as12/bin/edb-as-12-setup initdb + +注意 更改数据路径需要修改 service 文件 +``` + +``` +systemctl start edb-as-12 +``` + diff --git a/debian 11 安装 编译nginx.md b/debian 11 安装 编译nginx.md new file mode 100644 index 0000000..b0b1d74 --- /dev/null +++ b/debian 11 安装 编译nginx.md @@ -0,0 +1,545 @@ +### debian 11 安装 编译nginx + + + +##### 安装编译环境 + +``` + #GCC + apt install -y build-essential + + #安装正则库 + apt install -y libpcre3 libpcre3-dev + + #安装zlib库 + apt install -y zlib1g-dev + + #openssl + apt install -y openssl libssl-dev + +``` + + + +##### 下载源码 + +官网 https://nginx.org/en/download.html + +这里以 `nginx-1.20.2` 版本为例 + +https://nginx.org/download/nginx-1.22.0.tar.gz + +![image-20220812225816199](http://pic.61dz.com/pic/image-20220812225816199.png) + + + +##### 解压源码 + +``` + cd /opt/ + + wget https://nginx.org/download/nginx-1.22.0.tar.gz + + tar -zxvf nginx-1.22.2.tar.gz + + cd nginx-1.22.2/ + +``` + + + +##### 配置编译参数模块 + +指定安装路径 --prefix=/usr/local/nginx + +执行用户、组 可以不加,如果系统中没有 该用户会报错 + +--user=www \ +--group=www \ + + + +``` + ./configure \ + --prefix=/usr/local/nginx \ + --user=www \ + --group=www \ + --sbin-path=/usr/local/nginx/sbin/nginx \ + --conf-path=/usr/local/nginx/nginx.conf \ + --error-log-path=/var/log/nginx/error.log \ + --http-log-path=/var/log/nginx/access.log \ + --pid-path=/var/run/nginx.pid \ + --lock-path=/var/run/nginx.lock \ + --http-client-body-temp-path=/var/cache/nginx/client_temp \ + --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ + --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ + --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ + --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ + --with-file-aio \ + --with-threads \ + --with-http_addition_module \ + --with-http_auth_request_module \ + --with-http_dav_module \ + --with-http_flv_module \ + --with-http_gunzip_module \ + --with-http_gzip_static_module \ + --with-http_mp4_module \ + --with-http_random_index_module \ + --with-http_realip_module \ + --with-http_secure_link_module \ + --with-http_slice_module \ + --with-http_ssl_module \ + --with-http_stub_status_module \ + --with-http_sub_module \ + --with-http_v2_module \ + --with-mail \ + --with-mail_ssl_module \ + --with-stream \ + --with-stream_realip_module \ + --with-stream_ssl_module \ + --with-stream_ssl_preread_module + +``` + + + + + +##### 编译 and 安装 nginx + +``` + make + + make install +``` + + + +##### 创建进程守护 + +``` + vim /usr/lib/systemd/system/nginx.service + + + + + [Unit] + Description=nginx + After=network.target + + [Service] + Type=forking + ExecStart=/usr/local/nginx/sbin/nginx + ExecReload=/usr/local/nginx/sbin/nginx -s reload + ExecStop=/usr/local/nginx/sbin/nginx -s quit + PrivateTmp=true + + [Install] + WantedBy=multi-user.target + + +``` + + + + + +##### 验证安装 + +``` +curl 127.0.0.1 +``` + + + +配置nginx.conf + +加到 http 节点中 + +``` + include mime.types; + default_type application/octet-stream; + + server_names_hash_bucket_size 512; + client_header_buffer_size 32k; + large_client_header_buffers 4 32k; + client_max_body_size 50m; + + sendfile on; + tcp_nopush on; + + keepalive_timeout 60; + + tcp_nodelay on; + + fastcgi_connect_timeout 300; + fastcgi_send_timeout 300; + fastcgi_read_timeout 300; + fastcgi_buffer_size 64k; + fastcgi_buffers 4 64k; + fastcgi_busy_buffers_size 128k; + fastcgi_temp_file_write_size 256k; + fastcgi_intercept_errors on; + + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 2; + gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; + gzip_vary on; + gzip_proxied expired no-cache no-store private auth; + gzip_disable "MSIE [1-6]\."; + + limit_conn_zone $binary_remote_addr zone=perip:10m; + limit_conn_zone $server_name zone=perserver:10m; + + server_tokens off; + access_log off; +``` + + + +##### 分离配置文件 + +将每个网站单独一个配置 ,在nginx中全局加载 + +在/etc/ 目录中创建 nginx 文件夹用来储存 配置 + +``` + mkdir /etc/nginx/site-enable -p + + mkdir /etc/nginx/tcp-enable + + cd /etc/nginx/site-enable + + vim site.conf +``` + + + +#### 具体使用 + +如果你是按我的方法编译,那么,需要注意。 + +- `/usr/local/nginx`:为Nginx编译安装的地址。 +- `/usr/local/nginx/nginx.conf`:Nginx默认配置文件。 + +同时,我们使用`systemctl`对Nginx进行管理: + +- `systemctl start nginx`:启动Nginx服务。 +- `systemctl reload nginx`:Nginx配置重载。 +- `systemctl stop nginx`:停止Nginx服务。 + + + +#### 常见问题 + +没有用户 + +![image-20220812233620354](http://pic.61dz.com/pic/image-20220812233620354.png) + + + +目录创建失败(多级目录) + +![image-20220812233649678](http://pic.61dz.com/pic/image-20220812233649678.png) + +#### 附1: `systemctl 操作` + +``` + #重载配置文件 添加新的 或者修改都要重载。 + systemctl daemon-reload + + #启动Nginx服务 + systemctl start nginx + + #Nginx配置重载。 + systemctl reload nginx + + #停止Nginx服务。 + systemctl stop nginx + + #重启nginx + systemctl restart nginx + + # 停止nginx服务开机自启动 + systemctl disable nginx.service +``` + +#### 附2: `journalctl操作` + +``` + + + #追踪日志 + journalctl -f -u nginx.service + + #读日志 + journalctl -r -u nginx.service +``` + + + +#### 附3: `linux 创建用户` + +``` + #创建用户组 + groupadd www + + #创建用户 + useradd www -g www + adduser 用户名 +``` + +##### useradd与adduser 差异 + +###### 命令使用方法 + +``` + useradd 用户名 + + adduser 用户名 +``` + +###### 命令差异总结 + +在Ubuntu下`useradd`与`adduser`命令不同 + +- useradd在使用该命令创建用户是不会在/home下自动创建与用户名同名的用户目录,而且不会自动选择shell版本,也没有设置密码,那么这个用户是不能登录的,需要使用passwd命令修改密码。 + +- adduser在使用该命令创建用户是会在/home下自动创建与用户名同名的用户目录,选择系统shell版本,会在创建时会提示输入密码,更加友好。 + +在CentOS下`useradd`与`adduser`命令相同 + +- useradd 和 adduser都会在/home下自动创建与用户名同名的用户目录,但是没有提示输入密码,需要使用passwd手动设置一下! + +​ `passwd 用户名; #为用户设置密码` + +#### 附4: 完整的nginx 配置文件 + +apt 卸载nginx + +``` +查询 nginx 相关软件 + +dpkg --get-selections|grep nginx + +卸载nginx(删除配置) +apt-get --purge remove nginx + + +``` + + + +#### 附5: 完整的nginx 配置文件 + +###### nginx.conf + +``` + +worker_processes auto; + +worker_rlimit_nofile 51200; + +stream { + log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time'; + + access_log /var/log/nginx/tcp-access.log tcp_format; + error_log /var/log/nginx/tcp-error.log; + + include /etc/nginx/tcp-enable/*.conf; +} + + +events { + use epoll; + worker_connections 51200; + multi_accept on; + } + + +http { + include mime.types; + default_type application/octet-stream; + + server_names_hash_bucket_size 512; + client_header_buffer_size 32k; + large_client_header_buffers 4 32k; + client_max_body_size 50m; + + sendfile on; + tcp_nopush on; + + keepalive_timeout 60; + + tcp_nodelay on; + + fastcgi_connect_timeout 300; + fastcgi_send_timeout 300; + fastcgi_read_timeout 300; + fastcgi_buffer_size 64k; + fastcgi_buffers 4 64k; + fastcgi_busy_buffers_size 128k; + fastcgi_temp_file_write_size 256k; + fastcgi_intercept_errors on; + + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 2; + gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; + gzip_vary on; + gzip_proxied expired no-cache no-store private auth; + gzip_disable "MSIE [1-6]\."; + + limit_conn_zone $binary_remote_addr zone=perip:10m; + limit_conn_zone $server_name zone=perserver:10m; + + server_tokens off; + access_log off; + + server { + listen 80; + server_name localhost; + location / { + root html; + index index.html index.htm; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + } +include /etc/nginx/site-enable/*.conf; +} + +``` + + + +###### web-site.conf + +``` +server { + listen 80; + server_name frp.plugin.dr1997.com; + index index.php index.html index.htm default.php default.htm default.html; + root /www/wwwroot/frp.plugin.dr1997.com; + + #禁止访问的文件或目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) + { + return 404; + } + + #一键申请SSL证书验证目录相关设置 + location ~ \.well-known{ + allow all; + } + + access_log /www/wwwlogs/frp.plugin.dr1997.com.log; + error_log /www/wwwlogs/frp.plugin.dr1997.com.error.log; +} +``` + +###### ssl + +``` +server { + listen 80; + listen 443 ssl http2; + server_name frp.dr1997.com *.frp.dr1997.com; + index index.php index.html index.htm default.php default.htm default.html; + root /www/wwwroot/frp.dr1997.com; + + #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 + #error_page 404/404.html; + #HTTP_TO_HTTPS_START + if ($server_port !~ 443){ + rewrite ^(/.*)$ https://$host$1 permanent; + } + #HTTP_TO_HTTPS_END + ssl_certificate /www/server/panel/vhost/cert/frp.dr1997.com/fullchain.pem; + ssl_certificate_key /www/server/panel/vhost/cert/frp.dr1997.com/privkey.pem; + ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + add_header Strict-Transport-Security "max-age=31536000"; + error_page 497 https://$host$request_uri; + + #SSL-END + + + #一键申请SSL证书验证目录相关设置 + location ~ \.well-known{ + allow all; + } + + access_log /www/wwwlogs/frp.dr1997.com.log; + error_log /www/wwwlogs/frp.dr1997.com.error.log; +} +``` + +###### 反向代理(http) + +``` + server { + listen 80; + listen 443 ssl http2; + server_name frp.dr1997.com *.frp.dr1997.com; + index index.php index.html index.htm default.php default.htm default.html; + root /www/wwwroot/frp.dr1997.com; + + #PROXY-START/ + location ~* \.(gif|png|jpg|css|js|woff|woff2)$ { + proxy_pass http://127.0.0.1:8880; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header REMOTE-HOST $remote_addr; + expires 12h; + } + location / { + proxy_pass http://127.0.0.1:8880; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header REMOTE-HOST $remote_addr; + + add_header X-Cache $upstream_cache_status; + + #Set Nginx Cache + + add_header Cache-Control no-cache; + } + + #PROXY-END/ + + access_log /www/wwwlogs/frp.dr1997.com.log; + error_log /www/wwwlogs/frp.dr1997.com.error.log; + } + + + +``` + +###### 反向代理 tcn + +``` + upstream tcp { + server 127.0.0.1:3306; + } + + server { + listen 3307; + proxy_connect_timeout 8s; + proxy_timeout 24h; + proxy_pass tcp; + } +``` + diff --git a/git 删除远端文件.md b/git 删除远端文件.md new file mode 100644 index 0000000..e9b533e --- /dev/null +++ b/git 删除远端文件.md @@ -0,0 +1,13 @@ +# git 删除远端文件 + + + +``` +git rm -r -n --cached 文件/文件夹名称 + +加上 -n 这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。 + + +git rm -r --cached 文件/文件夹名称 +``` + diff --git a/gitea+drone_cicd部署.md b/gitea+drone_cicd部署.md new file mode 100644 index 0000000..f6aa7cc --- /dev/null +++ b/gitea+drone_cicd部署.md @@ -0,0 +1,425 @@ + + +# gitea+drone_cicd部署记录 + + + +## 基础环境 + +1. centos 7.6 bit64 *3 +2. mysql 8.0 +3. gitea 1.16.8 +4. Nginx nginx-1.20.0 + +## 服务器划分 + +- 一台 2H4G8M80G硬盘的腾讯云(248-3) 安装 mysql+gitea+nginx(代理gitea) +- 一台 2H4G8M60G硬盘的腾讯云(248-2) 安装docker+drone+drone runner +- 一台 2H4G8M60G硬盘的腾讯云(248-1) 安装 mysql+java+ nginx(服务发布) + + + +## 安装mysql + +#### 下载mysql 源 + +打开地址 + +https://dev.mysql.com/downloads/repo/yum/ + +找到 **Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package** + +点击进去 找到 mysql 8.0 的源 + +在ssh 中下载 + +``` +wget https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm +``` + +查找 并卸载 自带的mysql + +``` +rpm -qa|grep mysql +find / -name mysql + +rpm -e --nodeps mysql-libs-5.1.* + +``` + +#### 安装mysql + +``` + +//安装 mysql 源 +yum localinstall mysql80-community-release-el7-3.noarch.rpm + + +//安装密钥 +rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 + +//安装mysql 8.0 +yum install mysql-community-server + + +//启动 mysql +service mysqld start + +``` + +#### 修改mysql 密码 + +```arcade +//查询密码 +grep 'temporary password' /var/log/mysqld.log + +//登录mysql +mysql -uroot -p + +//修改密码 +ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; + +//刷新权限 +flush privileges; + + +//创建用户名 +create user '你的用户名'@'%' identified with mysql_native_password by '你的密码'; +create user 'gitea'@'%' identified with mysql_native_password by 'gitea147258;D'; +//设置权限 +grant all on *.* to '你的用户名'@'%'; +grant all on *.* to 'gitea'@'%'; +//刷新权限 +flush privileges; + +``` + +## 安装gitea + + + +### 安装git + +``` +yum -y install git +``` + +### 安装gitea + +``` +创建一个目录用于存放gitea和git数据的目录 +mkdir /opt/git + +// 创建用户组 +groupadd git +//创建用户 +useradd git -g git + +//进入创建的目录 +cd /opt/git + +//下载github 最新版 (https://github.com/go-gitea/gitea) +wget -O gitea https://github.com/go-gitea/gitea/releases/download/v1.16.8/gitea-1.16.8-linux-amd64 + +// 设置成可运行文件 +chmod +x gitea + + +//切换至 git 用户 +su git + +测试运行 能访问后 退出 切换到 root +./gitea web + +//将刚刚创建的目录授权给 git 用户,组。 +chown -R git:git /opt/git + + +//设置进程守护 +vim /etc/systemd/system/gitea.service + +[Unit] +Description=Gitea +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User=git +Group=git +ExecStart=/opt/git/gitea web --config /opt/git/custom/conf/app.ini +Restart=always + +[Install] +WantedBy=multi-user.target + + + +//运行 +systemctl start gitea +// 查看是否成功运行 +ps -aux | grep gitea +``` + +### 安装Nginx + +#### 下载nginx + +```bash +//切换目录 (看个人习惯) +cd /opt/nginx +wget http://nginx.org/download/nginx-1.20.0.tar.gz + +``` + +#### 安装依赖 + +``` +# 安装gcc、gcc-c++ +yum -y install gcc +yum -y install gcc-c++ + +# 安装pcre 、zilb +yum -y install pcre* +yum -y install zlib* + +# 安装openssl(若需要支持 https 协议) +yum -y install openssl +yum -y install openssl-devel +``` + + + +#### 解压nginx + +``` +tar -zxvf nginx-1.20.0.tar.gz +``` + +#### 编译nginx + +``` + //进入nginx 目录 + cd nginx-1.20.0 + + //配置编译参数 + ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre + + //编译安装 + make && make install + + //指定配置启动 访问ip 看到欢迎信息则成功 + /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf + + + +``` + +#### 进程守护 + +``` +# 新建文件 +vim /lib/systemd/system/nginx.service + +# 添加内容 +[Unit] +Description=nginx.server +After=network.target + +[Service] +Type=forking +PIDFILE=/var/run/nginx.pid +ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf +ExecRepload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s QUIT $MAINPID +PrivateTmp=true + +[Install] +WantedBy=multi-user.target +``` + + + +#### 开机自启 + +``` +# 启动nginx服务 +systemctl start nginx.service + +# 停止nginx服务 +systemctl stop nginx.service + +# 重启nginx服务 +systemctl restart nginx.service + +# 查看nginx服务当前状态 +systemctl status nginx.service + +# 设置nginx服务开机自启动 +systemctl enable nginx.service + +# 停止nginx服务开机自启动 +systemctl disable nginx.service +``` + + + +#### 常用命令 + +``` +# 进入目录 +cd /usr/local/nginx/sbin + +# 验证配置是否正确 +./nginx -t +# 如果看到如下内容, 那么配置正确, 可以重启Nginx +nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok +nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful + +# 重启Nginx, 之后就可以通过域名访问了, 哈哈 +./nginx -s reload +``` + + + +#### 配置反向代理 + +目录 ssl证书自行替换 + +``` +server +{ + listen 80; + listen 443 ssl http2; + server_name gitea.dr1997.com; + index index.php index.html index.htm default.php default.htm default.html; + root /www/wwwroot/gitea_dr1997_com; + + #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 + #error_page 404/404.html; + #HTTP_TO_HTTPS_START + if ($server_port !~ 443){ + rewrite ^(/.*)$ https://$host$1 permanent; + } + #HTTP_TO_HTTPS_END + ssl_certificate /www/ssl/gitea_dr1997_com/fullchain.pem; + ssl_certificate_key /www/ssl/gitea_dr1997_com/privkey.pem; + ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + add_header Strict-Transport-Security "max-age=31536000"; + error_page 497 https://$host$request_uri; + + #SSL-END + + #ERROR-PAGE-START 错误页配置,可以注释、删除或修改 + #error_page 404 /404.html; + #error_page 502 /502.html; + #ERROR-PAGE-END + + #引用反向代理规则,注释后配置的反向代理将无效 + + location / { + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://127.0.0.1:3000; + } + location ~ .*\.(js|css|png)$ { + proxy_pass http://127.0.0.1:3000; + } + #PROXY-END/ + + #禁止访问的文件或目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) + { + return 404; + } + + + access_log /www/wwwlogs/gitea.dr1997.com.log; + error_log /www/wwwlogs/gitea.dr1997.com.error.log; +} +``` + +## 安装 Drone + +### 安装 drone server + +### 安装 drone runner + +### 流水线配置 + +``` +workspace: + base: /srv/drone-demo + path: . + +pipeline: + build: + image: golang:alpine + # pull: true + environment: + - KEY=VALUE + secrets: [key1, key2] + commands: + - echo $$KEY + - pwd + - ls + - go version + - GO111MODULE=off CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app ./ + - ls + - ./app + +``` + +全程容器化 + + + +``` + +docker run \ + --volume=/var/lib/drone:/data \ + --env=DRONE_GITEA_SERVER=https://git.dr1997.com \ + --env=DRONE_GITEA_CLIENT_ID=74e78545-efa3-4c69-b9a3-226579f65ead \ + --env=DRONE_GITEA_CLIENT_SECRET=BeSfuXea0EFwNCNNE3dLA4aDbZUyAeFEmpjpibZx1Ysq \ + --env=DRONE_RPC_SECRET=ad12a3284ecc37e2bcb03d40a88854e2 \ + --env=DRONE_SERVER_HOST=drone.dr1997.com \ + --env=DRONE_SERVER_PROTO=https \ + --env=DRONE_TLS_AUTOCERT=true \ + --env=DRONE_GIT_ALWAYS_AUTH=true \ + --publish=80:80 \ + --publish=443:443 \ + --restart=always \ + --detach=true \ + --name=drone \ + drone/drone:2 + + + + + docker pull drone/drone-runner-docker:1 + + + + docker run --detach \ + --volume=/var/run/docker.sock:/var/run/docker.sock \ + --env=DRONE_RPC_PROTO=https \ + --env=DRONE_RPC_HOST=drone.dr1997.com \ + --env=DRONE_RPC_SECRET=ad12a3284ecc37e2bcb03d40a88854e2 \ + --env=DRONE_RUNNER_CAPACITY=2 \ + --env=DRONE_RUNNER_NAME=my-first-runner \ + --publish=3000:3000 \ + --restart=always \ + --name=runner \ + drone/drone-runner-docker:1 +``` + + + + + diff --git a/mysql 迁移数据至postgresql.md b/mysql 迁移数据至postgresql.md new file mode 100644 index 0000000..34094b7 --- /dev/null +++ b/mysql 迁移数据至postgresql.md @@ -0,0 +1,176 @@ +# mysql 迁移数据至postgresql + + + +业务需要 需要将mysql 数据迁移到 postgresql 12 + + + +百度了许久 迁移工具还是挺多的 + +如 + +​ + + + +docker pull quay.io/enterprisedb/postgresql:12 + + + + +docker pull ghcr.dockerproxy.com/username/image:tag + + + +docker pull quay.io/username/image:tag + +docker pull quay.dockerproxy.com/username/image:tag + + + + docker run -d \ + --name some-postgres \ + -e POSTGRES_PASSWORD=cEnq!rnvWV7Z!~+7ag \ + -p 5444:5444\ + quay.io/enterprisedb/postgresql:12 + + + +docker run -d --name some-postgres \ + -e POSTGRES_PASSWORD=cEnq!rnvWV7Z!~+7ag \ + quay.io/enterprisedb/postgresql:12 + + + + + + docker run -it \ + --name some-postgres \ + quay.io/enterprisedb/postgresql:12 \ + psql -U postgres + + + + + + + + mytsql 172.17.0.3 + + + + + GitHub Container Registry +常规镜像代理 +官方命令:docker pull ghcr.io/username/image:tag +代理命令:docker pull ghcr.dockerproxy.com/username/image:tag + + + +docker run -d \ + --name pgsql-12 \ + -e POSTGRES_PASSWORD=yiling \ + -p 5432:5432 \ + -v /opt/postgresql/data:/var/lib/postgresql/data \ + ghcr.dockerproxy.com/enterprisedb/postgresql:12 + + + docker run -d --name pgsql-12 -e POSTGRES_PASSWORD=yiling -p 5432:5432 -v /opt/postgresql/data:/var/lib/postgresql/data ghcr.dockerproxy.com/enterprisedb/postgresql:12 + + + + + + + +$ docker run -d \ + --name some-postgres \ + -e POSTGRES_PASSWORD=mysecretpassword \ + ghcr.dockerproxy.com/enterprisedb/postgresql:12 + + + + + bin:/usr/pgsql-12 + + + data /var/lib/postgresql/data/pgdata + + + + + + docker run -d -v /opt/pgload/pgload.load:/opt/pgload/pgload.load --name pgloader dimitri/pgloader:latest pgloader /opt/pgload/pgload.load + +​ + + + + + mysql_native_password + + + + caching_sha2_password + + + + + 镜像 + docker run -itd --name=ubuntu ubuntu:18.04 /bin/bash + + apt-get update && apt-get install lsb-core + + + + su -c 'echo "deb [arch=amd64] https://apt.enterprisedb.com/$(lsb_release -cs)-edb/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/edb-$(lsb_release -cs).list' + + + su -c 'echo "machine apt.enterprisedb.com login start password oIVqaoGTDFL5aYHD" > /etc/apt/auth.conf.d/edb.conf' + + apt-get -y install apt-transport-https + + apt-get install -y dialog + + apt-get install -y wget + + apt-get install -y vim + + wget -q -O - https://apt.enterprisedb.com/edb-deb.gpg.key | apt-key add - + + apt update + + apt-get -y install edb-as12-server + + /usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log start + + + + /usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log restart + + + +su - enterprisedb + +docker run -itd -v /opt/edb-as:/var/lib/edb-as/ -v /var/log/edb-as:/var/log/edb-as -p 5444:5444 --name=myedb myedb:12 /bin/bash + + + + + +docker run -itd -v /opt/edb-as:/var/lib/edb-as/ -v /var/log/edb-as:/var/log/edb-as/ -p 5444:5444 --name=myedb_v2 myedb:12_v2 /bin/bash + + + +su enterprisedb && /usr/lib/edb-as/12/bin/pg_ctl -D /var/lib/edb-as/12/main -l /var/log/edb-as/edb-as-12-main.log restart + + + + + + + + + +docker run -itd -p 5445:5444 --name=myedb_test myedb:12 /bin/bash \ No newline at end of file diff --git a/postgresql 数据备份 .md b/postgresql 数据备份 .md new file mode 100644 index 0000000..52b9566 --- /dev/null +++ b/postgresql 数据备份 .md @@ -0,0 +1,14 @@ +## postgresql 数据备份 + + + + + +以9.6为例 + +root 账号进入 /opt/postgresql/as9.6/bin + + + +执行 + diff --git a/postgresql导入导出.md b/postgresql导入导出.md new file mode 100644 index 0000000..2275f5a --- /dev/null +++ b/postgresql导入导出.md @@ -0,0 +1,134 @@ +``` +//导入 +pg_restore +psql -Uicc -dicc -f ./xxx.sql +psql -Uicc -dicc -h10.23.101.52 -f ./schema/tables/table.sql + +//导出表 模式 数据 +pg_dump -h10.23.101.52 -Uicc -dicc> ~/dum.sql +pg_dump -h10.23.101.52 -Uicc -dicc -f icc.dmp + +报错停止 -v ON_ERROR_STOP=1 + +-a 只要数据 +-s 只要表结构 +-O 不设置表归属 +-n, --schema=SCHEMA 只转储指定名称的模式 +-T 排除表 +-t 指定表 +-Z 压缩0-9 + + +pg_dump -U postgres vendemo | gzip > /vendemo.gz 备份下来只有30多k + +// 导出压缩文件 +pg_dump -h10.23.101.52 -Uicc -dicc -t 表名 -t表名 -a -O | gzip > iccData.gz +pg_dump -Uicc -dicc | gzip > iccData.gz + + +//导入压缩文件 +gzip -d iccData.gz | psql -Uicc -dicc -h10.23.101.52 +//没测试过 +psql -Uicctestedb -dicctestedb < gzip -d iccData.gz + + + + +psql -U iccedb -d iccedb -h 192.168.53.118 -n 'icc2' | gzip > ~/iccedb_icc2_202206301142.gz + +psql -U iccedb -d iccedb -h 192.168.53.118 -v schema=icc2 | gzip > ~/iccedb_icc2_202206301142.gz + + + + + +pg_dump -Uenterprisedb -dicc -h10.23.101.119 \ +-T icc.t_icc_inv_leg \ +-T icc.t_icc_inv_leg_rate \ +-T icc.tcn_stat_new | gzip > ~/icc_icc_202207081500.gz + + + +./pg_dump -Uenterprisedb -dicc -h10.23.101.119 -O \ +-n icc -s \ +-f ~/icc_data_20220719_2130.sql + +yiing&654 + + + + + + +#导出 icc 模式下 排除 t_icc_inv_seg 等表 采用自定义格式压缩等级9(最大) + +./pg_dump -Uenterprisedb -dicc -h10.23.101.119 \ +-O -v -F c -Z 9 \ +-t 'icc.*' \ +-T '*.t_icc_inv_seg' \ +-T '*.t_icc_inv_leg_rate' \ +-T '*.t_icc_hsd_inv_leg' \ +-T '*.t_icc_inv_leg' \ +-T '*.tcn_stat_new' \ +-T '*.tcn_stat_sales_volume_total' \ +-T '*.t_foreign_ticket_record' \ +-T '*.tcn_stat_sales_volume_tmp' \ +-T '*.t_icc_hsd_inv_seg' \ +-T '*.tcn_stat_sales_volume' \ +-T '*.t_icc_inv_seg_cabin' \ +-f ~/icc_data_20220719_test.sql + + +#恢复 + +./pg_restore -Uenterprisedb -dtest2 -h10.23.101.119 \ +-F c ~/icc_data_20220719_test.sql + + + + + + + +uat +psql -Uiccedb -diccedb -h192.168.53.118 -f ~/ + + +sit +psql -Uicctestedb -dicctestedb -h192.168.53.123 -f ~/ +``` + + + + + + + + + + + +导出导出部分数据 + +``` +COPY (select * from icc.tcn_stat +where afferent_date between to_date('20220701','yyyymmdd') and to_date('20220714','yyyymmdd') ) TO '/home/edbdata/test.csv' WITH csv; + + + +COPY ( + +select * from icc.tcn_stat_sales_volume_total +where flight_date between to_date('20220701','yyyymmdd') and to_date('20221231','yyyymmdd') + +) TO '/home/edbdata/tcn_stat_sales_volume_total.csv' WITH csv; + + + + +COPY tcn_stat_sales_volume_total FROM '/home/edbdata/tcn_stat_sales_volume_total.csv' WITH csv; + + + +``` + diff --git a/postgresql锁表查询.md b/postgresql锁表查询.md new file mode 100644 index 0000000..7fb2256 --- /dev/null +++ b/postgresql锁表查询.md @@ -0,0 +1,39 @@ +``` +SELECT locker.pid, + pc.relname, + locker.mode, + locker_act.application_name, + least(query_start,xact_start) start_time, + locker_act.state, + CASE + WHEN granted='f' THEN + 'wait_lock' + WHEN granted='t' THEN + 'get_lock' + END lock_satus,current_timestamp - least(query_start,xact_start) AS runtime, + locker_act.query +FROM pg_locks locker,pg_stat_activity locker_act, pg_class pc +WHERE locker.pid=locker_act.pid + AND NOT locker.pid=pg_backend_pid() + AND application_name<>'pg_statsinfod' + AND locker.relation = pc.oid + AND pc.reltype<>0 --and pc.relname='t' +ORDER BY runtime desc; + + +SELECT pg_terminate_backend(14448) + +``` + + + +``` +playboy=> select pg_size_pretty(pg_total_relation_size('test')); //查看表的总大小,包括索引大小 + pg_size_pretty + + playboy=> select pg_size_pretty(pg_relation_size('test')); //以KB,MB,GB的方式来查看表大小 + pg_size_pretty + + +``` + diff --git a/使用 ora2pg 将oracle 数据导入 postgresql.md b/使用 ora2pg 将oracle 数据导入 postgresql.md new file mode 100644 index 0000000..9ab7248 --- /dev/null +++ b/使用 ora2pg 将oracle 数据导入 postgresql.md @@ -0,0 +1,548 @@ +# 使用 ora2pg 将oracle 数据导入 postgresql + +## 安装edb +##### 安装edb 源 + +``` + +yum -y install https://yum.enterprisedb.com/edbrepos/edb-repo-latest.noarch.rpm + +``` + +##### 设置账号密码 + +``` + +sed -i "s@:@start:oIVqaoGTDFL5aYHD@" /etc/yum.repos.d/edb.repo + +``` + +##### 安装 扩展包 源 + +``` + +yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + +``` + +##### 安装edb + +``` + +yum -y install edb-as14-server + +``` + +##### 初始化 + +``` + +PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as14/bin/edb-as-14-setup initdb + +PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as12/bin/edb-as-12-setup initdb + + + +PGSETUP_INITDB_OPTIONS="-E UTF-8 -D /home/edbdata" /usr/edb/as12/bin/edb-as-12-setup initdb + +``` + +##### 启动 edb + +``` + +systemctl start edb-as-14 + +``` + +##### 连接edb +``` + +sudo su - enterprisedb +psql edb + +``` + + + + +### 常见问题 + +- 远程连接数据库失败 修改文件 data/pg_hba.conf 添加 + + ``` + + host all all 0.0.0.0/0 md5 + + ``` + +- 修改数据库密码(在edb 库执行) + + ``` + + ALTER USER enterprisedb WITH PASSWORD 'yiing&654'; + + ``` + + + + + +## 安装 ora2pg + +### 安装 perl 环境 + +``` +yum install -y perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker +yum -y install perl-CPAN +``` + + + +### 安装Oracle客户端 + +官网下载 Oracle Instant Client 等包 上传服务器安装 + +``` +rpm -ivh oracle-instantclient19.15-basic-19.15.0.0.0-1.x86_64.rpm +rpm -ivh oracle-instantclient19.15-devel-19.15.0.0.0-1.x86_64.rpm +rpm -ivh oracle-instantclient19.15-jdbc-19.15.0.0.0-1.x86_64.rpm +rpm -ivh oracle-instantclient19.15-sqlplus-19.15.0.0.0-1.x86_64.rpm +``` + + + +#### 设置环境变量ORACLE_HOME +``` +export ORACLE_HOME=/usr/lib/oracle/19.15/client64/ +``` + + + +#### 本地已安装有Oracle数据库 + +ORACLE_HOME如下设置 + +``` +export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 +export LD_LIBRARY_PATH=$ORACLE_HOME/lib +``` + + + +### 安装 perl 依赖 + +``` +perl -MCPAN -e 'install DBD::Oracle' +perl -MCPAN -e 'install DBI' +perl -MCPAN -e 'install DBD::Pg' +``` + +按照自己 的路径设置 环境变量 + +``` +export POSTGRES_HOME=/usr/edb/as14 +export POSTGRES_HOME=/var/lib/edb/as14 +``` + + + +#### 常见问题 + +``` +Can't locate Test/NoWarnings.pm in @INC (@INC contains: t/lib /root/.cpan/build/DBD-Oracle-1.83-LDK8k0/blib/lib /root/.cpan/build/DBD-Oracle-1.83-LDK8k0/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at t/26exe_array.t line 15. +``` + + 安装 perl-Test-NoWarnings-1.04-2.el7.noarch 解决 + + + +提示测试不通过 手动下载源码 安装 + +下载地址:https://metacpan.org/release/DBI + +``` +tar -zxvf DBI-1.642.tar.gz +cd DBI-1.642 +perl Makefile.PL +make +make install +``` + + + + + + + +### 安装ora2pg + +下载软件包 +https://github.com/darold/ora2pg/releases + +默认安装在`/usr/local/bin/` 目录下 + +``` +[root@Test01 ~]# tar -xjf ora2pg-20.0.tar.bz2 +[root@Test01 ~]# cd ora2pg-xx/ +[root@Test01 ~]# perl Makefile.PL PREFIX= +[root@Test01 ora2pg-18.2]# make && make install +``` + +简单检查 +ora2pg --help + +## 迁移数据 +### 初始化项目 + +``` +//初始化项目 +ora2pg --init_project ora2pg + + +ora2pg -t SHOW_VERSION -c config/ora2pg.conf +ora2pg -t SHOW_SCHEMA -c config/ora2pg.conf +ora2pg -t SHOW_TABLE -c config/ora2pg.conf +ora2pg -t SHOW_COLUMN -c config/ora2pg.conf +ora2pg -t SHOW_ENCODING -c config/ora2pg.conf +``` + +### 配置配置文件 + +默认配置文件即可 需要修改 + +``` +# Set Oracle database connection (datasource, user, password) +ORACLE_DSN dbi:Oracle:host=dev-db.yldev.net;sid=hcc;port=1521 +ORACLE_USER icc +ORACLE_PWD ICCICC + +# Oracle schema/owner to use +SCHEMA ICC + + + +# Set which object to export from. By default Ora2Pg export all objects. +# Value must be a list of object name or regex separated by space. Note +# that regex will not works with 8i database, use % placeholder instead +# Ora2Pg will use the LIKE operator. There is also some extended use of +# this directive, see chapter "Limiting object to export" in documentation. + + +# 可以使用正则 如 t_.* 可以排除 不想导出的对象 如!t_t2 +#配置中文释义 https://blog.csdn.net/Loiterer_Y/article/details/110927688 +#ALLOW TABLE_TEST + +# The value can be a comma delimited list of schema but not when using TABLE +# export type because in this case it will generate the CREATE SCHEMA statement +# and it doesn't support multiple schema name. For example, if you set PG_SCHEMA +# to something like "user_schema, public", the search path will be set like this +# SET search_path = user_schema, public; +# forcing the use of an other schema (here user_schema) than the one from Oracle +# schema set in the SCHEMA directive. You can also set the default search_path +# for the PostgreSQL user you are using to connect to the destination database +# by using: +# ALTER ROLE username SET search_path TO user_schema, public; +#in this case you don't have to set PG_SCHEMA. +#PG_SCHEMA LLOW +PG_SCHEMA icc +``` + + + +### 测试连接 + +执行以下命令 返回oracle 版本则连接成功 + +``` +ora2pg -t SHOW_VERSION -c config/ora2pg.conf +``` + + + +### 导出表结构 + +先安装 screen 防止意外断开 导出失败 + +``` +yum install -y screen + +``` + +#### screen 常用命令 + +``` +//开启一个screen +screen -S name +//进入一个 screen +screen -r name +// screen 列表 +screen -ls + +可以用快捷键 Ctrl+a d(即按住 Ctrl,依次再按 a,d),而会话中的程序不会关闭 +``` + + + +### 导出数据 + +该命令根据数据库大小 表大小等待时间不一 建议使用screen 运行 + +``` +ora2pg -t COPY -o data.sql -b ./data -c ./config/ora2pg.conf +``` + + + +### 修改校验表结构 + +导出完成后 在 `./schema/tables` 下有转换好的表结构(主要修改关键字段) + +``` +oid +tableoid +xmin +cmin +xmax +cmax +ctid +``` + + + +### 导入数据库 + +切换到`enterprisedb` 用户 + +执行 `sh import_all.sh` 按照提示导入数据 + + + +## 附录 + +#### 修改用户组 权限 + +``` +chown [-R] ownname:groupname filename +chmod -R 777 filename + +``` + +#### 追踪服务日志 + +``` +journalctl -f -u icc-analysis.service +``` + +#### 查看文件大小 + +``` +df -hl +df -h path +ls -lht + +du -ah --max-depth=1 /path + +查看删除的文件 +lsof -n | grep deleted + +du -bsh / +``` + +#### Linux 替换命令 sed + +``` +参数说明: + +-e