我过去常常使用 Python,Java 和 Javascript 编写代码。每一个这样的语言/平台都需要一个运行时的安装。最近,我开始涉及 Go(或是 golang 如果你喜欢)平台。看起来 Go 是静态连接的。因此我尝试编译一个简单的 web 服务输出 Hello World 并且运行在 scratch 容器中。下面是这个 Hello World web 服务的代码:
package main
import (
"fmt"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello World from Go in minimal Docker container")
}
func main() {
http.HandleFunc("/", helloHandler)
fmt.Println("Started, serving at 8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
明显地,我不能在 scratch 容器中编译我的 web 服务,因为容器中没有 Go 编译器。正如我在 Mac 上工作,我也无法编译 Linux 的二进制文件一样(实际上,是可以在不同的平台上交叉编译 Go 的源码的,但这会在另外一篇博客中介绍)。
FROM google/golang
RUN CGO_ENABLED=0 go get -a -ldflags '-s' github.com/adriaandejonge/helloworld
RUN cp /gopath/src/github.com/adriaandejonge/helloworld/Dockerfile /gopath
CMD docker build -t adejonge/helloworld gopath
W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/raring-backports/multiverse/binary-i386/Packages 404 Not Found [IP: 91.189.91.13 80]
W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/raring/main/binary-amd64/Packages 404 Not Found
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/raring-security/universe/binary-i386/Packages 404 Not Found [IP: 91.189.88.149 80]
E: Some index files failed to download. They have been ignored, or old ones used instead
W: GPG error: http://repo.mate-desktop.org saucy InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 68980A0EA10B4DE8
W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://extras.ubuntu.com precise Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key
' ' /usr/lib/libreoffice/program/soffice
deb gnome-shell
deb Docky
deb google-chrome-stable
deb soffice
deb gnome-settings-daemon
deb gnome-terminal-server
SUSE( Software and System Entwicklung,即软件和系统开发。其中‘entwicklung‘是德语,意为开发)Linux 是由 Novell 公司在 Linux 内核基础上建立的操作系统。SUSE Linux 有两个发行分支。其中之一名为 openSUSE,这是一款自由而且免费的操作系统 (free as in speech as well as free as in wine)。该系统由开源社区开发维护,支持一些最新版本的应用软件,其最新的稳定版本为 13.2。
另外一个分支是 SUSE Linux 企业版。该分支是一个为企业及商业化产品设计的 Linux 发行版,包含了大量的企业应用以及适用于商业产品生产环境的特性。其最新的稳定版本为 12。
# zypper help install
install (in) [options] {capability | rpm_file_uri}
Install packages with specified capabilities or RPM files with specified
location. A capability is NAME[.ARCH][OP], where OP is one
of <, <=, =, >=, >.
Command options:
--from Select packages from the specified repository.
-r, --repo Load only the specified repository.
-t, --type Type of package (package, patch, pattern, product, srcpackage).
Default: package.
-n, --name Select packages by plain name, not by capability.
-C, --capability Select packages by capability.
-f, --force Install even if the item is already installed (reinstall),
downgraded or changes vendor or architecture.
--oldpackage Allow to replace a newer item with an older one.
Handy if you are doing a rollback. Unlike --force
it will not enforce a reinstall.
--replacefiles Install the packages even if they replace files from other,
already installed, packages. Default is to treat file conflicts
as an error. --download-as-needed disables the fileconflict check.
......
安装之前搜索一个安转包(以 gnome-desktop 为例 )
# zypper se gnome-desktop
Retrieving repository 'openSUSE-13.2-Debug' metadata ............................................................[done]
Building repository 'openSUSE-13.2-Debug' cache .................................................................[done]
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ......................................................... [done]
Building repository 'openSUSE-13.2-Non-Oss' cache ...............................................................[done]
Retrieving repository 'openSUSE-13.2-Oss' metadata ..............................................................[done]
Building repository 'openSUSE-13.2-Oss' cache ...................................................................[done]
Retrieving repository 'openSUSE-13.2-Update' metadata ...........................................................[done]
Building repository 'openSUSE-13.2-Update' cache ................................................................[done]
Retrieving repository 'openSUSE-13.2-Update-Non-Oss' metadata ...................................................[done]
Building repository 'openSUSE-13.2-Update-Non-Oss' cache ........................................................[done]
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+---------------------------------------+-----------------------------------------------------------+-----------
| gnome-desktop2-lang | Languages for package gnome-desktop2 | package
| gnome-desktop2 | The GNOME Desktop API Library | package
| libgnome-desktop-2-17 | The GNOME Desktop API Library | package
| libgnome-desktop-3-10 | The GNOME Desktop API Library | package
| libgnome-desktop-3-devel | The GNOME Desktop API Library -- Development Files | package
| libgnome-desktop-3_0-common | The GNOME Desktop API Library -- Common data files | package
| gnome-desktop-debugsource | Debug sources for package gnome-desktop | package
| gnome-desktop-sharp2-debugsource | Debug sources for package gnome-desktop-sharp2 | package
| gnome-desktop2-debugsource | Debug sources for package gnome-desktop2 | package
| libgnome-desktop-2-17-debuginfo | Debug information for package libgnome-desktop-2-17 | package
| libgnome-desktop-3-10-debuginfo | Debug information for package libgnome-desktop-3-10 | package
| libgnome-desktop-3_0-common-debuginfo | Debug information for package libgnome-desktop-3_0-common | package
| libgnome-desktop-2-17-debuginfo-32bit | Debug information for package libgnome-desktop-2-17 | package
| libgnome-desktop-3-10-debuginfo-32bit | Debug information for package libgnome-desktop-3-10 | package
| gnome-desktop-sharp2 | Mono bindings for libgnome-desktop | package
| libgnome-desktop-2-devel | The GNOME Desktop API Library -- Development Files | packag
| gnome-desktop-lang | Languages for package gnome-desktop | package
| libgnome-desktop-2-17-32bit | The GNOME Desktop API Library | package
| libgnome-desktop-3-10-32bit | The GNOME Desktop API Library | package
| gnome-desktop | The GNOME Desktop API Library | srcpackage
获取一个模式包的信息(以 lamp_server 为例)。
# zypper info -t pattern lamp_server
Loading repository data...
Reading installed packages...
Information for pattern lamp_server:
------------------------------------
Repository: openSUSE-13.2-Update
Name: lamp_server
Version: 20141007-5.1
Arch: x86_64
Vendor: openSUSE
Installed: No
Visible to User: Yes
Summary: Web and LAMP Server
Description:
Software to set up a Web server that is able to serve static, dynamic, and interactive content (like a Web shop). This includes Apache HTTP Server, the database management system MySQL,
and scripting languages such as PHP, Python, Ruby on Rails, or Perl.
Contents:
S | Name | Type | Dependency
--+-------------------------------+---------+-----------
| apache2-mod_php5 | package |
| php5-iconv | package |
i | patterns-openSUSE-base | package |
i | apache2-prefork | package |
| php5-dom | package |
| php5-mysql | package |
i | apache2 | package |
| apache2-example-pages | package |
| mariadb | package |
| apache2-mod_perl | package |
| php5-ctype | package |
| apache2-doc | package |
| yast2-http-server | package |
| patterns-openSUSE-lamp_server | package |
使用 ‘zypper refresh’ or ‘zypper ref’ 来刷新 zypper 软件库。
# zypper refresh
或者
# zypper ref
Repository 'openSUSE-13.2-0' is up to date.
Repository 'openSUSE-13.2-Debug' is up to date.
Repository 'openSUSE-13.2-Non-Oss' is up to date.
Repository 'openSUSE-13.2-Oss' is up to date.
Repository 'openSUSE-13.2-Update' is up to date.
Repository 'openSUSE-13.2-Update-Non-Oss' is up to date.
All repositories have been refreshed.
刷新一个指定的软件库(以 ‘repo-non-oss’ 为例 )。
# zypper refresh repo-non-oss
Repository 'openSUSE-13.2-Non-Oss' is up to date.
Specified repositories have been refreshed.
强制更新一个软件库(以 ‘repo-non-oss’ 为例 )。
# zypper ref -f repo-non-oss
Forcing raw metadata refresh
Retrieving repository 'openSUSE-13.2-Non-Oss' metadata ............................................................[done]
Forcing building of repository cache
Building repository 'openSUSE-13.2-Non-Oss' cache ............................................................[done]
Specified repositories have been refreshed.
# zypper mr -rk -p 85 repo-non-oss
Repository 'repo-non-oss' priority has been left unchanged (85)
Nothing to change for repository 'repo-non-oss'.
对所有的软件库关闭 rpm 文件缓存。
# zypper mr -Ka
RPM files caching has been disabled for repository 'openSUSE-13.2-0'.
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
对所有的软件库开启 rpm 文件缓存。
# zypper mr -ka
RPM files caching has been enabled for repository 'openSUSE-13.2-0'.
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.
关闭远程库的 rpm 文件缓存
# zypper mr -Kt
RPM files caching has been disabled for repository 'repo-debug'.
RPM files caching has been disabled for repository 'repo-debug-update'.
RPM files caching has been disabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been disabled for repository 'repo-non-oss'.
RPM files caching has been disabled for repository 'repo-oss'.
RPM files caching has been disabled for repository 'repo-source'.
RPM files caching has been disabled for repository 'repo-update'.
RPM files caching has been disabled for repository 'repo-update-non-oss'.
开启远程软件库的 rpm 文件缓存。
# zypper mr -kt
RPM files caching has been enabled for repository 'repo-debug'.
RPM files caching has been enabled for repository 'repo-debug-update'.
RPM files caching has been enabled for repository 'repo-debug-update-non-oss'.
RPM files caching has been enabled for repository 'repo-non-oss'.
RPM files caching has been enabled for repository 'repo-oss'.
RPM files caching has been enabled for repository 'repo-source'.
RPM files caching has been enabled for repository 'repo-update'.
RPM files caching has been enabled for repository 'repo-update-non-oss'.
对于那些满怀抱负而又缺乏知识的生灵,有一个叫Evo/Lution Live ISO的ISO镜像格式安装器可以拯救他们。即便它貌似像发行版一样启动,但它其实除了辅助安装Arch Linux准系统之外啥都不干。Evo/Lution是一个项目,它旨在通过提供Arch的简单安装方式来为Arch的增加更多的用户基数,就像为那些用户提供全面帮助和文档的社区一样。在这样一个组合中,Evo是Live CD(不可安装),而Lution是个安装器本身。项目创立者看到了Arch及其衍生发行版的开发者和用户之间的巨大鸿沟,而想要在所有参与者之间构筑一个身份平等的社区。
When the Apache HTTP Server manages its child processes, it needs a way to wake up processes that are listening for new connections. To do this, it sends a simple HTTP request back to itself. This request will appear in the access_log file with the remote address set to the loop-back interface (typically 127.0.0.1 or ::1 if IPv6 is configured). If you log the User-Agent string (as in the combined log format), you will see the server signature followed by “(internal dummy connection)” on non-SSL servers. During certain periods you may see up to one such request for each httpd child process.
static apr_status_t dummy_connection(ap_pod_t *pod)
{
//...有省略
/* Create the request string. We include a User-Agent so that
* adminstrators can track down the cause of the odd-looking
* requests in their logs.
*/
srequest = apr_pstrcat(p, "OPTIONS * HTTP/1.0rnUser-Agent: ",
ap_get_server_banner(),
" (internal dummy connection)rnrn", NULL);
//...有省略
}
这些进程在处理完当前请求以后(OPTIONS请求), 就会发现, oh, 主进程让我退出。
static void child_main(int child_num_arg)
{
//...有省略
while (!die_now && !shutdown_pending) {
//...有省略
//1. listen
//2. accept
//3. process request
/* Check the pod and the generation number after processing a
* connection so that we'll go away if a graceful restart occurred
* while we were processing the connection or we are the lucky
* idle server process that gets to die.
*/
if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
die_now = 1;
}
//...有省略
}
//...有省略
}
linux-xa3t:~ # zypper help remove
remove (rm) [options] ...
Remove packages with specified capabilities.
A capability is NAME[.ARCH][OP], where OP is one of <, <=, =, >=, >.
Command options:
-r, --repo Load only the specified repository.
-t, --type Type of package (package, patch, pattern, product).
Default: package.
-n, --name Select packages by plain name, not by capability.
-C, --capability Select packages by capability.
--debug-solver Create solver test case for debugging.
-R, --no-force-resolution Do not force the solver to find solution,let it ask.
--force-resolution Force the solver to find a solution (even an aggressive one).
-u, --clean-deps Automatically remove unneeded dependencies.
-U, --no-clean-deps No automatic removal of unneeded dependencies.
-D, --dry-run Test the removal, do not actually remove.
例子3:打开zypper shell/会话
linux-xa3t:~ # zypper sh
zypper>
或
linux-xa3t:~ # zypper shell
zypper>
例子4:列出已定义的仓库
linux-xa3t:~ # zypper repos
或
linux-xa3t:~ # zypper lr
4.1) 以表格的形式列出仓库的URI
4.2) 以优先级列出仓库
linux-xa3t:~ # zypper lr -p
例子5:刷新仓库
linux-xa3t:~ # zypper ref
Repository 'openSUSE-13.1-Non-Oss' is up to date.
Repository 'openSUSE-13.1-Oss' is up to date.
Repository 'openSUSE-13.1-Update' is up to date.
Repository 'openSUSE-13.1-Update-Non-Oss' is up to date.
All repositories have been refreshed.
Valence(之前称作Firefox工具适配器)让开发者可以通过连接Firefox开发者工具到其他主流浏览器的引擎来跨浏览器和设备进行开发和调试。Valence 还将Mozilla打造的用来调试FirefoxOS和Firefox for Android的工具延展到了包括Android上的Chrome以及 iOS上的Safari在内的其他主流移动浏览器中。这些工具目前包括查看器、调试器、控制台和样式编辑器。
siteA-public-IP siteB-public-IP: PSK "pre-shared-key"
## in case of multiple sites ##
siteA-public-IP siteC-public-IP: PSK "corresponding-pre-shared-key"
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Oct 16 08:59:45 openstack sshd[1214]: fatal: No supported key exchange algorithms [preauth]
Google Pagespeed在作为一个Nginx的模块在研发这么久之后仍是beta版本,着实有点尴尬,不过也证明了该项目是成功的,最起码它仍在迭代,实际上在使用中,我们也碰到一些非模块本身的问题,譬如当它基于反向代理时模板的寻址,图片的URL重写…为此不得不对其做一些配置让它不是看起来多了一个协议,而是真正的能对页面的细节进行优化,最大限度的压榨服务器的的性能提高用户访问速度..
[...]
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name server.unixmen.local;
[...]
location ~ .php$ {
try_files $uri =404; ---------> Add this line
fastcgi_split_path_info ^(.+.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
这里面,我增加了额外一行‘try_files $uri =404;’用于避免0day漏洞。
保存文件并退出。
测试 nginx 配置
使用下面的命令测试nginx配置是否存在语法错误:
sudo nginx -t
典型输出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
通常情况下,这该归结于项目管理问题,管理员必须对横跨多个代码库的那些代码负责。基于这个观点,整改第一步就是提取核心的业务关键功能,并将之拆分为独立的服务(这也是本文的一个重点部分),也就是所谓的面向服务架构,在整个系统内遵循“separation of concern”原则。每个服务只负责一个业务逻辑,同时也要明确更高等级的业务功能。举个形象的例子也就是,这个系统可能是个搜索引擎、一个销售系统等。