Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
30536712
Commit
30536712
authored
Nov 12, 2018
by
christ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
elastic
parent
98908cb0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
177 additions
and
30 deletions
+177
-30
ElasticsTool.php
application/models/Elastics/ElasticsTool.php
+15
-1
application.ini
conf/application.ini
+8
-29
nginxLogsIndex.php
scripts/crontab/logs/nginxLogsIndex.php
+154
-0
No files found.
application/models/Elastics/ElasticsTool.php
View file @
30536712
...
@@ -303,7 +303,21 @@ class ElasticsToolModel
...
@@ -303,7 +303,21 @@ class ElasticsToolModel
$res
=
$this
->
client
->
indices
()
->
create
(
$params
);
$res
=
$this
->
client
->
indices
()
->
create
(
$params
);
return
$res
;
return
$res
;
}
}
public
function
createIndexAndMapping
(
$propertiesField
)
{
$params
=
[
'index'
=>
$this
->
dbName
,
//索引名称
'body'
=>
[
'mappings'
=>
[
//映射
$this
->
tbName
=>
[
//默认配置,每个类型缺省的配置使用默认配置
'properties'
=>
$propertiesField
],
],
]
];
$res
=
$this
->
client
->
indices
()
->
create
(
$params
);
return
$res
;
}
// public function createIkField($indexFild)
// public function createIkField($indexFild)
// {
// {
// $params = [
// $params = [
...
...
conf/application.ini
View file @
30536712
...
@@ -15,34 +15,23 @@ application.modules = Index,Api,Admin,Client
...
@@ -15,34 +15,23 @@ application.modules = Index,Api,Admin,Client
[productone : common]
[productone : common]
; 数据库配置
; 数据库配置
resources.database.params.driver
=
"pdo_mysql"
resources.database.params.driver
=
"pdo_mysql"
resources.database.params.hostname
=
"
172.16.142.15
"
resources.database.params.hostname
=
"
rm-bp1j835zol35h2nm0.mysql.rds.aliyuncs.com
"
resources.database.params.port
=
3306
resources.database.params.port
=
3306
resources.database.params.database
=
"qmcs"
resources.database.params.database
=
"qmcs"
resources.database.params.username
=
"
root
"
resources.database.params.username
=
"
chenchuanwen
"
resources.database.params.password
=
"!@#$%12345werty"
resources.database.params.password
=
"!@#$%12345werty"
resources.database.params.charset
=
"UTF8"
resources.database.params.charset
=
"UTF8"
resources.database.params.driver_options.1002
=
"SET NAMES utf8"
resources.database.params.driver_options.1002
=
"SET NAMES utf8"
;
;
; ; 从库配置
; ; 从库配置
resources.database.slave.params.driver
=
"pdo_mysql"
resources.database.slave.params.driver
=
"pdo_mysql"
resources.database.slave.params.hostname
=
"
172.16.142.13
"
resources.database.slave.params.hostname
=
"
rm-bp1j835zol35h2nm0.mysql.rds.aliyuncs.com
"
resources.database.slave.params.port
=
3306
resources.database.slave.params.port
=
3306
resources.database.slave.params.database
=
"qmcs"
resources.database.slave.params.database
=
"qmcs"
resources.database.slave.params.username
=
"
root
"
resources.database.slave.params.username
=
"
chenchuanwen
"
resources.database.slave.params.password
=
"!@#$%12345werty"
resources.database.slave.params.password
=
"!@#$%12345werty"
resources.database.slave.params.charset
=
"UTF8"
resources.database.slave.params.charset
=
"UTF8"
resources.database.slave.params.driver_options.1002
=
"SET NAMES utf8"
resources.database.slave.params.driver_options.1002
=
"SET NAMES utf8"
; mongodb
resources.database.mongo.params.driver
=
"scram"
resources.database.mongo.params.hostname
=
"172.16.142.15"
resources.database.mongo.params.port
=
27017
resources.database.mongo.params.database
=
"qmcs"
resources.database.mongo.params.username
=
"qmcs"
resources.database.mongo.params.password
=
"123456asdfgh"
resources.database.mongo.params.charset
=
"UTF8"
resources.database.mongo.params.driver_options.1002
=
"SET NAMES utf8"
;
;
password.key
=
'~!@#$`1234qwertasdfgzxcvb'
;
password.key
=
'~!@#$`1234qwertasdfgzxcvb'
;
redis.database.params.host = "172.16.142.15"
redis.database.params.host = "172.16.142.15"
...
@@ -73,34 +62,24 @@ password.key='~!@#$`1234qwertasdfgzxcvb';
...
@@ -73,34 +62,24 @@ password.key='~!@#$`1234qwertasdfgzxcvb';
[product : common]
[product : common]
; 数据库配置
; 数据库配置
resources.database.params.driver
=
"pdo_mysql"
resources.database.params.driver
=
"pdo_mysql"
resources.database.params.hostname
=
"
127.0.0.1
"
resources.database.params.hostname
=
"
rm-bp1j835zol35h2nm0.mysql.rds.aliyuncs.com
"
resources.database.params.port
=
3306
resources.database.params.port
=
3306
resources.database.params.database
=
"qmcs"
resources.database.params.database
=
"qmcs"
resources.database.params.username
=
"
root
"
resources.database.params.username
=
"
chenchuanwen
"
resources.database.params.password
=
"!@#$%12345werty"
resources.database.params.password
=
"!@#$%12345werty"
resources.database.params.charset
=
"UTF8"
resources.database.params.charset
=
"UTF8"
resources.database.params.driver_options.1002
=
"SET NAMES utf8"
resources.database.params.driver_options.1002
=
"SET NAMES utf8"
; 从库配置
; 从库配置
resources.database.slave.params.driver
=
"pdo_mysql"
resources.database.slave.params.driver
=
"pdo_mysql"
resources.database.slave.params.hostname
=
"
172.16.142.13
"
resources.database.slave.params.hostname
=
"
rm-bp1j835zol35h2nm0.mysql.rds.aliyuncs.com
"
resources.database.slave.params.port
=
3306
resources.database.slave.params.port
=
3306
resources.database.slave.params.database
=
"qmcs"
resources.database.slave.params.database
=
"qmcs"
resources.database.slave.params.username
=
"
root
"
resources.database.slave.params.username
=
"
chenchuanwen
"
resources.database.slave.params.password
=
"!@#$%12345werty"
resources.database.slave.params.password
=
"!@#$%12345werty"
resources.database.slave.params.charset
=
"UTF8"
resources.database.slave.params.charset
=
"UTF8"
resources.database.slave.params.driver_options.1002
=
"SET NAMES utf8"
resources.database.slave.params.driver_options.1002
=
"SET NAMES utf8"
; mongodb
resources.database.mongo.params.driver
=
"scram"
resources.database.mongo.params.hostname
=
"127.0.0.1"
resources.database.mongo.params.port
=
27017
resources.database.mongo.params.database
=
"qmcs"
resources.database.mongo.params.username
=
"qmcs"
resources.database.mongo.params.password
=
"123456asdfgh"
resources.database.mongo.params.charset
=
"UTF8"
resources.database.mongo.params.driver_options.1002
=
"SET NAMES utf8"
password.key
=
'~!@#$`1234qwertasdfgzxcvb'
;
password.key
=
'~!@#$`1234qwertasdfgzxcvb'
;
redis.database.params.host = "127.0.0.1"
redis.database.params.host = "127.0.0.1"
redis.database.params.port
=
"6379"
redis.database.params.port
=
"6379"
...
...
scripts/crontab/logs/nginxLogsIndex.php
0 → 100644
View file @
30536712
<?php
/**
* 生成店铺订单索引
* 执行时间:每分钟执行一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define
(
"APPLICATION_PATH"
,
realpath
(
dirname
(
__FILE__
)
.
'/../../../'
));
//指向public的上一级
require
APPLICATION_PATH
.
'/scripts/crontab/baseCli.php'
;
require
APPLICATION_PATH
.
'/scripts/crontab/common.php'
;
error_reporting
(
E_ALL
^
E_NOTICE
);
class
clinNginxLogsIndex
extends
basecli
{
const
CLI_ADMIN_ID
=
255
;
private
$bDoUnLock
=
FALSE
;
// 是否允许释放 LOCK 文件
private
$_debug
=
0
;
private
$lockFileName
;
public
$key
=
''
;
private
$fromState
;
private
function
mkdirs
(
$dir
,
$mode
=
0777
)
{
if
(
is_dir
(
$dir
)
||
@
mkdir
(
$dir
,
$mode
))
{
return
TRUE
;
}
if
(
!
$this
->
mkdirs
(
dirname
(
$dir
),
$mode
))
{
return
FALSE
;
}
return
@
mkdir
(
$dir
,
$mode
);
}
/**
* 析构
*/
public
function
__destruct
()
{
parent
::
__destruct
();
if
(
$this
->
bDoUnLock
)
{
@
unlink
(
$this
->
lockFileName
);
}
}
public
function
getIndex
(
$dayOption
){
$dateStr
=
date
(
'Y-m-d'
,
strtotime
(
$dayOption
));
$indexStr
=
\Our\Common
::
format
(
"nignx-log-"
.
$dateStr
);
return
$indexStr
;
}
public
function
removeNginxLogIndex
(){
$index
=
$this
->
getIndex
(
"-30 day"
);
$type
=
"nginx-log"
;
$elasticsTool
=
\Elastics\ElasticsToolModel
::
getInstance
(
$type
,
$index
);
$i
=
30
;
while
(
$elasticsTool
->
indexExists
(
$index
)){
$elasticsTool
->
deleteIndex
(
$index
);
$i
--
;
$index
=
$this
->
getIndex
(
"-
{
$i
}
day"
);
}
}
//创建索引
public
function
createNginxLogIndex
()
{
$index
=
$this
->
getIndex
(
"+1 day"
);
$type
=
"nginx-log"
;
$elasticsTool
=
\Elastics\ElasticsToolModel
::
getInstance
(
$type
,
$index
);
$propertiesfield
=
[
//映射
"@timestamp"
=>
[
"type"
=>
"date"
,
"format"
=>
"strict_date_optional_time||epoch_millis"
],
"@version"
=>
[
"type"
=>
"string"
],
"client"
=>
[
"type"
=>
"string"
],
"domain"
=>
[
"type"
=>
"string"
],
"host"
=>
[
"type"
=>
"string"
],
"path"
=>
[
"type"
=>
"string"
],
"referer"
=>
[
"type"
=>
"string"
],
"responsetime"
=>
[
"type"
=>
"string"
],
"size"
=>
[
"type"
=>
"string"
],
"status"
=>
[
"type"
=>
"string"
],
"type"
=>
[
"type"
=>
"string"
],
"ua"
=>
[
"type"
=>
"string"
],
"url"
=>
[
"type"
=>
"string"
,
"index"
=>
"not_analyzed"
],
];
$elasticsTool
->
createIndexAndMapping
(
$propertiesfield
);
}
protected
function
_runCli
()
{
$this
->
_debug
=
isset
(
$this
->
aArgv
[
1
])
?
intval
(
$this
->
aArgv
[
1
])
:
0
;
if
(
$this
->
_debug
)
{
echo
"*** Debug mode ***
\n
"
;
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir
=
$this
->
_getBaseFileName
(
'logs'
);
if
(
!
$this
->
mkdirs
(
$lockDir
))
{
echo
'****create dir fail ****'
;
exit
;
}
$this
->
lockFileName
=
$lockDir
.
DS
.
'nginxLogsIndex.locks'
;
if
(
file_exists
(
$this
->
lockFileName
))
{
$stat
=
stat
(
$this
->
lockFileName
);
if
((
TIMESTAMP
-
$stat
[
'mtime'
])
>
1800
)
{
echo
"文件被锁超过1800秒,被强制删除"
;
@
unlink
(
$this
->
lockFileName
);
}
else
{
$this
->
halt
(
'['
.
date
(
'Y-m-d H:i:s'
)
.
'] The CLI is running'
.
"
\n
"
);
}
}
$this
->
bDoUnLock
=
true
;
file_put_contents
(
$this
->
lockFileName
,
"running"
);
// CLI 独占锁
$shopkeeperService
=
\Business\Store\ShopkeeperServiceModel
::
getInstance
();
$shopkeeperService
->
baseDir
=
\Our\Common
::
getConfig
(
'out.config'
);
try
{
$this
->
createNginxLogIndex
();
}
catch
(
\Exception
$ex
)
{
throw
new
\Exception
(
$ex
->
getMessage
(),
$ex
->
getCode
());
}
echo
'nginx,log 生成成功'
.
date
(
'Y-m-d H:i:s'
,
TIMESTAMP
)
.
"
\r\n
"
;
}
}
$oCli
=
new
clinNginxLogsIndex
(
TRUE
);
EXIT
;
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment