分类 技术 下的文章

frp管理端截图

因为家里有台蜗牛星际安装了WIN10作为下载机同时用hyper-v 和 docker 跑了一些服务,不在家的时候用vnc远程连接操作或者用vsc的远程开发连到hyper-v上的Centos6.5
下面介绍一下穿透内网vnc远程桌面内网机器的过程

家里用的是移动宽带,没有外网IP
不在家的话只好用内网穿透

不过前提条件是需要有一台有固定IP的VPS

内网是:WIN10 (客户端)
外网中转VPS (服务器端)
操作系统:CENTOS6.5
固定IP:123.123.123.123

我用的是
https://github.com/fatedier/frp
下载对应的文件,分别是
WIN10用 frp_0.31.2_windows_amd64.zip
CENTOS6.5用 frp_0.31.2_linux_arm64.tar.gz

服务器端

文件放在这里 /data/services/frp/
修改配置文件 frps.ini

[common]
bind_addr = 0.0.0.0
bind_port = 7100
# 设置管理后台的用户名和密码
dashboard_user = king
dashboard_pwd = king
dashboard_port = 7700

后执行测试一下
# frps -c frps.ini
通过浏览器访问
http://123.123.123.123:7700
这里要注意vps要配置一下防火墙放开 7100和7700两个端口
centos 就是
# vi /etc/sysconfig/iptables
添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7100 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7700 -j ACCEPT
保存后重启防火墙
# service iptables restart
当然你的VPS是在腾讯云这些云平台的话还要注意一下安全组的设置

客户端

下载的文件放在 c:/frp
修改frpc.ini

[common]
server_addr = 123.123.123.123 #这里要和上面配置的服务器端口一致
server_port = 7100

[vnc] #名称自定义
type = tcp #vnc走的是tcp
local_ip = 127.0.0.1 #本地IP
local_port = 5900 #vnc默认的端口
remote_port = 6000 #转发端口

然后执行
frpc.exe -c frpc.ini

然后手机断开WIFI在4G下用VNC连接 123.123.123.123:6000 测试一下

WIN10开机启动 frpc

用这个工具 https://github.com/kohsuke/winsw
下载对应平台的执行文件,我这里是
WinSW.NET461.exe
把执行文件改名为 winsw.exe 放到 c:/frp
添加新增一个配置文件 winsw.xml 放到 c:/frp

<service>
    <id>frp</id>
    <name>frp</name>
    <description>frp remote control</description>
    <executable>frpc</executable>
    <arguments>-c frpc.ini</arguments>
    <logmode>reset</logmode>
</service>

然后以管理员的身份cmd,执行如下命令
winsw install
winsw start
搞定!

CENTOS6.5开机启动 frps

添加文件 /data/services/frp/frps.sh
nohup /data/services/frp/frps -c /data/services/frp/frps.ini >> /data/services/frp/frps.log 2>&1 &
添加文件 /etc/init.d/frps

#!/bin/bash
#
# Comments to support chkconfig
# chkconfig: - 98 02
# description: your_prog_name service script
#
# Source function library.
. /etc/init.d/functions

### Default variables
prog_name="frps"
prog_path="/data/services/frp/frps.sh"
pidfile="/var/run/${prog_name}.pid"
prog_demon="frps"
options=""

# Check if requirements are met
[ -x "${prog_path}" ] || exit 1

RETVAL=0

start(){
  echo -n $"Starting $prog_name: "
  daemon $prog_path $options
  RETVAL=$?
  PID=$(pidof ${prog_demon})
  [ ! -z "${PID}" ] && echo ${PID} > ${pidfile}
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name
  return $RETVAL
}

stop(){
  echo -n $"Shutting down $prog_name: "
  killproc -p ${pidfile}
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name
  return $RETVAL
}

restart() {
  stop
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  status)
    status $prog_demon
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    RETVAL=1
esac

exit $RETVAL

执行以下命令
# chkconfig frps on 设置开机运行
# service frps start 启动
# service frps status 查看状态
# service frps stop 关闭

把下面脚本放到,路径自己决定
/data/services/godaddy/ddns.sh
然后 crontab -e 添加,频率自己修改
*/5 * * * * /data/services/godaddy/ddns.sh >> /data/services/godaddy/ddns.log

顺便找了几个获取公网IP的接口
http://ip-api.com/json/?lang=zh-CN

有频率限制,不能短时间内重复调用,应该是因为可以查任意IP归属地,所以限制了
http://ip.taobao.com/service/getIpInfo.php?ip=myip
这个也可以任意查任意IP归属地
http://ip-api.com/json/113.97.18.125?lang=zh-CN

http://www.taobao.com/help/getip.php

http://pv.sohu.com/cityjson

ddns.sh

# 你的域名,注意不包括主机名
domain="king.com"
# 主机名,支持泛域名哦也支持 @
name="*" 
# 登录 godaddy 查看
key="xxxxxxxxxxxxxxxx" 
# 登录 godaddy 查看
secret="xxxxxxxxxxx"

headers="Authorization: sso-key $key:$secret"
cur_dateTime="`date +%Y-%m-%d,%H:%M:%S`";
echo $cur_dateTime;
# echo $headers
result=$(curl -s -X GET -H "$headers" \
"https://api.godaddy.com/v1/domains/$domain/records/A/$name")
dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "dnsIp:" $dnsIp

# 获取你的公网IP
ret=$(curl -s GET "http://pv.sohu.com/cityjson")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "currentIp:" $currentIp
if [ "$dnsIp" != "$currentIp" ];
then
    echo "Ips are not equal"
    request='[{"data":"'$currentIp'","ttl":3600}]'
    echo $request
    nresult=$(curl -i -s -X PUT \
 -H "$headers" \
 -H "Content-Type: application/json" \
 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
    echo $nresult
fi  

用户文件多的话,例如头像,存储到CDN的时候也要考虑目录平均散列
比较常用是按日期,例如 /2020/02/
但是缺点也非常明显,分布不均
或者直接按userId取模,例如 userId % 1000 分1000个目录来存放,只要userId是连续的,文件就必然是平均分布到这1000个目录
可是,数量很大的时候,一级目录下每个目录的文件数量或者一级目录就会非常多。
那么可以按二级目录来存放

function buildPath($id, $l1num, $l2num)
{
    //(id %(二级目录数量*二级目录数量) / 二级目录数量 => 取整 一级目录
    //(id %(二级目录数量*二级目录数量)% 二级目录数量 => 二级目录
    $tmp = $id % ($l1num * $l2num);
    $l1 = floor($tmp / $l2num);
    $l2 = $tmp % $l2num;
    return ['l1' => $l1, 'l2' => $l2];
}

为了方便演示我把一级目录和二级目录数量设置得比较小的值
就算是

$l1num = 10;
$l2num = 100;
$fileNum = 1000000;

每个目录就1000个文件,这样足够了:)
测试

$l1num = 2; //一级目录数量
$l2num = 5; //二级目录数量
$fileNum = 1000000; //文件数量
$dir = [];
for($i = 0; $i < $l1num; $i++) {
    for ($j = 0; $j < $l2num; $j++) {
        $dir[$i][$j] = 0;
    }
}
for ($i = 1; $i <= $fileNum; $i++) {
    $rs = $this->buildPath($i, $l1num, $l2num);
    $dir[$rs['l1']][$rs['l2']]++;
}
print_r($dir);
Array
(
    [0] => Array
        (
            [0] => 100000
            [1] => 100000
            [2] => 100000
            [3] => 100000
            [4] => 100000
        )

    [1] => Array
        (
            [0] => 100000
            [1] => 100000
            [2] => 100000
            [3] => 100000
            [4] => 100000
        )

)

如果没有唯一id的话也可以使用文件md5后的hash截取部份字串来作来目录来存放,不过缺点就是目录数量就非常多,而且hash费cpu

最近用UNI-APP做项目
因为无论在小程序还是原生APP中,富文本对HTML的标签和样式支持是有限的,而且手机上也不需要像PC WEB端呈现的东西那么丰富,所以就有想法找一个简洁一点的编辑器。

Squire
http://neilj.github.io/Squire/
这本身并没有UI,虽然例子中看到最上面有功能按钮。一切都需要手动添加,当然也可以用例子中的squire ui 去改。
虽然灵活,不过费时
Squire.png

simditor
国产的,但没找到中文文档,呵呵
https://simditor.tower.im/
simditor.png

Trumbowyg
https://alex-d.github.io/Trumbowyg/
Trumbowyg.png

JQUERY NOTEBOOK
http://raphaelcruzeiro.github.io/jquery-notebook/
JQUERY NOTEBOOK.png

Quill
https://quilljs.com/
Quill.png

HandyEditor
http://he.catfish-cms.com/
HandyEditor.png

summernote
https://summernote.org/
summernote.png

Medium Editor
http://yabwe.github.io/medium-editor/
MediumEditor.png

Draft.js
Draft.js
Draft.js.png

Froala Editor
收费的
https://www.froala.com/
Forala Editor.png

基于 Laravel + Dingo api + JWT + laravel-admin 的基础项目
基于 rest api 完成了注册登录等接口,修改后直接使用

代码下载

启动新项目直接使用节省时间
前后台和接口独立域名

版本:

  • Laravel 5.7.13
  • Dingo api 2.0.0-alpha2
  • JWT rc.3
  • laravel-admin 1.6.7

以下所有例子都是使用 lvbegin.com 域名

接口地址: http://api.lvbegin.com
管理端:http://admin.lvbegin.com
门户:http://www.lvbegin.com

开发环境部署
$ composer install
$ cp .env.example .env

根据实际情况修改设置,特别是数据库和REDIS,还有下面两个

ADMIN_DOMAIN=[admin.lvbegin.com](http://admin.lvbegin.com)
API_DOMAIN=[api.lvbegin.com](http://api.lvbegin.com)

继续执行下面命令

$ php artisan key:generate
$ php artisan admin:install
$ php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
$ php artisan jwt:secret
$ php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
$ php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

以上执行完毕,并且修改了虚拟主机配置后可以通过浏览器打开

http://admin.lvbegin.com 测试管理端,账号和密码: admin

http://api.lvbegin.com 接口需要通过 postman 测试

接口列表:
php artisan api:routes

用户验证接口

测试的时候记得先调用注册接口注册一个用户先

虚拟主机参考
server {
    listen 80;
    server_name api.lvbegin.com admin.lvbegin.com www.lvbegin.com;
    index index.php index.html index.htm;
    root /data/www/laravel-beginning/public; # default Laravel's entry point for all requests
    set_real_ip_from 10.104.17.235;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;
    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000; # address of a fastCGI server
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
    }
}
截图

管理端

管理端

POSTMAN 调试

参考