Centos 清理空间

df -h 列出磁盘占用率
df -i 查询inode占用情况
在根目录执行du -h -x –max-depth=1 列出目录占用空间情况
可能的原因是已经删除的文件,被占用,导致空间不释放。
lsof / | grep deleted
列出的文件,如果占用空间不是0,则说明是这个原因。
随意查看占用的进程,重启即可。

发表在 待分类 | Centos 清理空间已关闭评论

VNC隐藏图标静默运行

注册表找到

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\vncserver]

将ImagePath里的内容”C:\Program Files\RealVNC\VNC Server\vncserver.exe” -service 改为

“C:\Program Files\RealVNC\VNC Server\vncserver.exe” -service -DisableTrayIcon=1

重启,可以看到右下角已经没有VNC图标了。

用vncview连接时,服务端还是可以提示已经连接。

发表在 待分类 | VNC隐藏图标静默运行已关闭评论

Mysql的备份与还原操作

1、命令行登录mysql
mysql -ujhy -pjKwBwCJHTXrRFMss
use jhy

2、mysqldump备份
mysqldump -u jhy -pjKwBwCJHTXrRFMss jhy JHYTHB2020 > /www/wwwroot/jhy/FTP/JHYTHB2020.sql ;

3、导入数据库
mysql -userver -pXCFmP55dAbJL4Kr3 server < /www/wwwroot/server/JHYTHB2020.sql
另一种方式
mysql -userver -pXCFmP55dAbJL4Kr3
use server
source /www/wwwroot/server/JHYTHB2020.sql

4、压缩备份
mysqldump -usl_yxbl_ltd -pjJw5pPT7PzAEf2Hd sl_yxbl_ltd sl1xxc2022 | gzip> /www/wwwroot/sl/sl1xxc2022.sql.gz ;

5、连续操作
wget http://sl.yxbl.ltd/sl1xxc2022.sql.gz && gunzip < /www/wwwroot/server/sl1xxc2022.sql.gz | mysql -userver -pXCFmP55dAbJL4Kr3 server

6、备份表中提取数据到当前数据库
rename table sl2xrh to sl2xrhold,tmp2023 to sl2xrh;
insert into sl2xrh select * from sl2xrhold where time between '2023-01-01 00:00:00' and '2024-01-01 00:00:00';

发表在 待分类 | Mysql的备份与还原操作已关闭评论

Centos7运行OpenVPN Client

云端的一台服务器需要连接内网资源,路由器采用ikuai路由器。采用OpenVPN方式连接到内网的方法:

1、路由器下载配置文件。重命名为.ovpn格式可以被更多客户端识别。
一个典型的配置文件:

client
dev-type tun
dev tunx
proto udp
tun-mtu 1400
cipher AES-128-CBC
comp-lzo
remote ip1 1195
remote ip2 1195
resolv-retry infinite
nobind
persist-key
persist-tun
verb 3
auth-user-pass  /etc/openvpn/client/密码文件
log-append /etc/openvpn/client/日志文件
script-security 2
keepalive 5 10
auth-nocache
daemon

<ca>
-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgIJAKKxdPvAYYRXMA0GCSqGSIb3DQEBCwUAMDcxCzAJBgNV
BAYTAkNOMQ4wDAYDVQQKDAVpS3VhaTEYMBYGA1UEAwwPaUt1YWkgRGV2aWNlIENB
-----END CERTIFICATE-----
</ca>

# redirect-gateway def1 bypass-dns  # uncomment to set as default gateway
# route-nopull  # uncomment to disable server route push
#

2、修改配置文件。
remote 可以写两行,第一个不通时会自动第二个。
;指定密码文件位置:
auth-user-pass /etc/openvpn/client/ovjhy.auth
;增加用户名和密码文件ovjhy.auth
首行为用户名
第二行为密码

;指定日志文件路径
log-append /etc/openvpn/client/log_JHY.log
;增加保活参数 5秒一次ping心跳,10秒收不到认为离线
keepalive 5 10

3、CentOS安装OpenVPN
yum install openvpn

4、上传配置文件到服务器 /etc/openvpn/client/目录。

5、运行VPN

openvpn /etc/openvpn/client/JHY.ovpn
openvpn /etc/openvpn/client/JHY.ovpn > /dev/null &
openvpn /etc/openvpn/client/JHY.ovpn > /etc/openvpn/client/JHY.log &
;静默方式运行
openvpn –daemon –config /etc/openvpn/client/JHY.ovpn
;指定log目录的方式运行
openvpn –daemon –config /etc/openvpn/client/JHY.ovpn –log-append /var/log/openvpn.log

6、开机自动启动

测试可以正常启动,但会异常停止,未明原因;
创建服务文件
/etc/systemd/system/openvpn-client@.service

[Unit]
Description=OpenVPN client for %i
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/sbin/openvpn --daemon --config /etc/openvpn/client/%i.ovpn --log-append /var/log/openvpn_%i.log
Restart=on-failure

[Install]
WantedBy=multi-user.target

//禁用服务
sudo systemctl disable openvpn-client@JHY
//使能服务
sudo systemctl enable openvpn-client@JHY
//启动服务
sudo systemctl start openvpn-client@JHY
//查看服务状态
sudo systemctl status openvpn-client@JHY
//启动服务
sudo systemctl stop openvpn-client@JHY
//刷新服务配置文件
systemctl daemon-reload

7、宝塔定时任务守护和开启VPN

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#------------------------------
#获取进程的号码
processnum=`ps -ef | grep "openvpn --daemon --config /etc/openvpn/client/JHY.ovpn" | grep -v "grep" | awk '{print $2}'`
#杀死进程
#echo $processnum 
#kill -9 $processnum
#获取进程统计数量
count=`ps -ef | grep "openvpn --daemon --config /etc/openvpn/client/JHY.ovpn" | grep -v "grep" | wc -l`
echo $count  #输出统计数量
if [ 0 == $count ];then
	#启动进程
    openvpn --daemon --config /etc/openvpn/client/JHY.ovpn
	endDate=`date +"%Y-%m-%d %H:%M:%S"`
	echo "[$endDate] Start OpenVPN.JHY"
fi
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"

8、OpenVPN的优化
加密方式应该更新为AES-256-GCM,先用的256-CBC方式未来会被不支持。

9、多连接下的配置
dev tunx
这个tunx在每个连接时不能相同,不然会引起冲突。需要每个连接用不同的名称来命名。

发表在 待分类 | Centos7运行OpenVPN Client已关闭评论

NodeMCU 用LFS增加内存空间

http://192.168.99.10/test/ 内网服务器上,有个服务,可以将lua代码压缩后生成zip文件上传生成lfs.img文件。

<?php
ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
print_r($_FILES); // Debug
$dbgErrLog = "web-luac-cross.log";
$zipFile = $_FILES['name']['tmp_name'];
$upLoadName = $_FILES['name']['name'];
$zipName = basename($upLoadName);
$entries = [];
/*
* Clean up and exit on error
*/
function abort($error) {
  global $zipFile, $zip, $entry, $tempDir;
  if (is_uploaded_file($zipFile)) unlink($zipFile);
  if (is_resource($zip)) zip_close($zip);
  if (is_resource($entry)) zip_entry_close($entry);
  $dbgOP = ob_get_contents();
  file_put_contents($dbgErrLog, $dbgOP);
  ob_end_clean();
  $resp = htmlentities($error, ENT_QUOTES | ENT_IGNORE, "UTF-8");
  $resp = <<<EOD
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Luac.cross compile error</title></head>
<body><pre>$resp</pre></body></html>
EOD;
  http_response_code(404);
  header('Cache-Control : no-cache, no-store, must-revalidate, max-age=0');
  header('Content-type : text/html;charset=UTF-8');
  header('Content-Length: ' . strlen($resp));
  echo $resp;
  exit();
}
// Open uploaded ZIPfile, aborting on error
if (!preg_match('/^([[:alpha:]_]\w{1,32}).zip$/i', $zipName,$matches)) {
    abort("Zip file must conform to Lua variable name convention with .zip extention");
} else {
    $imageName = $matches[1].'.img';
}
if (!is_uploaded_file($zipFile)) abort("No zip file uploaded");
$zip = zip_open($zipFile);
if (!is_resource($zip)) abort("File is not a valid ZIP format");
// Unpack the uploaded ZIP file into a tmpdir
$tempDir = tempnam(sys_get_temp_dir(), 'luac_dir');
if (file_exists($tempDir)) unlink($tempDir);
mkdir($tempDir);
while (is_resource($entry = zip_read($zip))) {
  $name = basename(zip_entry_name($entry));
  $entryName = "${tempDir}/${name}";
  // Filenames must have a valid Lua name root
  if (preg_match('/^[[:alpha:]_]\w*.lua$/', $name)) {
    echo "$entryName found\n"; // Debug
    $entries[] = $entryName;
    $contents = '';
    while (($chunk = zip_entry_read($entry,8192))) {
      $contents .= $chunk;
    }
    zip_entry_close($entry); $entry = NULL;
    file_put_contents($entryName, $contents);
  }
}
zip_close($zip); $zip = NULL;
if (count($entries)==0) abort("ZIP contains no Lua files");
$luaFiles = implode (" ", $entries);
$outLFS = "${tempDir}/lfs.img";
exec("luac.cross -f -o ${outLFS} ${luaFiles}", $output, $status);
if ($status != 0) abort("luac.cross compile error: \n" . implode ("\n", $output) );
$LFSimage = file_get_contents($outLFS);
file_put_contents(time().".img",$LFSimage);
exec("rm -rf ${tempDir}");
file_put_contents($dbgErrLog, ob_get_contents());
ob_end_clean();
http_response_code(200);
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=LFS.img");
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen($LFSimage));
echo $LFSimage;

就是采用luac.cross将lua文件打包。对于esp8266小内存mcu效果良好。

发表在 待分类 | NodeMCU 用LFS增加内存空间已关闭评论

NodeMCU将自主程序打包入固件

当前仅介绍生成带程序固件的方法,如何编译自定义固件不在本文介绍。

固件可以为自主编译也可为公开固件,

获取spiflash的起始地址,执行lua脚本:

do
  local s,p={},node.getpartitiontable()
  for _,k in ipairs{'lfs_addr','lfs_size','spiffs_addr','spiffs_size'} do
    s[#s+1] ='%s = 0x%06x' % {k, p[k]}
  end
  print ('{ %s }' % table.concat(s,', '))
end

得到spiffs_addr
0x088000

第二步:./spiffsimg -f 88000.img -S 1MB -U 557056 -r lua.script

lua.script文件内容为:需要生成的文件

import /root/nodemcu-firmware/local/fs/init.lua init.lua
import /root/nodemcu-firmware/local/fs/index.html.gz index.html.gz
import /root/nodemcu-firmware/local/fs/LFS.img LFS.img
ls

其中557056是0x088000的十进制。

得到flash内容为88000.img的文件。

在linux环境中,将nodemcu的固件合并为烧录文件的方法:

srec_cat -output “temp.bin” -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
srec_cat -output “nodemcu_32mb.bin” -binary temp.bin -binary -fill 0xff 0x00000 0x088000 lua.img -binary -offset 0x088000

在windows中,https://srecord.sourceforge.net/download.html 下载安装软件

cd C:\Program Files\srecord\bin
srec_cat.exe -output "nodemcu_32mb.bin" -binary temp.bin -binary -fill 0xff 0x00000 0x088000 lua.img -binary -offset 0x088000

得到的nodemcu_32mb.bin烧录到MCU即可。

发表在 待分类 | NodeMCU将自主程序打包入固件已关闭评论

金蝶云星空动态打开外部URL

实现目的:在金蝶单据内通过按钮查询外部系统的相关联数据

实现步骤:1、增加菜单栏按钮,在菜单集合内添加。并且去掉新增可见属性

2、注册python插件

import clr
clr.AddReference("System")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.Contracts")
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from System import *
from System.ComponentModel import *
from System.Collections.Generic import *
from System.Text import *

# 表单插件 - 按钮点击事件处理函数
# 点击按钮:最先执行
def BarItemClick(e):
     if e.BarItemKey == "UNW_web":
        #this.View.ShowMessage("这是BarItemClick按钮测试")
        url = "http://www.baidu.com/s?wd="+ this.Model.GetValue("FBillNo").ToString();
        this.View.AddAction("ShowWebURLExt", url);
        #this.View.SendDynamicFormAction(this.View);

# def AfterBarItemClick(e):
#     if e.BarItemKey == "UNW_web":
#         this.View.ShowMessage("这是AfterBarItemClick按钮测试")
发表在 待分类 | 金蝶云星空动态打开外部URL已关闭评论

清理系统的winsxs目录

检查:Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore
清理: DISM.exe /online /Cleanup-Image /StartComponentCleanup

发表在 待分类 | 清理系统的winsxs目录已关闭评论

phar文件解密

<?php
$phar = new Phar('file.phar');
$phar->extractTo('file/',null,true);
?>

金蝶发布的PHP版本的sdk采用了phar格式的形式来提供的。将php的源文件进行打包,调用的时候引用这个文件就可以。但是没有源文件的SDK就是一个黑盒,看源文件才能更灵活的掌握SDK,上边的方法就得到php源文件了。

发表在 待分类 | phar文件解密已关闭评论

通过管理员权限自动运行bat文件的方法

@echo off&color 17
if exist "%SystemRoot%\SysWOW64" path %path%;%windir%\SysNative;%SystemRoot%\SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
exit /B
:UACAdmin
cd /d "%~dp0"
net stop "CCCloudConnect"
timeout 10
net start "CCCloudConnect"
发表在 待分类 | 通过管理员权限自动运行bat文件的方法已关闭评论