window下查找监听端口进程并关闭

问题: 测试mock服务程序在windows下运行,强制关闭后终端cmd后再次启动时发现, 端口已经被占用。 F:\mock\server1>go run server.go Starting server... listen tcp :60001: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x18 pc=0xc6f2a0] goroutine 1 [running]: main.main() F:/mock/server1/server.go:163 +0x260 exit status 2 解决: 可以用下面方式查找并删除 F:\mock\server1>netstat -ano|findstr 60001 TCP 0.0.0.0:60001 0.0.0.0:0 LISTENING 25768 TCP [::]:60001 [::]:0 LISTENING 25768 F:\mblb\mock\server1>tasklist|findstr 25768 server.exe 25768 RDP-Tcp#40 1 7,280 K F:\mblb\mock\server1>taskkill /f /pid 25768 成功: 已终止 PID 为 25768 的进程。 F:\mblb\mock\server1>tasklist|findstr 25768 参考及引用: 关于taskkill 和 netstat 可以通过 /? 方式查看 ...

2022-11-29 · 2 min · 414 words

python tuple 一个元素时需要增加逗号

项目中使用python tuple时如果是一个元素一定要增加一个逗号,使用python3看下输出。 >>> t(0) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 't' is not defined >>> t=(0) >>> print(type(t)) <class 'int'> >>> print(t) 0 >>> t=(0,) >>> print(type(t)) <class 'tuple'> >>> print(t) (0,) 官方文档中描述: Note that it is actually the comma which makes a tuple, not the parentheses. The parentheses are optional, except in the empty tuple case, or when they are needed to avoid syntactic ambiguity. For example, f(a, b, c) is a function call with three arguments, while f((a, b, c)) is a function call with a 3-tuple as the sole argument. ...

2022-05-08 · 1 min · 139 words

mysql error 1364 Field doesn't have a default values

问题描述 前一阵在做一个系统迁移工作, mysql数据库版本进行了升级, 数据库mariadb版本原有版本 5.5.56,升级后版本10.3.9. $ mysql -V or $ mysql > select version(); 升级后原有功能报1364错误, 原因由于数据库中的SQL mode 默认定义调整。 可以通过以下命令进行看出 $mysql -u -e "select @@sql_mode" mysql 5.7版本以后默认打开了打开了STRICT_TRANS_TABLES。 可以通过配置文件修改,设置为"“则为取消 [mysqld] sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 或者使用sql, 多个模式间的用逗号分割不能有空格。 >SET session sql_mode = 'modes...'; 立即生效设置当前session sql_mode sql_mode mysql 文档关于STRICT_TRANS_TABLES描述。 Strict SQL Mode Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE. 严格模式控制MySQL如何处理数据如插入或更新中的无效值。例如,它可能具有错误的列数据类型,或者可能超出范围。当要插入的新行不包含一个非NULL列的值时,其定义中没有明确的默认子句。(对于null列,如果丢失了值,则将插入空。)严格模式还会影响诸如创建表之类的DDL语句. ...

2022-04-30 · 2 min · 348 words

git 常用命令

查看分支 git branch -av 导出分支 git remote add origin ssh://git@ip:port/branch.git git checkout -b localbranch origin/remotebranch 稀疏导出 git init <project> cd <project> git config core.sparsecheckout true echo "path1/" >> .git/info/sparse-checkout echo "path2/" >> .git/info/sparse-checkout git pull origin remotebranch 恢复误删除文件 git status git reset HEAD git checkout . non-fast-forward git fetch origin master git merge origin FETCH_HEAD 本地rebase导致non-fast-forward git reflog 查看HEAD的移动历史 git reset --hard xxxx 提交 git push origin localbranchname 参考及引用 图片 from 墨玉

2022-04-05 · 1 min · 72 words

vim putty gruvbox

putty 使用的是putty进行访问,可以使用gruvbox 提供的配色访问进行调整。 可以使用下面链接进去: https://github.com/morhetz/gruvbox-contrib/tree/master/putty 其他工具 如果使用是其他工具也可以找到对应的工具 https://github.com/morhetz/gruvbox-contrib 操作系统自带Vim 如果使用的操作系统自带Vim工具,可以下载下面工具编辑~/.vimrc $ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim $ cat ~/.vimrc 。。。 call plug#begin() Plug 'morhetz/gruvbox' call plug#end() 。。。 $ vi打开后 :PlugInstall grubbox提供的一些安装方法 https://github.com/morhetz/gruvbox/wiki/Installation 参考及引用 https://opensource.com/article/20/2/how-install-vim-plugins 图片from 江金倫 彰化縣-竹塘鄉-竹塘木棉道

2022-03-21 · 1 min · 38 words

centos8 yum 相关国内镜像仓库弃用(deprecated)

今天centos8使用yum安装软件时报错。 - Curl error (28): Timeout was reached for http://mirrors.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Connection timed out after 30001 milliseconds] - Status code: 404 for https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 42.81.213.224) 查看一下:https://mirrors.aliyun.com/centos/8/readme This directory (and version of CentOS) is deprecated. 由于只是安装tcpdump,目前临时解决方案调整了一下安装源。 # echo "8-stream" > /etc/yum/vars/releasever # yum clean all # yum makecache 如果未使用国内镜像也可以手工更新到 vault.centos.org 镜像地址 # cd /etc/yum.repos.d/ # sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* # sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* # yum update -y 镜像地址更新成功后可以升级到centos stream。 # dnf install centos-release-stream -y --allowerasing # dnf distro-sync -y 更详细可以参考引用链接 ...

2022-02-03 · 1 min · 91 words

centos8 过滤 syslog信息

服务器(centos8)在用户登录的时候会出现一些登录日志。 example.com systemd[1]: Started /run/user/0 mount wrapper. example.com systemd[1]: Created slice User Slice of UID 0. example.com systemd[1]: Starting User Manager for UID 0... example.com systemd[1]: Started Session 51 of user root. example.com systemd[20871]: Starting D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Timers. example.com systemd[20871]: Reached target Paths. example.com systemd[20871]: Listening on D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Sockets. example.com systemd[20871]: Reached target Basic System. example.com systemd[20871]: Reached target Default. example.com systemd[20871]: Startup finished in 51ms. example.com systemd[1]: Started User Manager for UID 0. example.com systemd[1]: session-51.scope: Succeeded. example.com systemd[1]: Stopping User Manager for UID 0... example.com systemd[20871]: Stopped target Default. example.com systemd[20871]: Stopped target Basic System. example.com systemd[20871]: Stopped target Sockets. example.com systemd[20871]: Stopped target Paths. example.com systemd[20871]: dbus.socket: Succeeded. example.com systemd[20871]: Closed D-Bus User Message Bus Socket. example.com systemd[20871]: Reached target Shutdown. example.com systemd[20871]: Starting Exit the Session... example.com systemd[20871]: Stopped target Timers. example.com systemd[1]: user@0.service: Killing process 20967 (systemctl) with signal SIGKILL. example.com systemd[1]: user@0.service: Succeeded. example.com systemd[1]: Stopped User Manager for UID 0. example.com systemd[1]: Stopping /run/user/0 mount wrapper... example.com systemd[1]: Removed slice User Slice of UID 0. example.com systemd[1]: run-user-0.mount: Succeeded. example.com systemd[1]: user-runtime-dir@0.service: Succeeded. example.com systemd[1]: Stopped /run/user/0 mount wrapper. 通过下面命令生成rsyslog的过滤规则; echo 'if $programname == "systemd" and ($msg contains "Started /run/$msg" or $msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Created slice User" or $msg contains "Starting User Manager" or $msg contains "Starting User" or $msg contains "Starting D-Bus" or $msg contains "Reached target" or $msg contains "Listening on D-Bus" or $msg contains "Startup finished" or $msg contains "session-" or $msg contains "Stopping User Manager" or $msg contains "Stopped target" or $msg contain "dbus.socket" or $msg contains "Stopped target " or $msg contains "Removed session" or $msg contains "Removed slice User Slice of" or $msg contains "Stopped /run/user" or $msg contains "Stopped User Manager" or $msg contains "Stopping User Slice of" ) then stop' >/etc/rsyslog.d/ignore-systemd-session-slice.conf 根据实际情况, 新增相关过滤规则即可 ...

2022-01-02 · 2 min · 341 words

C++ pointers 和reference

Pointer 和 references 主要区别 reference:总代表一个对象, 没有null reference;pointer则没有限制,可以为null poiner可以被重新赋值; reference不可以被重新赋值。 应用场景 如果在不同时间指向不同对象则使用pointer, 如果一旦代表该对象就不能改变选择reference. 相关代码: 使用reference更富效率, 如下面的例子,不需要测试rd的值,他代表某一个double void printDouble(const double &rd) { cout << rd; } 而如果用pointers,那么就得测试下他是否为null。 void printDouble(const double *pd) { if (pd) { cout << *pd; } } 其他: 当然也有例外, 比如leveldb中就可以看到一下issue,DB::Get API should use reference instead of pointer #140 可以看到在下面一段描述,这里主要讨论关于函数参数使用引用还是指针。 Original issue 134 created by jvb127 on 2013-01-03T06:36:56.000Z: The current DB::Get API is defined as: virtual Status Get(const ReadOptions& options, const Slice& key, std::string* value) = 0; However, 'value' is not an optional parameter - it should point to a valid std::string. This is not checked by the implementation It could be considered to use a reference rather than a pointer: virtual Status Get(const ReadOptions& options, const Slice& key, std::string& value) = 0; 可以看到在google早些年的开发指南中,使用指针定义参数列表的参数和引用,通过const区分输入,输出参数。 ...

2021-10-25 · 2 min · 267 words

docker 安装 Wordpress 及更新

今天登录到博客提示需要升级php,更新了下镜像顺便把之前搭建的步骤整理了一下。 搭建流程: 申请宿主机器,我用是centos。 使用docker-compose完成进行wordpress安装; 申请域名,使用Let’s Encrypt申请域名证书,使用ngnix提供 https服务。 宿主机申请,域名申请, 可以自行选在有些云服务商是同时提供DNS服务的。 镜像安装 安装docker及docker-compose 1)官网安装步骤 : https://docs.docker.com/engine/install/ 2)参考知乎的一篇文章: https://zhuanlan.zhihu.com/p/93832797。 我使用的略做了调整: version: '3.3' services: db: image: mariadb:latest volumes: - ./db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: {mysqlroot密码} MYSQL_DATABASE: {数据库名称} MYSQL_USER: {用户名} MYSQL_PASSWORD: {用户密码} wordpress: depends_on: - db image: wordpress:latest volumes: - ./wordpress:/var/www/html ports: - "{端口}:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: {用户名} WORDPRESS_DB_PASSWORD: {密码} WORDPRESS_DB_NAME: {数据库名称} 版本升级 wordpress提示升级, 只要更一下word press镜像及可以了 1)下载最新镜像 # docker pull wordpress 2) 删除容器 #docker ps -a #docker rm {对应镜像的容器id} 3) 删除镜像 ...

2021-08-24 · 1 min · 91 words

Vagrant 创建Centos8 环境

使用Vagrant重新搭建一个测试环境,只需要简单几步就可以启动一个测试环境。 Vagrant 起初是和VirtualBox绑定, 1.1版本后支持Vmware, 1.6版本支持Docker容器。 环境搭建 使用VirtualBox镜像,在工作目录执行以下指令: vagrant init centos/8 vagrant up 启动登录修改下密码: vagrant ssh 之后就可以putty进行远程访问(IP:127.0.0.1,Port:2222) 网络配置 要跑一个golang的服务程序,需要启动端口1718 。修改工作目录下的 Vagrantfile文件增加以下一行即可。 config.vm.network "forwarded_port", guest: 1718, host: 1718 重启一下服务, 网路端口生效。 vagrant reload 参考引用 https://zh.wikipedia.org/wiki/Vagrant Photo by Nick Kwan from Pexels

2021-05-07 · 1 min · 38 words