百度云虚拟主机BCH 配置 rewrite重写功能

今天上午配置了下邯郸信息港的重写功能 , 增加网站访问效率,这个功能还是要加的,用的是百度的云虚拟主机 nginx 内核

直接加重写显然不现实,还好百度说明文档给出解决办法

基础配置文件不能修改,用户如有特殊需要,可添加bcloud_nginx_user.conf文件添加自定义配置

也就是说在/webroot 目录 直接建立一个 bcloud_nginx_user.conf

location /{

if ($host ~* www\.(.*)){
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}

}

这是www跳转写法 , 我用的是二级域名所以直接给大家看下dz3.3的静态化重写规则

Linux 查看蜘蛛爬虫记录

1. 百度蜘蛛爬行的次数

linux centos6 和 centos7 的一些区别

平时的我们基本都用CentOS 6 。但是偶尔遇到的就记录下来了,与大家分享。

防火墙
[CentOS 6]    iptables
[CentOS 7]    firewalld

在7中开启80端口

  1. firewall-cmd –zone=public –add-port=80/tcp –permanent   #出现success表明添加成功

复制代码

命令含义:

 

–zone                       #作用域

–add-port=80/tcp  #添加端口,格式为:端口/通讯协议

–permanent           #永久生效,没有此参数重启后失效

详细可参考 ## 传送门##

linux centos7 lnmp nginx 热处理

查找现有版本的模块 /usr/local/nginx/sbin/nginx -V

为添加模块安装openssl

http://www.openssl.org/source/openssl-1.0.1j.tar.gz
cd /usr/local/src
mkdir /usr/local/openssl
tar zxvf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j
./config –prefix=/usr/local/openssl
make
make install
vi /etc/profile
export PATH=$PATH:/usr/local/openssl/bin
:wq!
重新编译NGINX代码和模块
./configure –prefix=/usr/local/nginx –with-openssl=/usr/local/src/openssl-1.0.2
不要安装

make install
make 执行成功结束后我们当前目录objs中的nginx
复制到nginx执行目录

备份原文件
cp /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak
覆盖文件
cp objs/nginx /usr/local/nginx/sbin/nginx
热重启

/usr/local/nginx/sbin/nginx -s reload

linux centos7 nginx 开机启动设置

假定你源码安装Nginx:
安装路径是/usr/local/nginx
否则变更下面路径的文件:

#cd /etc/init.d/

#vi nginx
粘贴刚才的内容。检查是不是完整
#chmod +x nginx
#chkconfig add nginx
#chkconfig nginx on
在Centos下是这样。其他类同。

#!/bin/sh

#

#nginx – this script starts and stops the nginx daemin

#

# chkconfig:   – 85 15

# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \

#               proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /home/lnmp/nginx/conf/nginx.conf

# pidfile:     /home/lnmp/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ “$NETWORKING” = “no” ] && exit 0

nginx=”/home/lnmp/nginx/sbin/nginx”

prog=$(basename $nginx)

NGINX_CONF_FILE=”/home/lnmp/nginx/conf/nginx.conf”

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $”Starting $prog: ”

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $”Stopping $prog: ”

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $”Reloading $prog: ”

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case “$1″ in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $”Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}”

exit 2

esac

linux centos7 lnmp 手动编译,添加php模块

一、下载软件包

1、下载php

2、下载libmcrypt(安装mcrypt需要此软件包)

http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

3、下载mhash(安装mcrypt需要此软件包)

https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

4、下载mcrypt

https://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz

二、安装软件包

1、安装libmcrypt

cd /usr/local/src  #进入软件包存放目录

tar zxvf libmcrypt-2.5.8.tar.gz  #解压

cd libmcrypt-2.5.8  #进入安装目录

./configure  #配置

make #编译

make install  #安装

2、安装mhash

cd /usr/local/src

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure

make

make install

3、安装mcrypt

cd /usr/local/src

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

ln -s   /usr/local/bin/libmcrypt_config   /usr/bin/libmcrypt_config  #添加软连接

export LD_LIBRARY_PATH=/usr/local/lib  #添加环境变量

./configure

make

make install

如果/home/lnmp/php/lib/extion/…/mcrypt.so 说明成功

linux centos7 常见报错整理

错误:configure: error: libevent >= 1.4.11 could not be found
解决:yum -y install libevent libevent-devel
错误:configure: error: Please reinstall the mysql distributio
解决:yum -y install mysql-devel
错误:make: * [sapi/fpm/php-fpm] error 1
解决:用make ZEND_EXTRA_LIBS=’-liconv’编译
错误:configure: error: XML configuration could not be found
解决:yum -y install libxml2 libxml2-devel
错误:configure: error: No curses/termcap library found
解决:yum -y install ncurses ncurses-devel
错误:configure: error: xml2-config not found
解决:yum -y install libxml2 libxml2-devel
错误:configure: error: Cannot find OpenSSL’s <evp.h>
解决:yum install openssl openssl-devel
错误:configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决:yum install curl curl-devel
错误:configure: error: Cannot find ldap.h
解决:yum install openldap openldap-devel
错误:configure: error: libjpeg.(a|so) not found
解决:yum install libjpeglibjpeg -devel
错误:configure: error: libpng.(a|so) not found.
解决:yum install libpnglibpng –devel
错误:onfigure: error: freetype.h not found.
解决:yum install freetype-devel
错误:configure: error: cannot find output from lex; giving up
解决:yum -y install flex
错误:configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
解决:yum -y install zlib-devel openssl-devel
错误:Configure: error: Unable to locate gmp.h
解决:yum install gmp-devel
错误:Configure: error: Cannot find MySQL header files under /usr.
Note that the MySQL client library is not bundled anymore!
解决:yum install mysql-devel
更多的补充内容:
安装php: ./configure configure: error: XML configuration could not be found
yum -y install libxml2 libxml2-devel
Cannot find OpenSSL’s <evp.h> yum install openssl openssl-devel
1) Configure: error: xml2-config not found. Please check your libxml2 installation.
yum install libxml2 libxml2-devel (For RedHat & Fedora)
aptitude install libxml2-dev (For Ubuntu)
2) Checking for pkg-config… /usr/bin/pkg-config configure: error: Cannot find OpenSSL’s <evp.h>
yum install openssl openssl-devel
3) Configure: error: Please reinstall the BZip2 distribution
yum install bzip2 bzip2-devel
4) Configure: error: Please reinstall the libcurl distribution – easy.h should be in <curl-dir>/include/curl/
yum install curl curl-devel (For RedHat & Fedora)
install libcurl4-gnutls-dev (For Ubuntu)
5) Configure: error: libjpeg.(also) not found.
yum install libjpeg libjpeg-devel
6) Configure: error: libpng.(also) not found.
yum install libpng libpng-devel
7) Configure: error: freetype.h not found.
yum install freetype-devel
8) Configure: error: Unable to locate gmp.h
yum install gmp-devel
9) Configure: error: Cannot find MySQL header files under /usr. Note that the MySQL client library is not bundled anymore!
yum install mysql-devel (For RedHat & Fedora)
apt-get install libmysql++-dev (For Ubuntu)
10) Configure: error: Please reinstall the ncurses distribution
yum install ncurses ncurses-devel
11) Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
yum install unixODBC-devel
12) Configure: error: Cannot find pspell
yum install pspell-devel
13) configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install libmcrypt libmcrypt-devel (For RedHat & Fedora)
apt-get install libmcrypt-dev
14) Configure: error: snmp.h not found. Check your SNMP installation.
yum install net-snmp net-snmp-devel
15)
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: * [sapi/cgi/php-cgi] Error 1
yum install libtool-ltdl.x86_64 libtool-ltdl-devel.x86_64
16)
为php编译xcache模块的时候,需要运行phpize
得到了一个错误
/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.
通过安装 autoconf 可以解决
centos下执行 yum install autoconf 即可
Ubuntu下执行 apt-get install autoconf 即可
17)
/usr/local/php/bin/phpize
Cannot find config.m4.
Make sure that you run ‘/usr/local/php/bin/phpize’ in the top level source directory of the module
修改方法:
[[email protected] lnmp]# cd php-5.2.14ext/
[[email protected] ext]# ./ext_skel –extname=my_module
Creating directory my_module
Creating basic files: config.m4 config.w32 .cvsignore my_module.c php_my_module.h CREDITS EXPERIMENTAL tests/001.phpt my_module.php [done].
To use your new extension, you will have to execute the following steps:
$ cd ..
$ vi ext/my_module/config.m4
$ ./buildconf
$ ./configure –[with|enable]-my_module
$ make
$ ./php -f ext/my_module/my_module.php
$ vi ext/my_module/my_module.c
$ make Repeat steps 3-6 until you are satisfied with ext/my_module/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
[[email protected] ext]# cd my_module/
[[email protected] my_module]# vim config.m4
根据你自己的选择将
dnl PHP_ARG_WITH(my_module, for my_module support,
dnl Make sure that the comment is aligned:
dnl [ –with-my_module Include my_module support])
修改成
PHP_ARG_WITH(my_module, for my_module support,
Make sure that the comment is aligned:
[ –with-my_module Include my_module support])
或者将
dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,
dnl Make sure that the comment is aligned:
dnl [ –enable-my_module Enable my_module support])
修改成
PHP_ARG_ENABLE(my_module, whether to enable my_module support,
Make sure that the comment is aligned:
[ –enable-my_module Enable my_module support])
[[email protected] my_module]# vim my_module.c
将文件其中的下列代码进行修改
/* Every user visible function must have an entry in my_module_functions[].
*/
function_entry my_module_functions[] = {
PHP_FE(say_hello,    NULL) / ?添加着一行代码 /
PHP_FE(confirm_my_module_compiled,   NULL) / For testing, remove later. /
{NULL, NULL, NULL}   / Must be the last line in my_module_functions[] /
};
在文件的最后添加下列代码
PHP_FUNCTION(say_hello)
{
zend_printf(“hello sdomain!”);
}
再修改:php_sdomain.h
vi php_sdomain.h
在PHP_FUNCTION(confirm_my_module_compiled ); / For testing, remove later. / 这行的下面添加一行:
PHP_FUNCTION(say_hello); / For testing, remove later. /
保存文件退出
然后我们就可以在这个目录下使用上面的命令了
/usr/local/php/bin/phpize
执行以后会看到下面的
[[email protected] sdomain]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:     20020918
Zend Module Api No:   20020429
Zend Extension Api No:  20050606
[[email protected] sdomain]#
然后执行./configure –with-php-config=/usr/local/php/bin/php-config
然后执行make
make install
然后他会把对应的so文件生成放到PHP安装目录下面的一个文件夹,并提示在在什么地方,然后再把里面的SO文件拷到你存放SO文件的地方
即你在php.ini里面的extension_dir所指定的位置
最后一步是你在php.ini文件中打开这个扩展
extension=sdomain.so
然后
重新起动apache
以上错误都是在整个编译安装遇到的问题,然后结合网上的资料,找到的解决方法,总结到这个地方,希望能帮到大家!

linux centos7 supervisor 进程管理安装使用

1.install
easy_install supervisor or pip install supervisor #可以源码安装或是python安装,看个人

# yum install python-setuptools
# easy_install supervisor
如果easy_install不好使就从官方下载:
然后通过python安装:
# tar zxf supervisor-3.1.3.tar.gz
# cd supervisor
# python setup.py install

2.init
# 初始化配置文件
# 此命令会在 /etc/下创建一个示例配置文件
/usr/bin/echo_supervisord_conf > /etc/supervisord.conf

3.修改配置文件:

在supervisord.conf最后增加(分号后边的表示注释,可以不写):

[program:demo]
process_name=%(program_name)s_%(process_num)02d
command=php /usr/local/www/artisan queue:listen redis –sleep=1 –tries=0
autostart=true
autorestart=true
user=nginx
numprocs=2
redirect_stderr=true
stdout_logfile=/usr/local/www/storage/logs/queue.log
(更多配置说明请参考:http://supervisord.org/configuration.html)

运行命令:

supervisord -c /etc/supervisord.conf //启动supervisor

supervisorctl //打开命令行
[root @iZ2365j7l5bZ bin]# supervisorctl status
bandwidth RUNNING pid 2423 , uptime 0 : 06 : 35
[root @iZ2365j7l5bZ bin]# supervisorctl help

ctl中: help //查看命令

ctl中: status //查看状态

另外有一个坑需要注意:如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件,否则不会生效。。。
Supervisord 是用Python实现的一款非常实用的进程管理工具,在批量服务化管理时特别有效。可以将非Daemon的应用转为daemon程序。关于supervisord的安装和配置,在网上已经有很多现成的帖子,我这里就不重复了
在centos和rhel的环境下,我们一般是用chkconfig来管理服务的启动停止、开机自启动等。下面我列出Supervisord的服务脚本:

vi /etc/init.d/supervisord

#!/bin/bash
#
# supervisord This scripts turns supervisord on
# chkconfig: 345 83 04
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
#

# source function library
. /etc/rc.d/init.d/functions

set -a

PREFIX=/usr/local

SUPERVISORD=$PREFIX/bin/supervisord
SUPERVISORCTL=$PREFIX/bin/supervisorctl

PIDFILE=/var/supervisor/supervisord.pid
LOCKFILE=/var/supervisor/supervisord.lock

OPTIONS=”-c /etc/supervisord.conf”

# unset this variable if you don’t care to wait for child processes to shutdown before removing the $LOCKFILE-lock
WAIT_FOR_SUBPROCESSES=yes

# remove this if you manage number of open files in some other fashion
ulimit -n 96000

RETVAL=0
running_pid()
{
# Check if a given process pid’s cmdline matches a given name
pid=$1
name=$2
[ -z “$pid” ] && return 1
[ ! -d /proc/$pid ] && return 1
(cat /proc/$pid/cmdline | tr “\000” “\n”|grep -q $name) || return 1
return 0
}

running()
{
# Check if the process is running looking at /proc
# (works for all users)

# No pidfile, probably no daemon present
[ ! -f “$PIDFILE” ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $SUPERVISORD || return 1
return 0
}

start() {
echo “Starting supervisord: ”

if [ -e $PIDFILE ]; then
echo “ALREADY STARTED”
return 1
fi

# start supervisord with options from sysconfig (stuff like -c)
$SUPERVISORD $OPTIONS

# show initial startup status
$SUPERVISORCTL $OPTIONS status

# only create the subsyslock if we created the PIDFILE
[ -e $PIDFILE ] && touch $LOCKFILE
}

stop() {
echo -n “Stopping supervisord: ”
$SUPERVISORCTL $OPTIONS shutdown
if [ -n “$WAIT_FOR_SUBPROCESSES” ]; then
echo “Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit”
for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do
if [ ! -e $PIDFILE ] ; then
echo “Supervisord exited as expected in under $total_sleep seconds”
break
else
if [[ $sleep -eq “last” ]] ; then
echo “Supervisord still working on shutting down. We’ve waited roughly 60 seconds, we’ll let it do its thing from here”
return 1
else
sleep $sleep
total_sleep=$(( $total_sleep + $sleep ))
fi

fi
done
fi

# always remove the subsys. We might have waited a while, but just remove it at this point.
rm -f $LOCKFILE
}

restart() {
stop
start
}

case “$1″ in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart|force-reload)
restart
RETVAL=$?
;;
reload)
$SUPERVISORCTL $OPTIONS reload
RETVAL=$?
;;
condrestart)
[ -f $LOCKFILE ] && restart
RETVAL=$?
;;
status)
$SUPERVISORCTL $OPTIONS status
if running ; then
RETVAL=0
else
RETVAL=1
fi
;;
*)
echo $”Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}”
exit 1
esac

exit $RETVAL

——————————————————————

保存完毕之后,可以执行以下命令修改文件权限:

chmod 777 /etc/init.d/supervisord

/etc/init.d/supervisord start

这样,supervisor就启动了。

linux centos7 redis3.0.7稳定版源码安装设置远程登陆限制

1.wget http://download.redis.io/releases/redis-3.0.7.tar.gz
tar -zxvf redis3.0.7
make -j2 && make PREFIX=/home/redis install(指定的安装路径)

mkdir -p /home/redis/etc
cp redis.conf /home/redis/etc/
mkdir /etc/redis
ln -s /home/redis/etc/redis.conf /etc/redis/6379.conf
cp /home/source/redis-3.0.7/utils/redis_init_script /etc/init.d/redis
vi /etc/init.d/redis

在第二行加
#chkconfig: 2345 80 90

保存后执行,开机启动就可以用了:
chkconfig –add redis
chkconfig redis on
mkdir /home/server_home/redis/logs -p
mkdir /home/server_home/redis/home -p

# 增加 redis 验证权限流程参考我的redis远程密码设置

这样,远程redis免登陆就可以避免了

linux centos7 源码安装mysql5.6的版本

1. 先安装依赖包
yum install gcc gcc-c++ wget net-tools -y
yum install libaio* perl-Module-Install.noarch -y 安装mysql,这两个依赖包要安装的

mkdir -p /data/source 放下载下来的源码

2.下载 wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
glibc 是c语言包的意思

3.这一版mysql不需要cmake再make和make install编译源代码安装,直接安装即可
以绝对路径创建文件夹(此步可省略)
mkdir创建文件夹,稍后用来存放要安装的mysql
-m : 对新建目录设置存取权限
-p : 此时若路径中的某些目录尚不存在,系统将自动建立好那些尚不存在的目录mkdir -m777 -p /data/mysql

groupadd mysql
useradd -r -g mysql mysql -d /home/mysql

新建组mysql加入系统,为mysql服务添加组和用户,建立用户和组为了安全起见,不让mysql服务操作本身用到的文件以外的文件,所以最好新建linux用户安装mysql,增加mysql这个用户,作为系统账号,同时添加到mysql组理,主目录是/usr/local/mysqluseradd命令用来建立用户帐号和创建用户的起始目录,该命令使用权限是终极用户。新建用户密码为空
-g : 指定用户所属的起始群组。
-d : 指定用户登入时的启始目录。
-s : 指定用户登入后所使用的shell。-s /sbin/nologin 是不让登录shell
-g后第一个mysql是组名,第二个mysql是新建的用户名,新建用户信息可在/etc/passwd文件中查到

4. 修改属主和分组 chown -R mysql:mysql /home/mysql

5. /home/mysql/scripts/mysql_install_db –user=mysql –basedir=/home/mysql –datadir=/home/mysql/data
如果报错,一般都是依赖没装好,检测缺少哪个依赖包

6.cd /data/mysql/support-files
复制mysql服务启动配置文件到/etc/下并重命名为my.cnf,/etc/my.cnf如存在则输入y和回车覆盖
配置文件,如果没有的话,mysql所有的参数将会是默认值
cp my-default.cnf /etc/my.cnf

7.将mysql加入到可控制启动的服务的文件夹内,并命名mysql,即service可控制的服务名,至此可用service mysql start控制启动mysql
/etc/init.d 是/etc/rc.d/init.d的链接,在/etc/init.d添加一个文件会同步在/etc/rc.d/init.d下添加一个相同文件
cp mysql.server /etc/init.d/mysql

8.修改自启动调用的路径。其实若mysql的安装目录是/usr/local/mysql,则可省略此步
vim编辑器,是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面
进入后按键盘i进行编辑,修改如下俩值
basedir=/data/mysql
datadir=/data/mysql/data
编辑后按esc键输入:wq按回车保存。:q!是不保存退出
vim /etc/init.d/mysql

9.让mysql服务加入到开机启动指令管理的服务列表中
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接
–add : 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。服务脚本必须存放在/etc/ini.d/目录下
chkconfig –add mysql开机自启动mysql服务
on : 针对的服务有等级限制,具体查询chkconfig详细
chkconfig mysql on

10.原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:
# ln -s /home/mysql/bin/mysql /usr/bin

11.启用mysql,或者命令systemctl start mysql
service mysql start

设置mysql的root用户密码,此处设成123456,此root用户与linux不是一个
mysqladmin -u root password ‘123456’

登陆mysql,用刚才设置的密码mysql -u root -p