avg for centos centos官网
大家好,今天给各位分享avg for centos的一些知识,其中也会对centos官网进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!
CentOS6.x上部署Docker容器环境的全流程攻略
Docker.io是轻量级的容器引擎+映像仓库,在LXC(linux轻量级容器)的基础上构建,可以运行任何应用程序。
docker.io的核心层由以下几个部分组成:
1、可执行程序,/usr/bin/docker
2、docker.io网站上有一系列创建好的操作系统和应用程序映像
3、AUFS(另一个统一文件系统)来实现文件系统的快照,文件变化,控制只读或读写的需求。
4、LXC(Linux轻量级容器)
5、Cgroups(各种资源和命名空间的管理)
在本文写作的时候,最新版本是0.5.3,但目前开发很活跃,一些功能和特性可能在新版本中会发生变化。
需要注意的是CentOS 6.5与7.0的安装是有一点点不同的,CentOS-6上docker的安装包叫docker-io,并且来源于Fedora epel库,这个仓库维护了大量的没有包含在发行版中的软件,所以先要安装EPEL,而CentOS-7的docker直接包含在官方镜像源的Extras仓库(CentOS-Base.repo下的[extras]节enable=1启用)。前提是都需要联网,具体安装过程如下。
1.禁用selinux
[/code]
# getenforce
enforcing
# setenforce 0
permissive
# vi/etc/selinux/config
SELINUX=disabled
...
[/code]
2.安装 Fedora EPEL
epel-release-6-8.noarch.rpm包在发行版的介质里面已经自带了,可以从rpm安装。
复制代码
代码如下:
# yum install epel-release-6-8.noarch.rpm
//或
yum-y install
如果出现GPG key retrieval failed: [Errno 14] Could not open/read 问题,请在线安装epel,下载RPM-GPG-KEY-EPEL-6文件。
这一步执行之后,会在/etc/yum.repos.d/下生成epel.repo、epel-testing.repo两个文件,用于从Fedora官网下载rpm包。
3.检查内核版本
复制代码
代码如下:
# uname-r
2.6.32-431.el6.x86_64
# cat/etc/redhat-release
CentOS release 6.5(Final)
看到这个最低的内核版本,事实运行起来是没太大问题的,你也可以升级到3.10.x版本。
另外你也可以运行脚本check-config.sh,来检查内核模块符不符合(下面有些missing的,我的docker还是可以正常启动):
复制代码
代码如下:
[root@sean~]#./check-config
warning:/proc/config.gz does not exist, searching other paths for kernel config...
info: reading kernel config from/boot/config-2.6.32-431.el6.x86_64...
Generally Necessary:
- cgroup hierarchy: properly mounted [/cgroup]
- CONFIG_NAMESPACES: enabled
- CONFIG_NET_NS: enabled
- CONFIG_PID_NS: enabled
- CONFIG_IPC_NS: enabled
- CONFIG_UTS_NS: enabled
- CONFIG_DEVPTS_MULTIPLE_INSTANCES: enabled
- CONFIG_CGROUPS: enabled
- CONFIG_CGROUP_CPUACCT: enabled
- CONFIG_CGROUP_DEVICE: enabled
- CONFIG_CGROUP_FREEZER: enabled
- CONFIG_CGROUP_SCHED: enabled
- CONFIG_MACVLAN: enabled
- CONFIG_VETH: enabled
- CONFIG_BRIDGE: enabled
- CONFIG_NF_NAT_IPV4: missing
- CONFIG_IP_NF_TARGET_MASQUERADE: enabled
- CONFIG_NETFILTER_XT_MATCH_ADDRTYPE: missing
- CONFIG_NETFILTER_XT_MATCH_CONNTRACK: enabled
- CONFIG_NF_NAT: enabled
- CONFIG_NF_NAT_NEEDED: enabled
Optional Features:
- CONFIG_MEMCG_SWAP: missing
- CONFIG_RESOURCE_COUNTERS: enabled
- CONFIG_CGROUP_PERF: enabled
- Storage Drivers:
-"aufs":
- CONFIG_AUFS_FS: missing
- CONFIG_EXT4_FS_POSIX_ACL: enabled
- CONFIG_EXT4_FS_SECURITY: enabled
-"btrfs":
- CONFIG_BTRFS_FS: enabled
-"devicemapper":
- CONFIG_BLK_DEV_DM: enabled
- CONFIG_DM_THIN_PROVISIONING: enabled
- CONFIG_EXT4_FS: enabled
- CONFIG_EXT4_FS_POSIX_ACL: enabled
- CONFIG_EXT4_FS_SECURITY: enabled
假如你是自己编译内核,请特别留意几个绝对不能缺少的:DM_THIN_PROVISIONING、IP_NF_TARGET_MASQUERADE、NF_NAT。(AUFS_FS没有对应选项,还不清楚怎么回事,但不是必须)
4.安装 docker-io
复制代码
代码如下:
# yum install docker-io
Dependencies Resolved
===========================================================================================
Package
Arch Version Repository Size
===========================================================================================
Installing:
docker-io
x86_64 1.1.2-1.el6 epel 4.5 M
Installing for dependencies:
lua-alt-getopt noarch 0.7.0-1.el6 epel 6.9 k
lua-filesystem x86_64 1.4.2-1.el6 epel 24 k
lua-lxc
x86_64 1.0.6-1.el6 epel 15 k
lxc
x86_64 1.0.6-1.el6 epel 120 k
lxc-libs
x86_64 1.0.6-1.el6 epel 248 k
Transaction Summary
===========================================================================================
Install 6 Package(s)
许多文档介绍到这里,下一步为挂载/cgroup文件系统,我的docker版本为1.1.2,没有修改/etc/fstab的步骤。
5.启动试运行
复制代码
代码如下:
# service docker start
//或
# docker-d
6.以守护模式运行docker.io(在一个新的终端里)
复制代码
代码如下:
[root@localhost~]# docker-d
2013/08/21 07:47:07 WARNING: Your kernel does not support cgroup swap limit.
2013/08/21 07:47:07 Listening for HTTP on/var/run/docker.sock(unix)
7.在centos6.4容器里输出hello world
复制代码
代码如下:
[root@localhost~]# docker run centos:6.4 echo"hello world"
2013/08/21 07:48:41 POST/v1.4/containers/create
2013/08/21 07:48:41 POST/v1.4/containers/c6bc9e80097e/start
2013/08/21 07:48:41 POST/v1.4/containers/c6bc9e80097e/attach?logs=1stderr=1stdout=1stream=1
hello world
8.从容器里测试ping
复制代码
代码如下:
[root@localhost~]# docker-dns'8.8.8.8' run centos:6.4 ping-c 3 yahoo.com
2013/08/21 08:02:15 POST/v1.4/containers/create
2013/08/21 08:02:15 POST/v1.4/containers/c40a1244f9bc/start
2013/08/21 08:02:15 POST/v1.4/containers/c40a1244f9bc/attach?logs=1stderr=1stdout=1stream=1
PING yahoo.com(98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com(98.138.253.109): icmp_seq=1 ttl=48 time=323 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com(98.138.253.109): icmp_seq=2 ttl=48 time=329 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com(98.138.253.109): icmp_seq=3 ttl=49 time=302 ms
--- yahoo.com ping statistics---
3 packets transmitted, 3 received, 0% packet loss, time 2304ms
rtt min/avg/max/mdev= 302.032/318.318/329.656/11.807 ms
9.异常
在我的一次安装过程中,很不幸遇到下面的问题:
docker-d启动,或tail-f/var/log/docker查看日志
复制代码
代码如下:
[f32e7d9f]+job initserver()
[f32e7d9f.initserver()] Creating server
[f32e7d9f]+job serveapi(unix:///var/run/docker.sock)
2014/10/22 13:02:45 Listening for HTTP on unix(/var/run/docker.sock)
Error running DeviceCreate(createPool) dm_task_run failed
[f32e7d9f]-job initserver()= ERR(1)
2014/10/22 13:02:45 Error running DeviceCreate(createPool) dm_task_run failed
\nWed Oct 22 14:35:54 CST 2014\n
再或者是service docker restart
复制代码
代码如下:
Stopping docker:
[ OK ]
Starting cgconfig service: Error: cannot mount cpuset to/cgroup/cpuset: Device or resource busy
/sbin/cgconfigparser; error loading/etc/cgconfig.conf: Cgroup mounting failed
Failed to parse/etc/cgconfig.conf
[FAILED]
Starting docker:
[ OK ]
全选复制放进笔记Unable to enable network bridge NAT: iptables failed: iptables-I POSTROUTING-t nat-s 172.17.42.1/16!-d 172.17.42.1/16-j MASQUERADE: iptables v1.4.7: can't initialize iptables table `nat': Table does not exist(do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
如何使用Monit部署服务器监控系统
Monit是什么?
Monit是
一个跨平台的用来监控Unix/linux系统(比如Linux、BSD、OSX、Solaris)的工具。Monit特别易于安装,而且非常轻量级(只
有500KB大小),并且不依赖任何第三方程序、插件或者库。然而,Monit可以胜任全面监控、进程状态监控、文件系统变动监控、邮件通知和对核心服务
的自定义动作等场景。易于安装、轻量级的实现以及强大的功能,让Monit成为一个理想的后备监控工具。
我
已经在一些机器使用Monit几年了,而且我对它的可靠性非常满意。甚至作为全面的监控系统,对任何Linux系统管理员来说Monit也是非常有用和强
大的。在这篇教程中,我会展示如何在一个本地服务器部署Monit(作为后备监控系统)来监控常见的服务。在部署过程中,我只会展示我们用到的部分。
在Linux安装Monit
Monit已经被包含在多数Linux发行版的软件仓库中了。
Debian、Ubuntu或者Linux Mint:
$ sudo aptitude install monit
Fedora或者CentOS/RHEL:
在CentOS/RHEL中,你必须首先启用EPEL或者Repoforge软件仓库.
# yum install monit
Monit
自带一个文档完善的配置文件,其中包含了很多例子。主配置文件在/etc/monit.conf(Fedora/CentOS/RHEL
中),或者/etc/monit/monitrc(Debian/Ubuntu/Mint
中)。Monit配置文件有两部分:“Global”(全局)和“Services”(服务)。
Global Configuration: Web Status Page(全局配置:Web状态页面)
Monit可以使用邮件服务来发送通知,也可以使用HTTP/HTTPS页面来展示。我们先使用如下配置的web状态页面吧:
Monit监听1966端口。
对web状态页面的访问是通过SSL加密的。
使用monituser/romania作为用户名/口令登录。
只允许通过localhost、myhost.mydomain.ro和在局域网内部(192.168.0.0/16)访问。
Monit使用pem格式的SSL证书。
之后的步骤,我会使用一个基于Red Hat的系统。在基于Debian的系统中的步骤也是类似的。
首先,在/var/cert生成一个自签名的证书(monit.pem):
# mkdir/var/certs# cd/etc/pki/tls/certs#./make-dummy-cert monit.pem# cp monit.pem/var/certs# chmod 0400/var/certs/monit.pem
现在将下列代码片段放到Monit的主配置文件中。你可以创建一个空配置文件,或者基于自带的配置文件修改。
set httpd port 1966 and SSL ENABLE PEMFILE/var/certs/monit.pem allow monituser:romania allow localhost allow 192.168.0.0/16 allow myhost.mydomain.ro
Global Configuration: Email Notification(全局配置:邮件通知)
然后,我们来设置Monit的邮件通知。我们至少需要一个可用的SMTP服务器来让Monit发送邮件。这样就可以(按照你的实际情况修改):
邮件服务器的机器名:smtp.monit.ro
Monit使用的发件人:monit@monit.ro
邮件的收件人:guletz@monit.ro
邮件服务器使用的SMTP端口:587(默认是25)
有了以上信息,邮件通知就可以这样配置:
set mailserver smtp.monit.ro port 587 set mail-format{ from: monit@monit.ro subject:$SERVICE$EVENT at$DATE on$HOST message: Monit$ACTION$SERVICE$EVENT at$DATE on$HOST:$DESCRIPTION. Yours sincerely, Monit} set alert guletz@monit.ro
就像你看到的,Monit会提供几个内部变量($DATE、$EVENT、$HOST等),你可以按照你的需求自定义邮件内容。如果你想要从Monit所在机器发送邮件,就需要一个已经安装的与sendmail兼容的程序(如postfix或者ssmtp)。
Global Configuration: Monit Daemon(全局配置:Monit守护进程)
接下来就该配置Monit守护进程了。可以将其设置成这样:
在120秒后进行第一次检测。
每3分钟检测一次服务。
使用syslog来记录日志。
如下代码段可以满足上述需求。
set daemon 120 with start delay 240 set logfile syslog facility log_daemon
我们必须定义“idfile”,Monit守护进程的一个独一无二的ID文件;以及“eventqueue”,当monit的邮件因为SMTP或者网络故障发不出去,邮件会暂存在这里;以及确保/var/monit路径是存在的。然后使用下边的配置就可以了。
set idfile/var/monit/id set eventqueue basedir/var/monit
测试全局配置
现在“Global”部分就完成了。Monit配置文件看起来像这样:
# Global Section# status webpage and acl's set httpd port 1966 and SSL ENABLE PEMFILE/var/certs/monit.pem allow monituser:romania allow localhost allow 192.168.0.0/16 allow myhost.mydomain.ro# mail-server set mailserver smtp.monit.ro port 587# email-format set mail-format{ from: monit@monit.ro subject:$SERVICE$EVENT at$DATE on$HOST message: Monit$ACTION$SERVICE$EVENT at$DATE on$HOST:$DESCRIPTION. Yours sincerely, Monit} set alert guletz@monit.ro# delay checks set daemon 120 with start delay 240 set logfile syslog facility log_daemon# idfile and mail queue path set idfile/var/monit/id set eventqueue basedir/var/monit
现在是时候验证我们的工作了,你可以通过运行如下命令来验证存在的配置文件(/etc/monit.conf):
# monit-t Control file syntax OK
如果monit提示任何错误,请再检查下配置文件。幸运的是,错误/警告信息是可以帮助你发现问题的,比如:
monit: Cannot stat the SSL server PEM file'/var/certs/monit.pem'-- No such file or directory/etc/monit/monitrc:10: Warning: hostname did not resolve'smtp.monit.ro'
一旦你确认配置文件没问题了,可以启动monit守护进程,然后等2到3分钟:
# service monit start
如果你使用的是systemd,运行:
# systemctl start monit
现在打开一个浏览器窗口,然后访问。将<monit_host>替换成Monit所在机器的机器名或者IP地址。
如果你使用的是自签名的SSL证书,你会在浏览器中看到一个警告信息。继续访问即可。
你完成登录后,就会看到这个页面。
在这个教程的其余部分,我们演示监控一个本地服务器和常见服务的方法。你会在官方wiki页面看到很多有用的例子。其中的多数是可以直接复制粘贴的!
Service Configuration: CPU/Memory Monitoring(服务配置:CPU、内存监控)
我们先来监控本地服务器的CPU、内存占用。复制如下代码段到配置文件中。
check system localhost if loadavg(1min)> 10 then alert if loadavg(5min)> 6 then alert if memory usage> 75% then alert if cpu usage(user)> 70% then alert if cpu usage(system)> 60% then alert if cpu usage(wait)> 75% then alert
你可以很容易理解上边的配置。最上边的check是指每个监控周期(全局配置里设置的120秒)都对本机进行下面的操作。如果满足了任何条件,monit守护进程就会使用邮件发送一条报警。
如果某个监控项不需要每个周期都检查,可以使用如下格式,它会每240秒检查一次平均负载。
if loadavg(1min)> 10 for 2 cycles then alert
Service Configuration: SSH Service Monitoring(服务配置:SSH服务监控)
先检查我们的sshd是否安装在/usr/sbin/sshd:
check file sshd_bin with path/usr/sbin/sshd
我们还想检查sshd的启动脚本是否存在:
check file sshd_init with path/etc/init.d/sshd
最后,我们还想检查sshd守护进程是否存活,并且在监听22端口:
check process sshd with pidfile/var/run/sshd.pid start program"/etc/init.d/sshd start" stop program"/etc/init.d/sshd stop" if failed port 22 protocol ssh then restart if 5 restarts within 5 cycles then timeout
我
们可以这样解释上述配置:我们检查是否存在名为sshd的进程,并且有一个保存其pid的文件存在(/var/run/sshd.pid)。如果任何一个
不存在,我们就使用启动脚本重启sshd。我们检查是否有进程在监听22端口,并且使用的是SSH协议。如果没有,我们还是重启sshd。如果在最近的5
个监控周期(5x120秒)至少重启5次了,sshd就被认为是不能用的,我们就不再检查了。
Service Configuration: SMTP Service Monitoring(服务配置:SMTP服务监控)
现在我们来设置一个检查远程SMTP服务器(如192.168.111.102)的监控。假定SMTP服务器运行着SMTP、IMAP、SSH服务。
check host MAIL with address 192.168.111.102 if failed icmp type echo within 10 cycles then alert if failed port 25 protocol smtp then alert else if recovered then exec"/scripts/mail-script" if failed port 22 protocol ssh then alert if failed port 143 protocol imap then alert
我
们检查远程主机是否响应ICMP协议。如果我们在10个周期内没有收到ICMP回应,就发送一条报警。如果监测到25端口上的SMTP协议是异常的,就发
送一条报警。如果在一次监测失败后又监测成功了,就运行一个脚本(/scripts/mail-script)。如果检查22端口上的SSH或者143端
口上的IMAP协议不正常,同样发送报警。
centos下coreseek安装及使用方法
Coreseek中文全文检索引擎
Coreseek是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和信息处理领域,适用于行业/垂直搜索、论坛/站内搜索、数据库搜索、文档/文献检索、信息检索、数据挖掘等应用场景,用户可以免费下载使用
一,coreseek简介
官方
Coreseek是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和信息处理领域,适用于行业/垂直搜索、论坛/站内搜索、数据库搜索、文档/文献检索、信息检索、数据挖掘等应用场景。商业使用(例如,嵌入到其他程序中)需要获得商业授权。
Coreseek是一个支持中文的全文搜索引擎,意图为其他应用提供高速、低空间占用、高相关度结果的中文全文搜索能力。CoreSeek可以非常容易的与SQL数据库和脚本语言集成。
在Sphinx发行版本中提供的原生搜索API支持PHP、Python、Perl、Rudy和Java。搜索API非常轻量化,可以在几个小时之内移植到新的语言上。第三方API接口和插件提供了对Perl、C#、Haskell、Ruby-on-Rails支持,以及对其他可能的语言或者框架的支持。
版本介绍
Coreseek 3.2稳定版
Coreseek 4.1测式版
Coreseek 5最新版
二,安装Coreseek
注:本文是以centos+mysql做为数据源支持为基础的coreseek安装教程.mysql安装略过.
1,下载coreseek 3.2稳定版,下载其他版本请去官网自行下载
cd/usr/local/src/
wget
tar xzvf coreseek-3.2.14.tar.gz
cd coreseek-3.2.14
安装coreseek之前需要先安装需要预装的软件:yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel(注:这是centos 64位
其他系统请参考
2,安装mmseg
$ cd mmseg-3.2.14
$./bootstrap#输出的warning信息可以忽略,如果出现error则需要解决
$./configure--prefix=/usr/local/mmseg3
$ make make install
$ cd..
##如果提示libtool: unrecognized option `--tag=CC',请查看libtool问题解决方案
##安装完成后,mmseg使用的词典和配置文件,将自动安装到/usr/local/mmseg3/etc中
##中文分词测试,如果显示不正常,请检查当前环境下的locale和UTF-8中文字符显示设置
$/usr/local/mmseg3/bin/mmseg-d/usr/local/mmseg3/etc src/t1.txt
中文/x分/x词/x测试/x
中国人/x上海市/x
Word Splite took: 1 ms.
3,安装coreseek
$ cd csft-3.2.14
##执行configure,进行编译配置:
$ sh buildconf.sh
$./configure--prefix=/usr/local/coreseek--without-unixodbc--with-mmseg--with-mmseg-includes=/usr/local/mmseg3/include/mmseg/--with-mmseg-libs=/usr/local/mmseg3/lib/--with-mysql
如查提示找不到mysql includes file则使用下面的编译命令
./configure--prefix=/usr/local/coreseek--without-unixodbc--with-mmseg--with-mmseg-includes=/usr/local/mmseg3/include/mmseg/--with-mmseg-libs=/usr/local/mmseg3/lib/--with-mysql-includes=/alidata/server/mysql/include/--with-mysql-libs=/alidata/server/mysql/bin/
make make install
4,测式coreseek
cd../testpack
$/usr/local/coreseek/bin/indexer-c etc/csft.conf
##以下为正常情况下的提示信息:
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
##
##csft-4.0版显示:ERROR: nothing to do.
##
$/usr/local/coreseek/bin/indexer-c etc/csft.conf--all
##以下为正常索引全部数据时的提示信息:(csft-4.0版类似)
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
indexing index'xml'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 7585 bytes
total 0.075 sec, 101043 bytes/sec, 39.96 docs/sec
total 2 reads, 0.000 sec, 5.6 kb/call avg, 0.0 msec/call avg
total 7 writes, 0.000 sec, 3.9 kb/call avg, 0.0 msec/call avg
$/usr/local/coreseek/bin/indexer-c etc/csft.conf xml
##以下为正常索引指定数据时的提示信息:(csft-4.0版类似)
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
indexing index'xml'...
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 7585 bytes
total 0.069 sec, 109614 bytes/sec, 43.35 docs/sec
total 2 reads, 0.000 sec, 5.6 kb/call avg, 0.0 msec/call avg
total 7 writes, 0.000 sec, 3.9 kb/call avg, 0.0 msec/call avg
$/usr/local/coreseek/bin/search-c etc/csft.conf
##以下为正常测试搜索时的提示信息:(csft-4.0版类似)
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
index'xml': query'': returned 3 matches of 3 total in 0.093 sec
displaying matches:
1. document=1, weight=1, published=Thu Apr 1 22:20:07 2010, author_id=1
2. document=2, weight=1, published=Thu Apr 1 23:25:48 2010, author_id=1
3. document=3, weight=1, published=Thu Apr 1 12:01:00 2010, author_id=2
words:
$/usr/local/coreseek/bin/search-c etc/csft.conf-a Twittter和Opera都提供了搜索服务
##以下为正常测试搜索关键词时的提示信息:(csft-4.0版类似)
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
index'xml': query'Twittter和Opera都提供了搜索服务': returned 3 matches of 3 total in 0.038 sec
displaying matches:
1. document=3, weight=24, published=Thu Apr 1 12:01:00 2010, author_id=2
2. document=1, weight=4, published=Thu Apr 1 22:20:07 2010, author_id=1
3. document=2, weight=3, published=Thu Apr 1 23:25:48 2010, author_id=1
words:
1.'twittter': 1 documents, 3 hits
2.'和': 3 documents, 15 hits
3.'opera': 1 documents, 25 hits
4.'都': 2 documents, 4 hits
5.'提供': 0 documents, 0 hits
6.'了': 3 documents, 18 hits
7.'搜索': 2 documents, 5 hits
8.'服务': 1 documents, 1 hits
$/usr/local/coreseek/bin/searchd-c etc/csft.conf
##以下为正常开启搜索服务时的提示信息:(csft-4.0版类似)
Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release(r2117)]
Copyright(c) 2007-2010,
Beijing Choice Software Technologies Inc()
using config file'etc/csft.conf'...
listening on all interfaces, port=9312
三,配置coreseek支持mysql数据源
1,配置csft_mysql.conf文件
复制mysql配置文件到coreseek安装目录etc/下(比如/usr/local/coreseek/etc/)
cp/usr/local/src/coreseek-3.2.14/testpack/etc/csft_mysql.conf/usr/local/coreseek/etc/
cd/usr/local/coreseek/etc/
vi csft_mysql.conf
下面加红部分是需要你自己配置的
官方参考文档:数据源配置:mysql数据源
其他数据源请参考官方
==============================================================
#源定义
sourcephperz
{
type= mysql
sql_host=localhost
sql_user=root
sql_pass=xxxx
sql_db=phperz
sql_port= 3306
sql_query_pre= SET NAMES utf8
sql_query=SELECT id,title,descs,status from article
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
sql_attr_uint=status#从SQL读取到的值必须为整数
#sql_attr_timestamp= date_added#从SQL读取到的值必须为整数,作为时间属性
sql_query_info_pre= SET NAMES utf8#命令行查询时,设置正确的字符集
sql_query_info=SELECT* FROM article WHERE id=$id#命令行查询时,从数据库读取原始数据信息
}
#index定义
indexphperz
{
source=phperz#对应的source名称
path=/usr/local/coreseek/var/data/phperz#请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
docinfo= extern
mlock= 0
morphology= none
min_word_len= 1
html_strip= 0
#中文分词配置,详情请查看:
charset_dictpath=/usr/local/mmseg3/etc/#BSD、Linux环境下设置,/符号结尾
#charset_dictpath= etc/#Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
charset_type= zh_cn.utf-8
}
#全局index定义
indexer
{
mem_limit= 128M
}
#searchd服务定义
searchd
{
listen= 9312
read_timeout= 5
max_children= 30
max_matches= 1000
seamless_rotate= 0
preopen_indexes= 0
unlink_old= 1
pid_file=/usr/local/coreseek/var/log/searchd_mysql.pid#请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log=/usr/local/coreseek/var/log/searchd_mysql.log#请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log=/usr/local/coreseek/var/log/query_mysql.log#请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
}
==============================================================
2,建立索引
路经部分需要改成你自己的地址
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all
可能出现的错误
ERROR: index'phperz': sql_connect: Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2)(DSN=mysql://root:***@localhost:3306/phperz).
这是因为mysql的sock文件路经不正确导致的.
确认一下你的mysql.sock路经,建立一个软连接,比如
ln-s/tmp/mysql.sock/var/lib/mysql/mysql.sock
四,coreseek+php使用方式
复制安装止录下的/usr/local/src/coreseek-3.2.14/testpack/api/sphinxapi.php文件到你的项目里
你的程序里include sphinxapi.php
php使用方法见/usr/local/src/coreseek-3.2.14/testpack/api/test.php
另附我的使用方法:
===============================================================
$wd= trim($_GET['wd']);
include_once(JF_PATH./config/sph_cfg.php);
include_once(JF_PATH./include/sphinxapi.php);
$cl= new SphinxClient();
$cl-SetServer(SPH_SERVER_HOST, SPH_SERVER_POST);
$cl-SetConnectTimeout(3);
$cl-SetArrayResult(true);
$cl-SetMatchMode(1);
$cl-SetFilter(status, array(1));
$cl-SetLimits(0, 10);
$res=$cl-Query($wd, phperz_www);
if($res['matches']){
$rownum=$res['total'];
foreach($res['matches'] as$k=$v){
$re=$this-db-get_one(select* from article where id=.$v['id']);
if(!empty($re)){
$list[]=$re;
}
}
}
print_r($list);
===============================================================
五,coreseek日常维护
启动
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf
停止
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf--stop
建立索引
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all
重建索引
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all--rotate
你需要把启动命令加到开机自启动里
把重建索引命令加到计划任务里每天执行
本文为phperz原创,转载请注明出处.