range

If there were you, the world would be just right

谷歌登陆demo

header('Content-Type:text/html; charset=utf-8');

class Google
{
    protected $setting = [
        'app_id' => 'xx',          //客户端ID
        'app_secret' => 'xx',     //客户端密钥
        'redirect_uri' => 'xx',  //回调地址
    ];

    public function __construct($pf_game_id)
    {
        $this->client_id = $this->setting['app_id'];
        $this->client_secret = $this->setting['app_secret'];
        $this->redirect_uri = $this->setting['redirect_uri']."?pf_game_id=".$pf_game_id;
    }

    public function index()
    {
        //第一步:请求CODE
        if (empty($_GET['code'])) {
            $this->getCode($this->client_id, $this->redirect_uri);
        } else {

            //用户允许授权后,将会重定向到redirect_uri的网址上,并且带上code参数
            $code = $_GET['code'];
            $postData = array(
                'code' => $code,
                'client_id' => $this->client_id,
                'client_secret' => $this->client_secret,
                'redirect_uri' => $this->redirect_uri,
                'grant_type' => 'authorization_code'
            );

            //第二步:通过code获取access_token
            $purl = 'https://accounts.google.com/o/oauth2/token';
            $token = $this->CurlSend($postData,$purl);
            if (empty($token)) {
                exit("获取token失败");
            }
            echo "<pre>";print_r($token);die;
        }
    }

    /**
     * 抓取CODE
     * @param $client_id
     * @param $redirect_uris
     */
    protected function getCode($client_id, $redirect_uris)
    {
        $redirect_uris = urlencode($redirect_uris);
        $scope = urlencode('https://www.googleapis.com/auth/androidpublisher');
        $url = "https://accounts.google.com/o/oauth2/auth?response_type=code&access_type=offline&client_id={$client_id}&redirect_uri={$redirect_uris}&state&scope={$scope}&approval_prompt=auto";
        header('Location:' . $url);
    }


    protected function CurlSend($postData, $purl)
    {
        $fields = (is_array($postData)) ? http_build_query($postData) : $postData;
        $curlHeaders = [
            'content-type: application/x-www-form-urlencoded;CHARSET=utf-8',
            'Content-Length: ' . strlen($fields),
        ];

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $purl);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($curl);
        $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);

        if ($response && $responseCode == 200) {
            $json_data = json_decode($response, true);
            return $json_data;
        } else {
            return false;
        }
    }

    public function getATokenToRefToken($refresh_token){
        $url = 'https://accounts.google.com/o/oauth2/token';
        $postData = array(
            'client_id' => $this->client_id,
            'client_secret' => $this->client_secret,
            'grant_type' => 'refresh_token',
            'refresh_token' => $refresh_token
        );
        $token_data = $this->CurlSend($postData,$url);
        echo $token_data["access_token"];
    }
}

if(empty($_GET["pf_game_id"])){
    exit("pf_game_id is empty");
}
$google = new Google($_GET["pf_game_id"]);
$google->index();

安装python3:

安装相关包

yum install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc

下载python3的源码包

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz

解压python3源码包

xz -d Python-3.6.4.tar.xz
tar -xf Python-3.6.4.tar

编译安装

cd Python-3.6.4
./configure prefix=/usr/local/python3
make && make install

添加软链接

ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

安装Web.py(接收器)

pip3 install --upgrade pip

pip3 install web.py

设置gogs-web钩子
143918.png

编写脚本代码接收信号并更新git

#!/usr/bin/python3
#coding=utf-8
import web
import json
import os

urls = (
     '/', 'web_exec'
)
app = web.application(urls, globals())
# 获取当前日志路径 
log_path = os.getcwd()

class web_exec:
    def POST(self):
        # inp为str
        inp = web.input().payload
        # data为dict
        data = json.loads(inp)

        # 当前推送获取的分支
        ref = data['ref']

        # 只更新master 分支内容
        if( ref!='refs/heads/master' ):
            return

        msg = '------------------------------------ start ------------------------------------'
        self.write_log_to_file(msg)

        sys_msg = "当前推送获取的分支:"+ref
        self.write_log_to_file(sys_msg)

        # 当前更新版本
        after_version = data['after']
        sys_msg = "当前更新版本:"+after_version
        self.write_log_to_file(sys_msg)

        # 当前版本推送人
        username = data['pusher']['username']
        sys_msg = "当前版本推送人:"+username
        self.write_log_to_file(sys_msg)        

        # 当前项目
        name = data['repository']['name']
        sys_msg = "当前执行更新项目:"+name
        self.write_log_to_file(sys_msg)

        # 进入对应的目录
        path = '/data/web/' + name + '/'
        sys_msg = "执行进入目录:"+path
        self.write_log_to_file(sys_msg)

        os.chdir(path)

        # 取回更新后
        sys = '/usr/bin/git fetch --all'
        sys_msg = "执行git fetch:"+sys
        self.write_log_to_file(sys_msg)

        os.system(sys)

        # 执行更新版本
        sys = '/usr/bin/git reset --hard ' + after_version;
        sys_msg = "最终执行更新脚本命令:"+sys
        self.write_log_to_file(sys_msg)

        msg = '------------------------------------ end ------------------------------------'
        self.write_log_to_file(msg)

        return os.system(sys)

    # 记录日志信息
    def write_log_to_file(self,msg):
        print('开始写入数据 ====> ' + str(msg))
        with open(log_path + 'git_update.log', 'a', encoding='UTF-8') as f:
            f.write(json.dumps(msg, ensure_ascii=False) + '\n')
            f.close()

if __name__ == "__main__":
    app.run()

运行脚本

python3 web_gz.py

推送git内容
push38.png

查看脚本打印
11.png

进入项目目录,查看是否有拉取到内容
73016.png

end!!


Yaconf - 鸟叔开发的一个高性能的配置管理扩展

在PHP启动的时候, 处理所有的要处理的配置, 然后这些配置就会常驻内存, 随着PHP的生命周期存亡. 避免了每次请求的时候解析配置文件
https://www.laruence.com/2015/06/12/3051.html

扩展下载地址

https://github.com/laruence/yaconf

解压

unzip yaconf-master.zip

进入目录

cd yaconf-master

生成相应的configure文件

/usr/local/php/bin/phpize

运行配置

./configure --with-php-config=/usr/local/php/bin/php-config

进行编译安装

make && make install

安装完成进行php.ini文件配置

vim /usr/local/php/etc/php.ini

extension=yaconf.so
yaconf.directory= /data/ini # 需要导入的配置文件地址, .ini 作为文件后缀名
yaconf.check_delay=100 #心跳检查时间,若为0则不检查,但如果有修改,需重启PHP

重启php进程管理

service php-fpm restart

查看扩展是否安装成功

php -m | grep yaconf

yaconf.png
使用:

在对应的目录 /data/ini 下创建配置文件,如:

vim redis.ini

host=127.0.0.1
port=3673
time=5
a.b=2
a.c=3

编写php脚本读取内容

vim test.php

<?php
    $res = \Yaconf::get('redis');
    print_r($res);

执行脚本

php test.php

test.png

end!


1、使用命令下载

curl -sS https://getcomposer.org/installer | php

2、下载之后设置环境变量

mv composer.phar /usr/local/bin/composer

3、修改权限

chmod -R 777 /usr/local/bin/composer

4、修改镜像

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/


elasticsearch是什么东西,请自行百度。此处只是记录一下安装所需要操作日志。
0: 安装java环境
0.1.先查看本地是否自带java环境:

yum list installed |grep java

0.2.卸载自带的java(输入su,输入root超级管理员的密码,切换到root用户模式)

yum -y remove java-1.8.0-openjdk* 

yum -y remove tzdata-java*

0.3.查看yum仓库中的java安装包

yum -y list java*

0.4.安装java:

yum -y install java-1.8.0-openjdk*

0.5.查找Java安装路径

which java

ls -lrt /usr/bin/java(也就是上一步查询出来的路径),然后回车

输入ls -lrt /etc/alternatives/java(也就是上一步查询出来的路径),然后回车

从路径中可以看到在jvm目录下,输入cd /usr/lib/jvm,跳转到jvm的目录

输入ls 列出当前目录下的文件和文件夹

0.6.配置Java环境变量

输入vi /etc/profile去编辑环境变量

添加如下:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0
export JRE_HOME=$JAVA_HOME/jre  
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

保存退出

输入source /etc/profile,使配置立即生效

0.7.检查Java安装和配置情况 输入java -version,然后回车

1、创建用户 es(必须)

#使用root用户的操作 添加一个用户,叫做es
useradd es 
# 使用root用户创建目录
mkdir -p /export/servers/es
mkdir -p /export/data/es
mkdir -p /export/logs/es
# 将目录的权限分配给es用户
chown -R es /export/servers/es
chown -R es /export/data/es
chown -R es /export/logs/es
# 设置下es用户的密码,这里建议使用es作为密码,也就是账户名和密码一样。
passwd es
<input es>
# 切换到es用户
su es

2、下载安装包

切换到es用户下,下载安装包
su es
# 进入Home目录
cd 
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.tar.gz
tar -zxvf elasticsearch-6.6.0.tar.gz -C /export/servers/es/

3 修改配置文件

cd /export/servers/es/elasticsearch-6.6.0/config
vi elasticsearch.yml
# 追加内容:
xpack.ml.enabled: false
network.host: 0.0.0.0
http.port: 9200
#memory
bootstrap.memory_lock: false 
bootstrap.system_call_filter: false

4、启动

nohup /export/servers/es/elasticsearch-6.6.0/bin/elasticsearch >/dev/null 2>&1 &

5、 查看错误信息-(无报错则忽略)

tail -100f /export/logs/es/myes.log 
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

修改/etc/security/limits.conf在最后追加

* soft nofile 65536
* hard nofile 65536
修改/etc/sysctl.conf在最后追加

vm.max_map_count=655360

保存后,执行:
sysctl -p
重新切换es用户,重启elasticsearch

6、访问es

http://IP:9200

9200.png

使用

1.1 创建索引

curl -XPUT http://ip:9200/blog01/?pretty

1.2 插入文档

curl -XPUT http://ip:9200/blog01/article/1?pretty -d  '{"id": "1", "title": "What is lucene"}' -H "Content-Type: application/json"

1.3 查询文档

curl -XGET "http://ip:9200/blog01/article/1?pretty" -H "Content-Type: application/json"

1.4 更新文档

curl -XPUT http://ip:9200/blog01/article/1?pretty -d  '{"id": "1", "title": " What is elasticsearch"}' -H "Content-Type: application/json"

1.5 搜索文档

curl -XGET "http://ip:9200/blog01/article/1?pretty" -H "Content-Type: application/json"
curl -XGET "http://ip:9200/blog01/article/_search?q=title:'elasticsearch'&pretty" -H "Content-Type: application/json"

1.6 删除文档

curl -XDELETE "http://ip:9200/blog01/article/1?pretty"

1.7 删除索引

curl -XDELETE "http://ip:9200/blog01?pretty"