Jimmygao 发布的文章

新装的机子执行一下,请酌情使用,出问题后果自负。

优化设置

This script is only for 64bit Operating System ! 64位系统专用,老高有修改

#!/bin/bash
#author suzezhi
#this script is only for CentOS 6
#check the OS

platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "this script is only for 64bit Operating System !"
exit 1
fi
echo "the platform is ok"
version=`lsb_release -r |awk '{print substr($2,1,1)}'`
if [ $version != 6 ];then
echo "this script is only for CentOS 6 !"
exit 1
fi
cat << EOF
+---------------------------------------+
|   your system is CentOS 6 x86_64      |
|      start optimizing.......          |
+---------------------------------------
EOF

#make the 163.com as the default yum repo

#rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
#rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

yum install iotop lsof wget ntpdate crontabs -y

#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo

#add the third-party repo
#add the epel
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

#add the rpmforge
rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#update the system and set the ntp
yum clean all
yum -y update glibc\*
yum -y update yum\* rpm\* python\*
yum -y update
yum -y install ntp
echo "* 4 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >> /var/spool/cron/root
service crond restart

#set the file limit
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
*           soft   nofile       65535
*           hard   nofile       65535
EOF

#set the control-alt-delete to guard against the miSUSE
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

#disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#set ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
service sshd restart

#tune kernel parametres
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
EOF
/sbin/sysctl -p

#define the backspace button can erase the last character typed
#echo 'stty erase ^H' >> /etc/profile
#echo "syntax on" >> /root/.vimrc

#stop some crontab
mkdir /etc/cron.daily.bak
mv /etc/cron.daily/makewhatis.cron /etc/cron.daily.bak
mv /etc/cron.daily/mlocate.cron /etc/cron.daily.bak
chkconfig bluetooth off
chkconfig cups off
chkconfig ip6tables off
chkconfig iptables off
chkconfig fcoe off
chkconfig iscsi off
chkconfig iscsid off
chkconfig lldpad off
chkconfig nfslock off
chkconfig nfs off
chkconfig rpcbind off
chkconfig rpcgssd off
chkconfig rpcidmapd off
#disable the ipv6
cat > /etc/modprobe.d/ipv6.conf << EOFI
alias net-pf-10 off
options ipv6 disable=1
EOFI
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
cat << EOF
+-------------------------------------------------+
|               optimizer is done                 |
|   it's recommond to restart this server !       |
+-------------------------------------------------+
EOF

cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

对脚本的内容做一下说明:

  1. 先对系统进行判断,如果是Cent OS 64位,就继续运行。
  2. 先将系统的安装源设置为网易的(网易的安装源算是国内比较稳定的)
  3. 安装epel的源和rpmforge的源,利用第三方的源来让yum安装起来更方便
  4. 更新软件
  5. 设置为每天凌晨四点进行时间同步(跟国家授时中心的服务器进行时间同步)
  6. 将系统同时打开的文件个数增大
  7. 将ctrl alt delete键进行屏蔽,防止误操作的时候服务器重启
  8. 关闭selinux
  9. 禁用GSSAPI来认证,也禁用DNS反向解析,加快SSH登陆速度
  10. 优化一些内核参数
  11. 调整删除字符的按键为backspace(某些系统默认是delete)
  12. 打开vim的语法高亮
  13. 取消生成whatis数据库和locate数据库
  14. 关闭没用的服务
  15. 关闭IPv6

安全设置

#!/bin/bash

echo "#####################################"
echo "#####Centos Sytem Security Shell#####"
echo "#####################################"

time=`date  "+%Y-%m-%d"`

#1#######Lock Useless Users#########
for i in adm lp sync shutdown halt news uucp operator games gopher ftp
do
usermod -L $i
done

#2######Close Useless Services########
for i in nfs postfix ypbind portmap smb netfs lpd snmpd named squid xinetd apmd autofs cups isdn nfslock pcmcia sendmail xinetd
do
chkconfig --level 2345 $i off
done

#3#####Directory And File Limit#######
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow
# chattr -i /etc/passwd /etc/shadow /etc/group /etc/gshadow

chmod -R 700 /etc/rc.d/init.d/*
chmod 644 /var/log/wtmp /var/run/utmp

#4#####Clean System Banner###########
cp /etc/issue /etc/issue.$time
cp /etc/issue.net /etc/issue.net.$time
echo "" > /etc/issue
echo "" > /etc/issue.net

#5####Alter login.defs###############
cp /etc/login.defs /etc/login.defs.$time
egrep -v "^#|^$" /etc/login.defs|grep PASS_MIN_LEN
if [ $? = 0 ] ;then
egrep -v "^#|^$" /etc/login.defs|awk '/PASS_MIN_LEN/{print "PASS_MIN_LEN 12";next};{print}' >/etc/login.defs.tmp
mv -f /etc/login.defs.tmp /etc/login.defs
else
echo "PASS_MIN_LEN 12" >>/etc/login.defs
fi
egrep -v "^#|^$" /etc/login.defs|grep PASS_MAX_DAYS
if [ $? = 0 ] ;then
egrep -v "^#|^$" /etc/login.defs|awk '/PASS_MAX_DAYS/{print "PASS_MAX_DAYS 90";next};{print}' >/etc/login.defs.tmp
mv -f /etc/login.defs.tmp /etc/login.defs
else
echo "PASS_MAX_DAYS 90" >>/etc/login.defs
fi

#6####Alter profile###############
cp /etc/profile /etc/profile.$time
egrep -v "^#|^$" /etc/profile|grep TMOUT
if [ $? = 0 ] ;then
egrep -v "^#|^$" /etc/profile|awk '/TMOUT/{print "TMOUT=300;export TMOUT";next};{print}' >/etc/profile.tmp
mv -f /etc/profile.tmp /etc/profile
else
echo "TMOUT=300;export TMOUT" >>/etc/profile
fi

#7####Alter inittab###############
cp /etc/inittab /etc/inittab.bak$time
egrep -v "^#|^$" /etc/inittab|grep ca::ctrlaltdel
if [ $? = 0 ] ;then
egrep -v "^#|^$" /etc/inittab|awk '/^ca::ctrlaltdel/ {sub($1,"#"$1,$0);next};{print}' >/etc/inittab.tmp
mv -f /etc/inittab.tmp /etc/inittab
else
echo -e "#ca::ctrlaltdel:/sbin/shutdown\t-t3\t-r\tnow" >>/etc/inittab
fi

#8####Alter syslog###############
cp /etc/syslog.conf /etc/syslog.conf.$time
egrep -v "^#|^$" /etc/syslog.conf|egrep "\*\.err"
if [ $? != 0 ] ;then
echo "*.err        /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "\*\.info"
if [ $? != 0 ] ;then
echo "*.info        /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "\*\.emerg"
if [ $? != 0 ] ;then
echo "*.emerg        /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "local7\.\*"
if [ $? != 0 ] ;then
echo "local7.*        /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "kern\.debug"
if [ $? != 0 ] ;then
echo "kern.debug       /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "kern\.warning"
if [ $? != 0 ] ;then
echo "kern.warning       /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "authpriv\.none"
if [ $? != 0 ] ;then
echo "authpriv.none       /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "mail\.none"
if [ $? != 0 ] ;then
echo "mail.none       /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "daemon\.notice"
if [ $? != 0 ] ;then
echo "daemon.notice        /var/adm/messages" >>/etc/syslog.conf
fi
egrep -v "^#|^$" /etc/syslog.conf|egrep "cron\.\*"
if [ $? != 0 ] ;then
echo "cron.*      /var/log/cron" >>/etc/syslog.conf
fi
/etc/rc.d/init.d/syslog restart

#9####Alter host.conf###############
cp /etc/host.conf /etc/host.conf.$time
echo -e "order\tbind,hosts\nmulti\ton\nnospoof\ton" >/etc/host.conf

#10####Alter limits.conf###############
cp /etc/security/limits.conf /etc/security/limits.conf.$time
egrep -v "^#|^$" /etc/security/limits.conf|egrep "\*[[:space:]]soft[[:space:]]core[[:space:]]0"
if [ $? != 0 ] ;then
echo -e "*\tsoft\tcore\t0" >> /etc/security/limits.conf
fi
egrep -v "^#|^$" /etc/security/limits.conf|egrep "\*[[:space:]]hard[[:space:]]core[[:space:]]0"
if [ $? != 0 ] ;then
echo -e "*\thard\tcore\t0" >> /etc/security/limits.conf
fi
egrep -v "^#|^$" /etc/security/limits.conf|egrep "\*[[:space:]]hard[[:space:]]rss[[:space:]]5000"
if [ $? != 0 ] ;then
echo -e "*\thard\trss\t5000" >> /etc/security/limits.conf
fi
egrep -v "^#|^$" /etc/security/limits.conf|egrep "\*[[:space:]]hard[[:space:]]nproc[[:space:]]20"
if [ $? != 0 ] ;then
echo -e "*\thard\tnproc\t20" >> /etc/security/limits.conf
fi

#11####Alter pam_login###############
cp /etc/pam.d/login /etc/pam.d/login.$time
egrep -v "^#|^$" /etc/pam.d/login|egrep "^session[[:space:]]required[[:space:]]/lib/security/pam_limits.so"
if [ $? != 0 ] ;then
echo -e "session\trequired\t/lib/security/pam_limits.so" >> /etc/pam.d/login
fi

#12####Alter sshd_config###############
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.$time
egrep -v "^#|^$" /etc/ssh/sshd_config|egrep "^Protocol[[:space:]]2"
if [ $? != 0 ] ;then
echo -e "Protocol 2" >>/etc/ssh/sshd_config
fi

#13####Alter sysctl.conf###############
cp /etc/sysctl.conf /etc/sysctl.conf.$time
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.tcp_max_syn_backlog"
if [ $? != 0 ] ;then
echo "net.ipv4.tcp_max_syn_backlog=4096" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf_all.rp_filter"
if [ $? != 0 ] ;then
echo "net.ipv4.conf_all.rp_filter=1" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.tcp_syncookies"
if [ $? != 0 ] ;then
echo "net.ipv4.tcp_syncookies=1" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf\.all\.send_redirects"
if [ $? != 0 ] ;then
echo "net.ipv4.conf.all.send_redirects=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf\.all\.accept_redirects"
if [ $? != 0 ] ;then
echo "net.ipv4.conf.all.accept_redirects=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.ip_forward"
if [ $? != 0 ] ;then
echo "net.ipv4.ip_forward=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf\.all\.accept_source_route"
if [ $? != 0 ] ;then
echo "net.ipv4.conf.all.accept_source_route=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf\.default\.accept_redirects"
if [ $? != 0 ] ;then
echo "net.ipv4.conf.default.accept_redirects=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.conf\.default\.send_redirects"
if [ $? != 0 ] ;then
echo "net.ipv4.conf.default.send_redirects=0" >>/etc/sysctl.conf
fi
egrep -v "^#|^$" /etc/sysctl.conf|egrep "net\.ipv4\.icmp_echo_ignore_broadcasts"
if [ $? != 0 ] ;then
echo "net.ipv4.icmp_echo_ignore_broadcasts=1" >>/etc/sysctl.conf
fi
sysctl -p /etc/sysctl.conf
chown root:root /etc/sysctl.conf
chmod 600 /etc/sysctl.conf

脚本转自:

http://www.linuxde.net/2011/12/5756.html http://www.linuxpad.cn/linux/centos-sytem-security-shell.html

国外的主题对中文支持不好很不和谐,需要修改的地方很多,用起来也很麻烦,但是古语有云:

Bitch is bitchy!Taylor is Swift!

下面就记录一下更新主题前后的工作。动手能力强的可以参考这里自己写一个子主题,也可以完美解决!

  • 预先备份原来主题文件夹,起个名字叫old_theme。留个后悔药 备份路径wp-content/themes/sparkling ,sparkling就是老高的主题
  • 升级主题,原主题被覆盖
  • 老高修改过的文件包括(old_theme文件夹里按时间排序就能找到)
    1. header.php ---|---|seo优化
    2. functions.php ---|--常用函数
    3. single.php ---|---| 解决手机底部链接打不开的样式问题
    4. content.php ---|---|-主页显示文章字数限制,参考这篇文章
    5. footer.php --------统计代码已解决
  • 在新的主题文件夹中找到对应文件并修改 子主题以后讲

工作中需要微博的商业API,记录一下 不了解的TX先去看说说明 http://open.weibo.com/wiki/商业数据API

商业数据API:包括数据分析、舆情监测、获取全量粉丝三大特性,同时还有实时数据推送、历史数据检索、监测粉丝变化趋势、活跃&活动粉丝分析等多项功能,协助和指引企业开展社会化营销,让真实的用户数据变为企业的决策。

申请试用 申请试用的邮箱为

[email protected] 给这个地址发邮件说明意图即可 这一步挺麻烦的,需要提供很多企业信息,需要注意的是:商业API只提供商业用途,所以如果你的APP的服务对象不是企业,请绕道。 然后填写两张申请单,分别为 订阅服务申请单、REST接口申请单-测试版。 一个是订阅微博,粉丝登上数据用的,另一个是标准API,可以使用搜索等高级接口!

价格

套餐 搜索、订阅返回条数 使用期限 套餐使用费 套餐外使用费
A 200万条 1月 6,000元 3元/千条
B 2000万条 1年 60,000元 2.5元/千条
C 1亿条 1年 250,000元 1.6元/千条
D 5亿条 1年 800,000元 0.6元/千条

确定试用时间

试用时间一般两周,请充分利用好这宝贵的时间吧!

测试

REST接口很简单,和普通接口一样直接调用。就是订阅接口比较麻烦,当你生成订阅列表后,他会把满足你需要的数据放进一个类似队列的东西,然后你需要不断从这个队列中取出你需要的信息,而且这个获取过程需要HTTP长链接。。。。。。说起来很复杂,其实做起来更复杂 :mad: ! 下面就来讲讲订阅接口,先看看这两个文档:

看完这两个接口就基本知道了订阅到底是干啥用的。

订阅开启

首先,开启了订阅接口服务以后,你会有推送时间,还有推送IP等很多需要设置的东西,当然完成了这些基本设置后,就可以开始配置订阅规则了,订阅规则基于以下两个条件:

  1. 订阅用户

  2. 订阅关键字 从subscribe/update_subscribe这个接口的示例来看,订阅有以下特点:

    • 订阅规则即刻生效
    • 规则可以添加,修改
    • 规则可以随时查询
    • 每次修改量很有限(用户:50个;关键词:20个)

使用订阅

添加与删除一样 需要说明的是:

$params['subid'] = '***';  //你的订阅ID 新浪提供
$params['source'] = '***';  //你的APPid


session_start();

include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];

//获取所有关注,默认一次50个,可以自己写循环
$friends = $c->friends_by_id($uid);
$subscribe = '';
foreach( $friends['users'] as $value )
{
	$subscribe .= $value['id'].',';
}
$subscribe =  trim($subscribe,',');

//准备数据
$params = array();
$params['subid'] = '***';
$params['source'] = '***';
$params['add_uids'] = $subscribe;
//$params['del_uids'] = $subscribe;

$rs = $c->oauth->get('http://c.api.weibo.com/subscribe/update_subscribe.json', $params);
print_r($rs);


if($rs['result']){
	echo "订阅用户成功";
}

获取订阅信息

可以访问网址:

http://open.weibo.com/apps/yourappid/payservice/subscribe

也可以使用API读取

oauth->get('http://c.api.weibo.com/subscribe/update_subscribe.json', $params);
print_r($rs);

Ø ⊙ ╰_╯ ● § ㄥ ★ ☆ ▽ ° ◎ 〤ι〤 ≡ ˋ_ˊ ← → ↖ ↗ ↘ ↙ ↑ ↓ ﹏ ε ☭ ξ ็ ä └(^o^)┘ ﹌○﹋ ^o^

ส็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้ ส็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้ ส็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้ ส็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็ ส้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้้ ส็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็็> ฌูููููู

本文适合新手老手,有不对的地方欢迎指正! 如果有什么问题或者建议,请务必留言, :-)

老高很高兴与大家交流! 同时欢迎关注我的微博

写在前面:搜索引擎是个很神奇的东西,脾气捉摸不定,动不动就学个新算法让你不得安居乐业。许多新手都会觉得想让搜索引擎收录真难啊! 那么对于刚刚建成的新站和收录有问题的旧站,如何才能让搜索引擎顺利的收录你的网站呢? 花点时间看完本文,我相信你对SEO的理解一定会更加透彻。 预先约定几个说法(不分大小写)

  • wordpress ->wp
  • Search Engine Optimization->SEO
  • Uniform Resource Locator ->URL 下面老高就针对wordpress的SEO优化讲讲具体的步骤:

浅谈URL的优化

说到SEO,最先想到的应该是URL了,什么!你不知道URL是啥? 8-O 简单地说,URL就是

统一资源定位符(Uniform Resource Locator,缩写为URL)是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址。互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理它。https://blog.phpgao.com/ 就是一个URL,访客和搜索引擎就是靠他找到你的资源。URL的优化其实很简单,做到以下几点就OK!

伪静态

美化你的URL显示格式,即做好伪静态,打个例子,本文的URL默认为www.phpgao.com/?p=***|的形式,\*|为文章的数字ID,但是实际上他显示为www.phpgao.com/seo.html,如果这两个URL都指向同一篇文章,哪一个更能勾起你的欲望呢?同样的,搜索引擎也会试着理解你的URL ,然后抓取你的内容,分以适当的权重 ---|- 那么如何设置成这样的形式呢?首先需要了解伪静态、404错误、linux、win主机等概念,后面章节有讲。

网站地图

URL格式确定以后下面就要把你的URL告诉搜索引擎了,所以你需要一个**网站地图**,他可以告诉搜索引擎网站是什么结构,哪些页面比较重要,哪些可以忽略,有利于搜索引擎抓取。

robots.txt

robots的作用是控制爬虫的抓取范围,举个比方,你可以禁止爬虫收录你的wp-admin文件夹下所有文件,这样可以保证安全性。你需要明确的是,爬虫来到你的网站,就像吃货进了一个自助餐馆一样,只要能吃的他都不放过,如果你放任不管,那么可能他会把你和你太太盘子里的饭菜都会吃掉。所以你必须告诉他:“爬虫兄啊,你不能吃这个,这个是桌子!”。简单的介绍一下用法:

  • 请将robots.txt放到网站的根目录下,你可以参考一下www.taobao.com/robots.txt(百度中枪)
  • 编码无所谓,一般不会出现中文
  • 第一行写User-agent: * 意思只针对所有搜索引擎的爬虫
  • 紧接着Disallow: /wp-* 意思是不允许看wp-开头的所有文件
  • 你可以写很多个Disallow规则,记得首字母要大写
  • 你还可以在文件中指明sitemap路径 Sitemap: https://blog.phpgao.com/sitemap
  • robots.txt不要过于复杂 robots文件真的很重要,老高之前写过一个爬网页的程序放到了某个二级目录下,并在首页加了链接,但是忘记了屏蔽搜索引擎,导致谷歌收录了本站的9000多个垃圾内容页 :-( ,悲剧啊!话说百度还是很谨慎的,就是不收录!

提交入口--来我家玩吧!

提供几个提交网站的入口,此步是通知搜索引擎来收录你的网站

  1. 百度网站登录入口
  2. Google网站登录入口
  3. 360网站登录入口
  4. Bing网站登录入口
  5. 搜狗网站收录提交入口 这步最简单了!不要偷懒哦! 8-)

站长工具--查询收录的利器

站长工具就站长管理网站收录,转化率等信息的瑞士军刀

  1. 百度站长工具
  2. 谷歌站长工具
  3. seo工具

老高要在这里赞一下百度的抓取诊断功能,通过使用发现百度没有更新我站的DNS信息,于是换了DNSPOD解析,立马解决问题!

由于网络错误导致抓取失败

网站统计分析

网站统计,顾名思义就是统计网站浏览量,分析受众群体。原理是通过放脚本或者图片链接在你的网站里,每次访问的时候都会将此次请求信息发送给统计服务器,然后就可以在统计后台查看到实时访问信息了。与基于访问日志分析的办法不同,这种统计方法不是很准确,但是对付一般需求足够了!使用此插件必须在wp主题文件footer.php加入系统提供给你的统计代码,老高的经验是把统计代码加入一个

包裹的div中,因为可能一不小心,这条统计代码会带出来一个很丑的图片,影响网站美观!所以最终的代码会是这样的,其中script标签才是真正的统计代码,div的工作是让他不要影响网站的呈现。

主流工具如下:

  • 百度统计
  • 谷歌分析
  • 老高推荐百度统计(基于速度考虑)

直到这一步!你的网站才算是真正投入到了互联网这个茫茫大海之中,你要意识到的是搜索引擎只是索引到了互联网信息的一小部分而已,而这个数字已足够庞大,所以逛光光完成到这一步是不够的,下面就是提高篇!

##优化访问速度

###选择主机系统

这里你有两种选择

  • windows+iis
  • linux+apache

一般来说,linux主机是比win贵的,原因是:

更安全,windows面对黑客只能说雅蠛蝶了 更快,不是网速快,而是同等硬件下linux+apache跑PHP性能更好 更强大,其实最主要还是说伪静态的问题,linux天然支持,IIS就悲剧了,先哭着 :-( ,后面说原因 更稳定,linux一般很少死机的,windows我只能说呵呵了 总之,钱多就上linux;苦逼的话win还是能接受的。

###服务器地址

内地?香港?美国?韩国?到底搬哪儿好呢?

这还用问?当然是离得越近,速度越快了!下面简单说说利弊吧:

内地主机速度一定不会太慢,但是需要网站已备案 香港主机速度不一定,我在XX购买的空间电信打不开,网通倒是挺快。。。很郁闷 美国主机速度可能不如香港,快也快不到哪儿去 韩国速度和以上两地差不多

再此还是要罗嗦几句:

一般购买一年的空间,商家都会承诺一个月内退款的,没有声明的话请勿使用,或者提出试用要求,并且使用超级PING工具测速 一定要看看空间服务商的备案号,很多都是假的

★★网站开始运行后一定要定时备份,不论是空间还是数据库!★★

###GZIP–压缩html

GZIP一看就知道是压缩用的,能开就开吧。一般的panel都是提供这个功能的,如果没有也不影响。

查询是否压缩请使用Gzip检测工具检测,至于压缩率嘛,自己看吧!

是否压缩 是 压缩类型 gzip 原始文件大小 89103 字节 压缩后文件大小 13896 字节

###伪静态

伪静态就是为了让url美观一些,本文的网址为默认为

https://blog.phpgao.com/?p=238

但我修改固定连接格式是之变成了

https://blog.phpgao.com/seo.html

看到这个URL你会不会觉得根目录下就有一个seo.html吧?

其实不然,当你的浏览器访问了此网址https://blog.phpgao.com/seo.html,服务器在解析这个URL时会参考你的伪静态规则,隐性的将url变为https://blog.phpgao.com/index.php/seo.html,然后剩下工作就交给index.php,他会帮你找到对应的文章显示给读者!

####IIS

IIS悲剧的伪静态ISAPI_Rewrite分版本不说,不同版本伪静态的写法还有差别。。。设置参考我的文章

IIS下wordpress伪静态的配置

####APACHE

这里风景一片大好,htaccess教IIS学做人

####404补救

404也可以伪静态,但是设置很麻烦,一般不推荐。 原理就是当访问一个不存在的地址,服务器会找一个叫类似404.php的文件,在这个文件中分析URL并导航至相应页面去。

有兴趣自己实现的请百度之!

###静态内容加速

原理就是CDN服务商将你的网页文件缓存之,然后你的服务器就不用提供诸如jpg,css,js等不常更新的文件,减小了自己服务器的压力,好用的加速主要有七牛。

##网站结构优化

一个网站可能有很多栏目,栏目下会有许多文章,就像大树上结的果子。文章之间可能也会有相互关联,这种关系叫做叫内链。相对的,文章或栏目等指向他人网站的链接就叫外链。 每篇文章有自己的标题、关键字、描述和内容。

以上几个概念就是组成一个网站的基本结构。

###文章的结构

标题、关键字、摘要和内容分别对应英文中的title,keywords,desciption、content。 这些词语在几乎每一个网页中都有体现,搜索引擎就是根据以上几个属性来了解一个网站的所有内容。 其重要性按大小排序:content>title>desciption>keywords 所以在优化策略中,如果你的内容和别人的一样(比如使用火车头采集),那么如果你的标题设置的好,或者描述提取的好,那么你的排名就相对靠前一点。 (未完待续)

参考:

http://www.chinaz.com/web/2011/0727/201918.shtml

http://www.xmlas.com/robots-google-txt.html

一般wordpress主题都会在head标签之间使用wp_head()函数,因为这是个很重要的头部函数,很多功能插件都会用到它。 不过,如果你的wordpress主题用到了该函数,则会在head头部显示许多冗余的代码。

如果希望移除wordpress头部的多余代码,可以使用以下方法解决: 在主题文件夹下的functions.php文件中加入以下代码:

remove_action( 'wp_head', 'wp_generator' );//WordPress版本信息。
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );//最后文章的url
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );//最前文章的url
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//上下文章的url
remove_action( 'wp_head', 'feed_links_extra', 3 );//去除评论feed
remove_action( 'wp_head', 'feed_links', 2 );//去除文章的feed
remove_action( 'wp_head', 'rsd_link' );//针对Blog的离线编辑器开放接口所使用
remove_action( 'wp_head', 'wlwmanifest_link' );//如上
remove_action( 'wp_head', 'index_rel_link' );//当前页面的url
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );//短地址

来源: http://www.daxiawp.com/remove-wordpress-head-code.html

博客用的国外的主题,对中文处理不是太好。尤其是首页会把文章的全部内容都输出,使首页变得很长,对于我这种爱贴代码的程序猿来说,这个病,必须治!

解决办法有三种:

  1. more标签
  2. 自己写方法截取文字
  3. the_excerpt()

more标签

以下引用sumile_ting 的话:

这种方法是在每次写文章时在文章中插入一个More标签。

添加More标签的方法:

写文章时,在需要作为摘要的地方点击编辑器中的More标签,或在HTML编辑状态加加入,或者直接按Alt+Shift+T,3种方法任选其一。

这种方法使用起来太麻烦,要求每一篇文章都得手动加,一不小心可能就忘记了。还不如修改主题模板来的方便快捷。

自造方法

自己写方法必须对function.php和content.php做改写,先找到


the_content()方法返回了文章的内容,处理一下就可以限制字数了,具体方法请自查。

但是对于我还是不合适,因为此时文章还没有被插件渲染,文章内的代码会被直接以纯文本的形式展示,很不和谐。 所以这个方案,pass

the_excerpt()

此方法是wordpress显示文章摘要的API,效果与the_content() 一样,只是这个函数对中文支持不好,需要处理一下

以下是步骤:

方法2的the_content()修改为the_excerpt() 在function下加入以下代码

function custom_excerpt_length( $length ) {
    return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

给readmore加个链接,同样在functions.php中添加:

function new_excerpt_more( $more ) {
    return '阅读全文';
}
add_filter('excerpt_more', 'new_excerpt_more');

完美解决

参考:

http://sumile.blog.hexun.com/63924812_d.html

http://www.gemshe.com/fashion/suneyeglass/wordpress%E7%9A%84%E6%96%87%E7%AB%A0%E5%BD%A2%E5%BC%8Fget_post_format/

http://www.seanstudio.com/archives/2558

http://www.daxiawp.com/change-to-excerpt.html