SVN轻量服务器搭建

1.安装subversion服务。
Ubuntu:sudo apt-get install subversion
Centos:sudo yum install subversion
2.创建SVN仓库,如axfcms。
svnadmin create /svnRepos/axfcms
3.修改/svnRepos/conf目录下的所有文件。
A.修改svnserv.conf。命令如下:vim /svnRepo/axfcms/conf/svnserve.conf。

[general]
#匿名用户不可读
anon-access = none
#权限用户可写
auth-access = write
#密码文件为passwd
password-db = passwd
#权限文件为authz
authz-db = authz

B.添加访问用户:vim /svnRepo/axfcms/conf/passwd
[users]
# harry = harryssecret
# sally = sallyssecret
tone = 12345 #等号前是用户名,等号后是密码。
C.修改授权信息:vim /svnRepo/axfcms/conf/authz
[groups]
admin= tone
[/]
@admin = rw
*=r
4.启动服务
svnserve -d -T -r /svnRepo
5.随系统启动,在vim /etc/rc.local追加如下
svnserve -d -T -r /svnRepo/

6.客户端访问:
svn checkout svn://xxx.xxx.xxx.xxx/axfcms axfcms

找出当前目录的磁盘空间占用

1.列出当前目录下各子目录的磁盘占用:
ls|awk '$0'|xargs du -shdu -h --max-depth=1
2.列出当前目录下文件的大小:
ls -lhll -h
3.磁盘占用:df -h

cd / && ls|awk '$0'|xargs du -sh
clear && df -h && cd / && du -h --max-depth=1

4.列出已经删除但依旧没有释放的文件。
lsof|grep deleted

批量杀死特定进程

例如要杀死phantomjs的父进程为1的进程。
ps -ef |grep phantomjs| awk ‘$3==1 {print $2}’ | xargs kill -9

使用时,可以拆解上述命令,观察其最终删除了那些进程,如下。
1.ps -ef |grep phantomjs
2.ps -ef |grep phantomjs| awk ‘$3==1 {print $2}’

批量部署scrapy爬虫

1.首先安装scrapyd。
2.在爬虫scrapy.cfg文件中,清加如下列表:

[deploy:s158] #冒号隔开。
url = http://192.168.1.158:6800/

[deploy:s161]
url = http://192.168.2.161:6800/

[deploy:s88]
url = http://10.199.3.88:6800/

3.在与scrapy.cfg同级目录下建立任意py文件,如depoy.py文件,在其添加如下代码。

# -*- coding: utf-8 -*-
import os

project = os.path.dirname(__file__)
project = os.path.basename(project)
hosts = ['s158', 's161', 's88']
for it in hosts:
command = 'scrapy deploy %s -p %s' %(it, project)
os.system(command)

———————————————-

sh脚本:
#!/bin/sh

# you should modify some parameter below.

project='webproxy'

# hosts' string are from scrapy.cfg file at the same directory.
hosts="s2 s254 s102"

# ---------------------------------------------
# code body.
path=$(dirname $(readlink -f $0))
prjdir="$path/$project"

if [ ! -d "$prjdir" ]; then
echo ""
echo "can't find the path like ${prjdir}."
echo "make sure the spiders were done in this path."
echo ""
exit
fi

echo ""
echo "----"
echo "ready to deploy '$project' to [$hosts]"
echo "----"
echo ""

read -p "Do you want to continue [Y/N]?" answer
case $answer in
Y | y)
echo ""
for it in $hosts
do
scrapy deploy $it -p $project
done
;;
*)
echo ""
echo "nothing to do, good bye!!"
;;
esac
echo ""
echo ""

Mysql绿色版安装过程

1.下载:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-winx64.zip
2.安装mysql服务:mysqld –install mysql
3.启动数据库:net start mysql
4.停止数据库:net stop mysql
5.删除mysql服务:mysqld remove mysql

配置PHP环境变量

使用阿里LNMP,故其环境变量配置如下:
1.#vi /etc/profile
如增加一个环境变量:
export MY_REDIS_HOST="localhost"
——————-
2.修改php-fpm.conf,设置PHP环境变量:
#vi /etc/php5/fpm/php-fpm.conf
增加:
env[MY_REDIS_HOST]=$MY_REDIS_HOST

——————————-
3.在/etc/init.d/php-fpm脚本的合适位置添加:. /etc/profile。
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

. /etc/profile # i'm here.

php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"

wait_for_pid () {
注意,点号与路径之间有空格。实际上.与source是一样的,但是这里用source会报错
还要修改/etc/profile的权限,因为php-fpm启动用户是www-data , 而/etc/profile的权限用户为root,这里为了简章,将/etc/profile的权限设为“777”,即:
#chmod 777 /etc/profile
————————
4.修改php.ini配置。
因为php.ini默认不载入$_ENV变量定义,如果此时查看phpinfo(),会发现我们设置的环境变量为”no value”。
#vi /etc/php5/fpm/php.ini
修改:variables_order为:
variables_order="EGPCS"
————–
5.重启php-fpm
#service php5-fpm restart
6.测试设置结果。
查看phpinfo(),在”Enviroment variables” 一节与“PHP variables”一节内可能看到我们刚才设置的变量名及变量值。

使用国内镜像源来加速python pypi包的安装

pipy国内镜像目前有:
http://pypi.douban.com/ 豆瓣
http://pypi.hustunique.com/ 华中理工大学
http://pypi.sdutlinux.org/ 山东理工大学
http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学
对于pip这种在线安装的方式来说,很方便,但网络不稳定的话很要命。使用国内镜像相对好一些,如果想手动指定源,可以在pip后面跟-i 来指定源,比如用豆瓣的源来安装web.py框架:
pip install web.py -i http://pypi.douban.com/simple
注意后面要有/simple目录!!!
要配制成默认的话,需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改内容为:
code:
[global]
index-url = http://pypi.douban.com/simple
————————
Configuration
Config file
pip allows you to set all command line option defaults in a standard ini style config file.
The names and locations of the configuration files vary slightly across platforms.
On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf
On Windows, the configuration file is: %HOME%\pip\pip.ini

You can set a custom path location for the config file using the environment variable PIP_CONFIG_FILE.

The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (–index-url) and set the HTTP timeout (–default-timeout) to 60 seconds your config file would look like this:
[global]
timeout = 60
index-url = http://download.zope.org/ppix

———————————
方法2:配置方式修改
easy_install:
1.打开pydistutils.cfg
vi ~/.pydistutils.cfg
——
2.写入以下内容
[easy_install]
index_url = http://e.pypi.python.org/simple
————————
pip:
1.打开pip.conf
vi ~/.pip/pip.conf
2.写入以下内容
[global]
index-url = http://e.pypi.python.org/simple
速度比较快的国内镜像,都来自清华大学,服务器在北京。公网的服务器为官方镜像
公网:http://e.pypi.python.org/simple
教育网:http://pypi.tuna.tsinghua.edu.cn/simple

磁盘挂载

在阿里云购买了个数据盘,需要挂载,但发现网上的方法太混乱了,于是把验证有效的方法转载如下:

转:

1. 虚拟机设置添加,选择硬盘添加

2. 首先为磁盘创建文件系统:mkfs.ext3 /dev/sdb

3. 创建挂载点:mkdir /mnt/sdb

4. 挂载:mount /dev/sdb /mnt/sdb

5. fdisk -l

    发现有问题:

    Disk /dev/sdb doesn’t contain a valid partition table

6. fdisk /dev/sdb

跟着向导一步步做下去(如果不知道该输入什么,就输入“m”并回车,可以打印出菜单):

Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

(后面的菜单省略,太长了)

这里我们要添加一个新的分区,所以输入“n”

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-14098, default 1): (此处直接回车)

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-14098, default 14098): (此处直接回车)

Using default value 14098

Command (m for help): p

Disk /dev/sdb: 115.9 GB, 115964116992 bytes

255 heads, 63 sectors/track, 14098 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1       14098   113242153+  83  Linux

现在可以写入分区表了,所以输入“w”

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

现在再fdisk -l,结果正常

mysql数据损坏修复方法

1、myisamchk
使用 myisamchk 必须暂时停止 MySQL 服务器。例如,我们要检修 discuz 数据库。执行以下操作:
# service mysql stop (停止 MySQL );
# myisamchk -r /数据库文件的绝对路径/*MYI
# service mysql start
myisamchk 会自动检查并修复数据表中的索引错误。
2、mysqlcheck
使用 mysqlcheck 无需停止 MySQL ,可以进行热修复。操作步骤如下:
# mysqlcheck -r discuz.*

# service mysql stop (停止 MySQL );
# myisamchk -r /数据库文件的绝对路径/*MYI
# service mysql start
myisamchk 会自动检查并修复数据表中的索引错误。

注意,无论是 myisamchk 还是 mysqlcheck ,一般情况下不要使用 -f 强制修复,-f 参数会在遇到一般修复无法成功的时候删除部分出错数据以尝试修复。所以,不到万不得已不要使用 -f。