ngrok安装及使用

、安装环境

安装gcc和git(用于下载ngrok源码)
yum install gcc -y
yum install git -y

3、安装go语言环境

yum install -y mercurial git bzr subversion golang golang-pkg-windows-amd64 golang-pkg-windows-386

4、检查环境安装

git --version //( >= 1.7 )
go version

5、在服务器上搭建Ngrok服务

5.1.下载ngrok源码
git clone https://github.com/inconshreveable/ngrok.git
5.2.生成证书
cd ngrok
abc.com这里修改为自己的域名
export NGROK_DOMAIN="abc.com"

openssl genrsa -out rootCA.key 2048

openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem

openssl genrsa -out device.key 2048

openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr

openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
5.3.将新生成的证书替换,执行下面命令后 “y” 回车 一行一行执行代码!
cp rootCA.pem assets/client/tls/ngrokroot.crt

cp device.crt assets/server/tls/snakeoil.crt

cp device.key assets/server/tls/snakeoil.key

6、编译生成ngrokd(服务端)

GOOS=linux GOARCH=amd64 make release-server
​ 生成在~/ngrok/bin/目录中

7、编译生成ngrok(客户端)

GOOS=windows GOARCH=amd64 make release-client
​ 生成在~/ngrok/bin/windows_amd64/目录中

8、用SSH Secure Shell Client工具

将~/ngrok/bin/windows_amd64/里的文件下载到本地Windows下,如D:\ngrok

9、在D:\ngrok中新建文件,改名为 ngrok.cfg

文件中输入:
server_addr: "abc.com:8083" // 8083 监控端口

trust_host_root_certs: false

tunnels:

  http:

subdomain: "www"

proto:

http: "80"    // http 端口 httpAddr=":80"

  https:

subdomain: "www"

proto:

https: "443"  // https 端口 httpsAddr=":443"

  ssh:

remote_port: 2222

proto:

tcp: "22"             

  mstsc:

remote_port: 52222  // 远程开启52222或其他,只要不冲突 

proto:

tcp: "192.168.1.7:3389" // 本地windows的ip以及远程访问端口3389(默认)
以上 8083 80 443 与 远程开启的端口一致,

注意:一定要根据自己的实际情况在服务器后台安全组规则中开启或删除(我因为相对应的服务器安全组没开,卡了好久,希望可以帮助到大家)。

10、开启远程服务

在ngrok目录中 如果不在
cd ngrok

sudo ./bin/ngrokd -domain="abc.com"  -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":8083" &
这里的端口号与config文件对应,视情况而定
[16:05:23 CST 2018/01/09][INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry][tun] No affinity cache specified

[16:05:23 CST 2018/01/09][INFO] (ngrok/log.Info:112) Listening for public http connections on [::]:80

[16:05:23 CST 2018/01/09][INFO] (ngrok/log.Info:112) Listening for public https connections on [::]:443

[16:05:23 CST 2018/01/09][INFO] (ngrok/log.Info:112) Listening for control and proxy connections on [::]:8083

[16:05:23 CST 2018/01/09][INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting every 30 seconds
显示此为成功开启

11、开启客户机服务

在Windows中D:\ngrok新建文件 改名 start.bat 输入: ngrok -config=ngrok.cfg start http https ssh mstsc 直接双击运行
image.png
表示成功, 不成功的话看看自己的开启端口是否与config文件中对应 或查看服务器的远程端口是否在安全组中打开

!!!这很重要!!!

关于ngrok在远程开机自启问题 服务器后台开机启动运行ngrok服务端: 1.以下内容新建一个 start.sh 文件 放到 ~/ngrok/start.sh
~/ngrok/bin/ngrokd -domain="abc.com"  -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":8083" &
给权限:
chmod 755 ~/ngrok/start.sh
2.新建ngrok启动脚本文件
sudo vi /etc/init.d/ngrok
文件内容:
!/bin/sh

BEGIN INIT INFO

Provides:          ngrok

Required-Start:

Required-Stop:

Default-Start:    2 3 4 5

Default-Stop:      0 1 6

Short-Description: Start or stop the ngrok Proxy.

END INIT INFO

ngrok_path=~/ngrok/

case "$1" in

    start)

            echo "start ngrok service.."

            sh ${ngrok_path}/start.sh

            ;;

  *)

    exit 1

    ;;

esac
提示 : 运行sudo vi /etc/init.d/ngrok之后 !!直接按键盘 I 进入编辑模式,然后复制下面内容 然后 “esc” “:” “wq” “!” “回车” 意思是保存退出! 3.ngrok脚本文件 给权限
cd /etc/init.d

chmod 755 ngrok
4.添加启动服务 ngrok
chkconfig –add ngrok
5.测试服务是否能启动成功
service ngrok start
6.查看自启动的服务 是否有 nrgok !!
chkconfig   

CentOS宝塔面板如何挂载磁盘

fdisk -l mkfs.ext4 /dev/sdb mkdir -p /www mount /dev/sdb /www echo "/dev/sdb       /www         ext4           defaults            0 0" >> /etc/fstab 重新挂载所有分区    mount -a 检查是否挂载成功 df     Centos安装命令:
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install.sh && sh install.sh

linux环境 宝塔 连接sql server 2008

SqlServer数据库端口默认是1433 1.首先需要编译安装FreeTDS 说明:一定要从官网下载最新的版本FreeTDS-# wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz # tar -zxvf freetds-patched.tar.gz # cd freetds-1.00.94 需要注意的就是这里的--with-tdsver=7.3,这个非常重要,你需要根据你的数据库版本选择正确的配置项,由于现在大多是SQLserve2008所以需要选择7.3. # ./configure --prefix=/usr/local/freetds --with-tdsver=7.3 --enable-msdblib # make && make install 配置FreeTDS # cd ../ # echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf # ldconfig 验证FreeTDS版本 这一步非常重要,通过才可以继续,不然后面的步骤都是无意义的。 首先看看版本信息 # /usr/local/freetds/bin/tsql -C 测试数据库是否联通 # /usr/local/freetds/bin/tsql -H 数据库服务器IP  -p 端口号(1433) -U 用户名 -P 密码   3.添加PHP扩展pdo的pdo_dblib cd /root/ 下载php-5.6.30.tar.gz #tar -zxvf  php-5.6.30.tar.gz   #cd /root/php-5.6.30/ext/pdo_odbc #/www/server/php/56/bin/phpize #./configure --with-php-config=/www/server/php/56/bin/php-config --with-pdo-#dblib=/usr/local/freetds/ #make && make install
<?php header("Content-type: text/html; charset=utf-8"); try { $hostname = "数据库IP"; $port = 1433; $dbname = "数据库名"; $username = "blog.csdn.net.unix21"; $pw = "password"; $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw"); } catch (PDOException $e) { echo "Failed to get DB handle: " . $e->getMessage() . "\n"; exit; } $stmt = $dbh->prepare("SELECT top 5 * FROM tablename"); $stmt->execute(); while ($row = $stmt->fetch()) { print_r($row); } unset($dbh); unset($stmt); ?>

CakePHP 使用Redis缓存Paginator的数据

本身的Paginator无法缓存直接修改源代码方便缓存 也可以另存为新的Component 本文上不了头条 管理员说文字描述不够 难道这年头作者都可以去写代码了是吧 简易的可以看github:http://christianyeah.github.io/CakePHP-Paginator-Cache/ /lib/Cake/Controller/Component/PaginatorComponent.php 定位到196行和大约215行
/*
修改一下代码
源代码仅为
$results = $object->find($type, array_merge($parameters, $extra));
*/
if(!isset($options['cache_config'])){
    $results = $object->find($type, array_merge($parameters, $extra));
}
else{
    $cache_key = 'paginator_cache_'.$object->name.'_page_'.$page;
    $results = Cache::remember($cache_key, function() use ($object,$type,$parameters,$extra){
                   return $object->find($type,array_merge($parameters, $extra));
               },$options['cache_config']);
}
 
 
//开始修改 以上代码不变 仅方便定位
/*
修改一下代码
源代码仅为
$results = $object->find($type, array_merge($parameters, $extra));
*/
if(!isset($options['cache_config'])){
    $count = $object->find('count', array_merge($parameters, $extra));
}
else{
    $cache_key = 'paginator_cache_'.$object->name.'_count';
    $count = Cache::remember($cache_key, function() use ($object,$type,$parameters,$extra){
                 return $object->find('count',array_merge($parameters, $extra));
             },$options['cache_config']);
}
使用方法: 首先修改core.php
//probability代表一个概率 查看源码后可以知道是time()%$probability ==0 时调用Cache::gc()
Cache::config('common_paginator_cache_redis', array(
    'engine' => 'Redis',
    'duration' => '+15 minutes',
    'probability' => 70
));
控制器中修改:
//使用方法
//加入以下代码设置cache config即可 其他代码无需更改
$this->paginate = array(
    'limit' => 12,
    'cache_config'=>'common_paginator_cache_redis'//新增 匹配core.php中的配置
);