YY博客

分享英语网站运营的经验

By

sphinx编译安装出错:undefined reference to libiconv 解决方案

编译过程中提示出错:
错误描述

/usr/local/sphinx/src/sphinx.cpp:20060:undefined reference to libiconv_open'
/usr/local/sphinx/src/sphinx.cpp:20078: undefined reference to
libiconv’
/usr/local/sphinx/src/sphinx.cpp:20084: undefined reference to libiconv_close'
collect2: ld returned 1exit status
make[2]:***[indexer]Error1
make[2]:Leaving directory
/home/sphinx/src’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/sphinx/src’
make: *** [all-recursive] Error 1

解决办法:sphinx-2.2.11-release亲测有效:
===============以下为解决方案=======================================================

原因是g++没有添加 -libiconv选项

cd sphinx-2.1.9-release
vi src/Makefile

把LIBS = -lm -lz -lexpat -L/usr/local/lib -lrt -lpthread
改成
LIBS = -lm -lz -lexpat -L/usr/local/lib -lrt -lpthread -liconv

即可。

By

Sphinx 安装与使用方法 详细记录

官方文档
http://sphinxsearch.com/docs/current.html

1)官方下载安装包
http://sphinxsearch.com/downloads/release/
上传sphinx安装包
tar xzvf sphinx-2.2.6-release.tar.gz
cd sphinx-2.2.6-release

2)配置编译和安装
./configure –prefix=/usr/local/sphinx
make
make install
或者一条命令 make && make install

((如果出错的话,可以参考sphinx编译安装出错:undefined reference to libiconv 解决方案))

3)配置 sphinx.conf

cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf
vi sphinx.conf

编辑配置文件,此处使用已编辑好的配置为sphinx-min.conf
上传sphinx-min.conf到/usr/local/sphinx/etc。

4)索引部分:

全索引
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx-min.conf –all
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx-min.conf –all –rotate
某部分索引
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx-min.conf -—mp3share_search
目前使用的配置,增加部分索引方法
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/conf.d/mp3songfree.conf –all
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/conf.d/mrtmp3.conf –all –rotate

//增量索引合并 –增量索引偏移表未建立 , 此处未使用增量索引, 以后再实现
//indexer –config /usr/local/sphinx/etc/sphinx-min.conf –merge mp3share mp3shareincre –rotate

5)开启searchd服务
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx-min.conf
查看服务状态
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx-min.conf –status
停止服务
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx-min.conf –stop

无缝轮换服务
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx-min.conf –rotate

6)整合进PHP中,使用SphinxQL,以及FoolCode的框架
==========FoolCode的框架 + composer包=====================
https://github.com/FoolCode/SphinxQL-Query-Builder/

7)增加开机启动项及定期更新索引

开机启动:
将以下命令
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx-min.conf

加入etc/rc.local

暂时手动更新索引

结束。
——–目录说明———–
searchd 目录: /usr/local/sphinx/bin/searchd

By

[Python]使用 urllib.quote 进行 url 编码小技巧

今天在采集数据的是遇到链接中有中文的时候urllib2.quote将冒号也给编码了,google了下,发现了这篇blog,转载如下,留着备用
python的url编码函数是在类urllib库中,使用方法是:

urllib.quote(string[, safe]),除了三个符号“_.-”外,将所有符号编码,后面的参数safe是不编码的字符,使用的时候如果不设置的话,会将斜杠,冒号,等号,问号都给编码了。
>>> import urllib
>>> urllib.quote(“a-b-c”)
‘a-b-c’
>>> urllib.quote(“a+b+c”)
‘a%2Bb%2Bc’
>>> urllib.quote(“http://test.com/a+b+c”)
‘http%3A//test.com/a%2Bb%2Bc’
>>> urllib.quote(“http://test.com/a+b+c”, “:/”)
‘http://test.com/a%2Bb%2Bc’
>>> urllib.quote(“http://test.com/?q=a+b+c”, “:?=/”)
‘http://test.com/?q=a%2Bb%2Bc’
urllib2.quote 也是一样用法

By

FastDFS海量数据分布式存储方案(安装,配置,上线)

方案详细讲解:

By

利用MySQLTuner 优化 MySQL 性能(亲测)

MySQLTuner(https://github.com/major/MySQLTuner-perl/) 是一个 Perl 脚本,可以用来分析您的 MySQL 性能,并且基于收集到的信息给出相应的优化建议。这样子,您就可以调整 my.cnf 从而优化您的 MySQL 设置。

这边只是介绍使用方法,不保证说 MySQLTuner 对您就是绝对有效。

首先需要下载 MySQLTuner

# wget https://raw.github.com/major/MySQLTuner-perl/master/mysqltuner.pl

设置权限为可执行

# chmod +x mysqltuner.pl

然后就可以直接运行了

# ./mysqltuner.pl

如果遇到错误 Unable to find mysqladmin in your $PATH 可以输入

# PATH=$PATH:/usr/local/mysql/bin

PS:把 /usr/local/mysql/bin 改为您 MySQL 程序 mysqladmin 的路径

运行后的内容如下:

>> MySQLTuner 1.2.0 – MySQL High Performance Tuning Script
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with ‘–help’ for additional options and output filtering
Please enter your MySQL administrative login: <-- root Please enter your MySQL administrative password: <-- yourrootsqlpassword -------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [!!] Your MySQL version 4.1.11-Debian_etch1-log is EOL software! Upgrade soon! [OK] Operating on 32-bit architecture with less than 2GB RAM -------- Storage Engine Statistics ------------------------------------------- [--] Status: +Archive -BDB -Federated +InnoDB +ISAM -NDBCluster [--] Data in MyISAM tables: 301M (Tables: 2074) [--] Data in HEAP tables: 379K (Tables: 9) [!!] InnoDB is enabled but isn't being used [!!] ISAM is enabled but isn't being used [!!] Total fragmented tables: 215 -------- Performance Metrics ------------------------------------------------- [--] Up for: 12d 18h 33m 30s (1B q [1K qps], 185K conn, TX: 3B, RX: 377M) [--] Reads / Writes: 78% / 22% [--] Total buffers: 2.6M per thread and 58.0M global [OK] Maximum possible memory usage: 320.5M (20% of installed RAM) [OK] Slow queries: 0% (17/1B) [OK] Highest usage of available connections: 32% (32/100) [OK] Key buffer size / total MyISAM indexes: 16.0M/72.3M [OK] Key buffer hit rate: 99.9% [OK] Query cache efficiency: 99.9% [!!] Query cache prunes per day: 47549 [OK] Sorts requiring temporary tables: 0% [!!] Temporary tables created on disk: 28% [OK] Thread cache hit rate: 99% [!!] Table cache hit rate: 0% [OK] Open file limit used: 12% [OK] Table locks acquired immediately: 99% [!!] Connections aborted: 20% -------- Recommendations ----------------------------------------------------- General recommendations: Add skip-innodb to MySQL configuration to disable InnoDB Add skip-isam to MySQL configuration to disable ISAM Run OPTIMIZE TABLE to defragment tables for better performance Enable the slow query log to troubleshoot bad queries When making adjustments, make tmp_table_size/max_heap_table_size equal Reduce your SELECT DISTINCT queries without LIMIT clauses Increase table_cache gradually to avoid file descriptor limits Your applications are not closing MySQL connections properly Variables to adjust: query_cache_size (> 16M)
tmp_table_size (> 32M)
max_heap_table_size (> 16M)
table_cache (> 64)
浏览输出的结果,特别是末尾的 Recommendations ,里面一般会提到您需要在 my.cnf 修改的内容。修改 my.cnf 后记得重启 MySQL 。重启后再运行 MySQLTuner 检查。另外需要注意的是 MySQL 需要启动 24 小时候再运行 MySQLTuner ,不然有些内容会不准。
来自:http://tesfans.org/tuning-mysql-performance-with-mysqltuner/

本博主亲测,本脚本对MySQL 性能优化很有效果,但是5.5.20版本以下,因bug问题请注意table_open_cache不要超过64,否则会降低性能(详见:http://bit.ly/1mi7c4C)。
官方:http://bugs.mysql.com/bug.php?id=49177

By

/var/run/mysqld/mysqld.sock无法连接的解决办法

今天在给朋友开空间的时候,发现数据库的/var/run/mysqld/mysqld.sock无法连接,很是奇怪。因为在我安装mysql数据库的时候,通过mysql -uroot -p是可以正常连接的,不知道什么原因,今天再使用这个命令的时候,提示“Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)”。
开始我还以为mysql数据库没有启动,我先查看了一下mysql的状态,是正常启动的。这就不清楚是什么原因导致的了。
于是我就尝试着用mysql –socket=/tmp/mysql.sock -uroot -p发现能连接上了。那这就是第一种方法了!
既然可以通过–socket=/tmp/mysql.sock 来连接,而直接使用的时候是用/var/run/mysqld/mysqld.sock,为什么不搞个软连接了,于是就有了第二个方法:
mkdir -p /var/run/mysqld
ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock
最后测试用mysql -uroot -p可以正常连接了,不再用–socket了!
以上的方法是暂时的方法,因为/tmp/下的文件,重新启动后就没有了,想要得到最终的解决办法,还是要找到产生这个问答的原因。
其实原因就是,在你卸载系统中以前安装的MYSQL的时候,没有清除/etc/my.cnf文件,所以,大家在出现这样的问题的时候,一定要先检查一下,你的/etc/目录里面,有没有你系统中以前安装过的配置文件,确保这里没有问题。

By

mysql服务无法正常启动,The server quit without updating PID file (/var/run/mysqld/mysqld.pid)

开机后,mysql服务无法正常启动,报如下错误:

The server quit without updating PID file (/var/run/mysqld/mysqld.pid)

如何解决呢?首先确定你的硬盘空间充足

先用命令查询一下:

du -sh /*

如果确定硬盘空间够,那么执行以下命令:

sudo find / -name my.cnf

执行完毕,会出现文件名为my.cnf的所有路径列表,找到你的mysql配置文件,干掉其他无关的my.cnf,或者改名,然后重启,应该就行了。

出现这种问题的原因一般是,服务器已经安装mysql,安装其他包的时候,可能不知道怎么被附加了mysql的配置文件,导致mysql启动的时候,无法加载正确的配置文件。

来自:http://www.dotpig.net/2014/08/13/the-server-quit-without-updating-pid-file-varrunmysqldmysqld-pid/

=============================================================
网页出现:
Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
摘要:解决不能通过mysql .sock连接MySQL问题 这个问题主要提示是,不能通过 ‘/tmp/mysql.sock’连到服务器,而php标准配置正是用过’/tmp/mysql.sock’,但是一些mysql 安装方法 将 mysql.sock放在/var/lib/mysql.sock或者其他的什么地方,你可以通过修改/etc/my.cnf文件来修正它,打开文件,可以看到如下的东东:

  [mysqld]
  socket=/var/lib/mysql.sock
  改一下就好了,但也会引起其他的问题,如mysql 程序连不上了,再加一点:
  [mysql]
  socket=/tmp/mysql.sock
  或者还可以通过修改php.ini中的配置来使php用其他的mysql.sock来连,这个大家自己去找找
  
  或者用这样的方法:
  ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

网上的有问题,其实是这样的(上面的已修正过了):

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock

By

debian7 安装 MySQLdb模块