drop function if exists rand_string;
create function rand_string(str_length tinyint unsigned, str_type tinyint unsigned) returns varchar(255)
begin
-- Function : rand_string
-- Author : reymondtu#opencfg.com
-- Date : 2011/03/27
-- Params : str_length int unsigned
-- The random string length of random string
-- str_type int unsigned
-- The random string type
-- 1.0-9
-- 2.a-z
-- 3.A-Z
-- 4.a-zA-Z
-- 5.0-9a-zA-Z
--
-- Example :
--
-- mysql> select rand_string(32,5) from dual;
-- +----------------------------------+
-- | rand_string(32,5) |
-- +----------------------------------+
-- | HbPBz4DWSAiJNLt4SgExHVwQI34bI6mt |
-- +----------------------------------+
-- 1 row in set
declare counter int unsigned default 0;
declare const_chars varchar(64) default '0123456789';
declare result varchar(255) default '';
if str_type = 1 then
set const_chars = '0123456789';
elseif str_type = 2 then
set const_chars = 'abcdefghijklmnopqrstuvwxyz';
elseif str_type = 3 then
set const_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
elseif str_type = 4 then
set const_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
elseif str_type = 5 then
set const_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
else
set const_chars = '0123456789';
end if;
while counter < str_length do
set result = concat(result,substr(const_chars,ceil(rand()*(length(const_chars)-1)),1));
set counter = counter + 1;
end while;
return result;
end
linux内核升级后导致virtualbox不可用
解决办法:
sudo /etc/init.d/vboxdrv setup
sphinx faceted searching
查看nginx日志访问最多的10个ip
代码如下:
cat access.log | grep /item | awk '{ print $1 }' | sort | uniq -c | sort -rn | head -n 10
centos 安装 mqtt
安装服务端和客户端
wget -O /etc/yum.repos.d/mqtt.repo download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/home:oojah:mqtt.repo
yum update
yum install mosquitto mosquitto-clients
chkconfig mosquitto on
service mosquitto start
pypy+pip+virtualenv
安装pypy
yum install pypy*
安装pip
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
pypy get-pip.py
添加pypy pip别名
alias pypy_pip='/usr/lib64/pypy-2.2.1/bin/pip'
建立virtualenv
virtualenv ~/pypy -p `which pypy`
source ~/pypy/bin/activate
python --version
deactivate
如何退出python virtualenv
直接运行deactivate即可
python 性能优化
amazon aws linux下python环境安装
允许远程通过密码登录
给root设置一个密码,允许远程通过密码登录
chmod 400 xxx.pem
ssh -i xxx.pem ec2-user@host-ip
sudo passwd root
sudo su -
vim /etc/ssh/sshd_config
/etc/ssh/sshd_config内容如下
PermitRootLogin yes
PasswordAuthentication yes
UsePAM yes
然后
service sshd reload
开启epel
amazon aws如果采用redhat需要额外收授权费,目前aws官方2014.3基于centos 6,许多软件版本较旧,可以通过epel软件仓库安装一些新软件
yum-config-manager --enable epel
yum update
安装基本环境
yum groupinstall "Development tools" -y
yum install openssl-devel libxslt-devel libxml2-devel libffi-devel -y
安装mysql客户端
vim /etc/yum.repos.d/MariaDB.repo
# MariaDB 5.5 CentOS repository list - created 2014-09-13 05:43 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
安装MariaDB客户端
yum install MariaDB-client mysql-devel -y
安装redis客户端
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum-config-manager --enable remi
yum install redis -y
安装mongodb客户端
vim /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
安装mongodb客户端
yum update
yum install mongodb-org-shell -y
安装python环境
# yum install centos-release-SCL (aliyun only)
yum install python27*
yum install freetype-devel libjpeg-devel libpng-devel
# scl enable python27 bash (aliyun only)
virtualenv --no-site-packages /data/pyenv
source /data/pyenv/bin/activate
pip install redis cryptography sqlalchemy flask simplejson mongoengine python-amazon-product-api scrapy mysql-python gunicorn gevent
安装glusterfs客户端
#install glusterfs repo
wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/glusterfs-epel.repo
#fix it for amazon linux
sed -i 's/$releasever/6/g' /etc/yum.repos.d/glusterfs-epel.repo
#install glusterfs
yum install -y glusterfs-fuse
#setup fstab
echo "172.31.42.77:/pcvol /data_pcvol glusterfs defaults,noatime 0 0" >> /etc/fstab
#mount
mkdir /data_pcvol
mount -a
ls /data_pcvol
挂载日志磁盘
lsblk
mkfs -t ext4 /dev/xvdf
echo '/dev/xvdf /data_log ext4 defaults,nofail 0 2' >> /etc/fstab
mkdir /data_log
mount -a
centos mongodb安装
添加repo
vim /etc/yum.repos.d/mongodb.repo
[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el$releasever/
gpgcheck=0
enabled=1
安装启动
yum makecache
yum install mongodb-org
chkconfig mongod on
service mongod start