HackToday Walk Blog


  • Home

  • Tags

  • Archives

  • Search

ubuntu新版本14.10安装问题,及解决方案汇总

Posted on 2014-10-26

Ubuntu今年的最后一个版本14.10如期的发布了,新的版本汇集了一些新的特性,
Ubuntu Desktop: 除了Unity,Xorg 及一些软件包更新的集成外,最有看点的还是
Ubuntu Developer Tools Center,

Ubuntu官方将其定位: 为开发者提供Ubuntu上的快速开发环境,这里的开发环境并不局限在ubuntu应用,涵盖其他的比如Android,Go,
Web 等。 因为是新引入的特性,所以目前支持Android开发环境的快速搭建,期待用户的反馈再开发后续更多的支持。虽然是Ubuntu14.10
引入的官方支持,但是为了更好的LTS优先原则,可以通过PPA添加的方式来在Ubuntu 14.04中使用这个特性, 具体可以参见这篇blog
http://blog.didrocks.fr/post/Ubuntu-loves-Developers

笔者使用Virtualbox安装Ubuntu 14.10出现了如下几个问题,网上也有一些人遇到了,给出解决方法,汇总如下,

  1. 安装界面一片混乱,色彩模糊,

http://askubuntu.com/questions/541006/ubuntu-14-10-does-not-install-in-virtualbox

解决方法:

1
Hit Ctrl+Alt+F1 (you will see the shell) and then Ctrl+Alt+F7. You are good to proceed with the installation.
  1. Virtualbox Guest Additions 不能正确编译安装

这是因为老的版本的问题,下载最新的dkms,然后重新启动机器即可,

http://www.ubuntugeek.com/fix-for-ubuntu-14-10-screen-resolution-issue-on-virtualbox.html

解决方法:

1
  sudo apt-get install virtualbox-guest-dkms

参考资料:

Ubuntu 14.10 Release Notes
https://wiki.ubuntu.com/UtopicUnicorn/ReleaseNotes#Official_flavours

Docker技术-cgroup

Posted on 2014-10-13

Docker容器采用了linux内核中的cgroup技术来实现container的资源的隔离和控制。
关于cgroup我们需要了解的它的知识点:

  1. 基本概念

cgroup涉及到几个概念如下:
cgroup:以某种方式,将某些任务和subsystem进行关联
subsystem:基于cgroup的资源管理器,可以看作一种资源(比如CPU,Memory, I/O等),实现对一个cgroup的task的调度和控制
hierarchy:对crgoups和subsystems以某种形式进行的组织,cgroup组织形式是树结构,subsystem会关联连接到hierarchy上。

上面的概念有点抽象,看个简单的例子就明白了,比如redhat官网的一个图:

上面的就是一个1个hierarchy,有两个subsystem(cpu和memory) attach上,其中的cgroups以tree的结构组织。

既然cgroup是什么以及结构弄清楚了,那到底cgroup如何实现的资源的管理控制,cgroup是和task(乜可以看作是系统中的进程)关联的,这样不同的cgroup在subsystem中的资源控制下就能够分配到不同的份额或者设定不同的限制,同时可以统计监控资源的消耗情况。

  1. 如何使用Cgroups
    如果我们最原始的使用cgroup,不借助高级的docker方式,那么具体步骤如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
To start a new job that is to be contained within a cgroup, using
the "cpuset" cgroup subsystem, the steps are something like:

1) mount -t tmpfs cgroup_root /sys/fs/cgroup
2) mkdir /sys/fs/cgroup/cpuset
3) mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset
4) Create the new cgroup by doing mkdir's and write's (or echo's) in
the /sys/fs/cgroup virtual file system.
5) Start a task that will be the "founding father" of the new job.
6) Attach that task to the new cgroup by writing its PID to the
/sys/fs/cgroup/cpuset/tasks file for that cgroup.
7) fork, exec or clone the job tasks from this founding father task.

For example, the following sequence of commands will setup a cgroup
named "Charlie", containing just CPUs 2 and 3, and Memory Node 1,
and then start a subshell 'sh' in that cgroup:

mount -t tmpfs cgroup_root /sys/fs/cgroup
mkdir /sys/fs/cgroup/cpuset
mount -t cgroup cpuset -ocpuset /sys/fs/cgroup/cpuset
cd /sys/fs/cgroup/cpuset
mkdir Charlie
cd Charlie
/bin/echo 2-3 > cpuset.cpus
/bin/echo 1 > cpuset.mems
/bin/echo $$ > tasks
sh
# The subshell 'sh' is now running in cgroup Charlie
# The next line should display '/Charlie'
cat /proc/self/cgroup
  1. 使用Docker,减少冗长细节的cgroup使用
    虽然Docker给我们带来了极大的方便,但是我们还是需要了解一些cgroup的操作使用,这样才更加有信心处理各种问题,

3.1 使用cgroup-bin
一般操作系统没有默认安装这个工具,我们自己需要安装,提供了很多有趣而且很棒的命令:

1
2
3
4
5
lssubsys 列出包含subsystem的hierarchy
lscgroup 列出所有的cgroup

/proc/cgroups 列出了系统中cgroup的subsystem
/proc//cgroup 列出进程所属的cgroup,包含了cgroup的

3.2 Docker的结合
比如我们docker run了一个container,

先找出contianer的ID,

1
docker ps --no-trunc

根据上面找出的ID,找到对应的tasks ID,

1
cat  /sys/fs/cgroup/cpu/docker//tasks

查看对应的cgroup

1
cat /proc//cgroup
  1. 不同操作系统暴露的subsystem的区别
    ubuntu就和redhat有所不同,redhat有10中cgroup subsystem
    如果默认安装的ubuntu,比如14.04, 你会发现,没有net_cls和net_prio,具体如何搞出来,参看这个帖子

参考资料:

  1. Linux Kernel Doc about Cgroups
    https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt
  2. Cannot find network subsystem in cgroup on Ubuntu 12.04 LTS
    http://serverfault.com/questions/485919/cannot-find-network-subsystem-in-cgroup-on-ubuntu-12-04-lts
  3. Redhat cgroup
    https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/ch01.html
  4. Docker cgroup
    https://docs.docker.com/articles/runmetrics/#control-groups

如何登录到Docker的container中

Posted on 2014-10-04

使用Docker部署container后,我们总有类似的需求:登录到container中进行一些操作。

常见的方式

  1. 有ssh方式,特点是不需要特别的root权限,但是container需要安装sshd
  2. 使用nsenter来从container获得一个shell实现登录
  3. 使用nsinit

本文主要介绍nsenter的使用

nsenter使用非常方便,但是有的操作系统发行版本util-linux包比较老,所以没有包含这个nsenter,
那么你需要自己编译和安装,对于hacker们来说,源码编译安装不是小case嘛,走起!

注明: 下面的命令运行以Ubuntu 14.04为例

1)下载源码

1
2
git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git util-linux
cd util-linux/

2)安装依赖包(这个具体缺少的情况,会在运行 ./autogen.sh的提示,你也可以直接运行3),根据提示来安装对应的依赖包

1
2
3
4
sudo apt-get install libtool
sudo apt-get install automake
sudo apt-get install autopoint
sudo apt-get install libncurses5-dev

3)编译安装

1
2
./autogen.sh 
./configure & make

4)测试安装成功

1
./nsenter -V

5) 将nsenter加入系统环境可执行路径中

1
sudo cp ./nsenter /usr/bin

如何使用nsenter,非常简单,
1) 首先找到container对应的进程ID

1
sudo docker inspect --format "{{ .State.Pid }}"

2) 执行nsenter获得一个shell ,假设1)获得id是4308

1
sudo nsenter  --target 4308 --mount --uts --ipc --net --pid

这样就进入到了container中。
好了,有的人可能会说attach不是也可以吗?为什么用这个nsenter?
个人理解两个功能是完全不一样的,attach相当于找到原始的会话shell,而原始的shell可能是一个循环程序或者web server直接在shell下运行的,这样你如果执行Ctril-C,直接导致对应的container stop,所以这不是我们期望发生的。
nsenter则是新创建的一个shell,这样就是新的会话。

参考资料:

  1. Why there is no nsenter in util-linux?
    http://askubuntu.com/questions/439056/why-there-is-no-nsenter-in-util-linux
  2. 在 UOS 上体验 CoreOS
    https://www.ustack.com/blog/running-coreos-on-uos/
  3. Attaching to a container with Docker 0.9 and libcontainer
    http://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/
  4. Docker shell/provisioning without SSH
    https://github.com/mitchellh/vagrant/issues/4179

Docker的操作学习-attach,detach,volume data

Posted on 2014-10-01

Docker作为另一类虚拟化技术-容器方案,已经吸引了越来越多的开发和关注,docker在各大操作系统厂商-Ubuntu,Redhat等都提供了很好的集成,更给力的是docker的官方的文档写的非常清晰易懂。下文以ubuntu 14.04为例,对docker的CLI进行简单的学习,

Docker Hub上提供了大量image可以进行测试练习,所以我们随便选一个

  1. 启动进入一个shell
1
sudo docker run  -i -t  --name web training/webapp /bin/bash
  1. Detach 上面的container
1
CTRL-p CTRL-q
  1. Attach上面的container
1
sudo docker attach web
  1. 以background方式运行 container
1
sudo docker run  -d -P  training/webapp python app.py

其中 -P 是将container的ports暴露给对于主机所有的interface,比如上面的启动的container,
我们可以通过sudo docker ps 查看运行的端口,

1
f3ca5cd8c307        training/webapp:latest     /bin/bash     24 minutes ago      Up 22 minutes   0.0.0.0:49154->5000/tcp   web

这样,如果Host有多块网卡,每个网卡有不同的ip,所有的ip:49154 都可以访问这个web app了。

  1. Docker的数据管理及使用

    docker的Data volumes功能可以:

    • 对container进行方便的volume创建,
    • 对host的目录进行快捷的mount到container
    • 不同container之间通过volume进行数据共享
    • 对data volume进行方便的backup,restore和migrate

例如:

  • 创建一个名字是dbdata的container包含dbdata的volume
1
sudo docker run -i -t -v /dbdata --name dbdata training/postgres /bin/bash
  • 对上面的container的/dbdata挂载到新的container db1上
1
sudo docker run -i -t  --volumes-from dbdata --name db1 training/postgres /bin/bash

backup 和 restore:

  1. 首先启动一个新的container来对dbdata的data volume数据打包备份到host的当前目录下
1
sudo docker run --volumes-from dbdata -v $(pwd):/backup training/postgres tar cvf /backup/backup.tar /dbdata
  1. 创建一个用来restore上面数据的container,名字是dbdata2
1
sudo docker run -v /dbdata --name dbdata2  training/postgres /bin/bash
  1. un-tar到新创建的container的data volume中
1
sudo docker run --volumes-from dbdata2 -v $(pwd):/backup training/postgres tar xvf /backup/backup.tar

很明显,上面的几个步骤通过Host来实现了文件的转存。

作为外延,读者可以参考更多的资料:

  1. Docker的技术预览
    http://www.infoq.com/cn/articles/docker-core-technology-preview
  2. Docker的源码分析
    http://www.infoq.com/cn/articles/docker-source-code-analysis-part1?utm_campaign=infoq_content&utm_source=infoq&utm_medium=feed&utm_term=global&utm_reader=feedly
  3. Docker的CLI
    http://docs.docker.com/reference/commandline/cli/
    http://docs.docker.com/userguide/dockervolumes/
    http://docs.docker.com/userguide/usingdocker/

Enable 3D acceleration cause Virtual Box guest crash

Posted on 2014-09-30

最近遇到的一个问题,每次只要在guest的配置中enable 3D acceleration,就会出现, VirtualBox Manager Stop working,
导致guest无法正常的图形界面启动,google 了一下,有个帖子讨论是Virtulbox 的最近版本回归的一个Bug,

讨论link如下:

https://forums.virtualbox.org/viewtopic.php?f=6&t=62633
https://www.virtualbox.org/ticket/12772

Openstack keystone的policy设计处理分析

Posted on 2014-07-31

keystone设计的policy role based access controls(RBAC)非常有意思,最终暴露给用户的是一种简单的可编辑的语义规则。
举个例子如下:

1
2
3
4
5
6
{   
...
"admin_required": "role:admin or is_admin:1",
"identity:get_user": "rule:admin_required",
...
}

keystone的policy使用的driver默认配置是如下:
driver = keystone.policy.backends.sql.Policy

每个相应的API的访问请求都会经过相应RBAC的检测,
在keystone中的API是通过filterprotected,protected的decorator来作用的,
调用入口:

1
2
3
self.policy_api.enforce(creds,
action,
authorization.flatten(policy_dict))

具体的时序图以get_user为例如下:

Enforcer这个类其中的enforce方法逻辑如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 ....
self.load_rules()

# Allow the rule to be a Check tree
if isinstance(rule, BaseCheck):
result = rule(target, creds, self)
elif not self.rules:
# No rules to reference means we're going to fail closed
result = False
else:
try:
# Evaluate the rule
result = self.rules[rule](target, creds, self)
except KeyError:
LOG.debug(_("Rule [%s] doesn't exist") % rule)
# If the rule doesn't exist, fail closed
result = False
...

其中各种rule的就是各种规则来实现不同角色的权限管理,
具体的rule类层次结构如下:

下次我们将对其policy语言的解析处理进行详细的分析

chef-server的架构简介

Posted on 2014-07-15

chef采用的C/S架构,主要包括chef-server还有chef-client

  1. 总体架构
    chef-server,控制节点,主要存储相关的cookbook,配置节点的策略,描述注册节点的元数据
    安装节点,使用chef-client来向server节点获取配置信息,包括recipe,templates,file等,完成节点的配置工作。

chef为了更好的支持并发,分布式环境,在11.X版本前段的server采用了erlang开发,也就是上面的Erchef 部分。

各个组件的部分,

(1)Nginx,前端的http请求的负载均衡
(2) WebUI,提供更友好的GUI方式使用chef
(3)Erchef,Chef-server的API实现层
(4) Bookshelf, 是一种对象存储。按照文件的checksum存储,所以同样的文件只会存取一次,这样不同版本的cookbook的重复的文件不会存储多次。具体可以查看 /var/opt/chef-server/bookshelf/data/bookshelf/目录下的文件
(5) Message Queues,采用的rabbitmq,
chef-expander 从消息队列里取出消息,处理成对应的格式,提供给chef-solr做索引
chef-solr对apache solr包装,提供可以进行索引和查找的REST API
索引数据存储的位置是 /var/opt/chef-server/chef-solr/data
(6) PostgreSQL, chef-server的数据存储,
查看具体数据库表结构:
export PATH=$PATH:/opt/chef-server/embedded/bin/
psql -U opscode_chef
\l 列出所有数据库
\dt 列出当前连接数据库的表
数据库相关的存储数据, /var/opt/chef-server/postgresql/data

  1. 核心API server的组件架构

Erchef具体架构细节:

根据上面的结构图,可以看到对象的更新时chef_objects和bookshelf的完成
chef_authn:实现了chef相关的http请求的签名和验证协议
chef-index:和apache solr的交互,对象的增删改,和rabbimq交互。

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
%% @doc Delete an object from Solr.
%% @end
%%
%% Note that the guard for this function recapitulates the chef_indexable_type()
%% custom type. This is done out of an abundance of caution and
%% paranoia :)
delete(VHost, Type, ID, DatabaseName, SolrUrl) when Type =:= 'client';
Type =:= 'data_bag';
Type =:= 'data_bag_item';
Type =:= 'environment';
Type =:= 'node';
Type =:= 'role' ->
PackagedData = package_for_delete(Type, ID, DatabaseName, SolrUrl),
publish(VHost, PackagedData, routing_key(ID)).

chef_objects:定义了chef内部的一些对象,environment,node,data bag等
chef_db: chef-server的数据库层逻辑,
chef_wm: 包含了erchef的rest api实现和路由定义

  1. Chef-client执行流程:

    A “chef-client run” is the term used to describe a series of steps that are taken by the chef-client when it is configuring a node. The following diagram shows the various stages that occur during the chef-client run, and then the list below the diagram describes in greater detail each of those stages.

参考资料:

  1. chef-server.rb Optional Settings http://docs.opscode.com/config_rb_chef_server_optional_settings.html
  2. Monitor http://docs.opscode.com/server_monitor.html
  3. chef-client http://docs.opscode.com/chef_client.html
  4. Erchef https://github.com/opscode/erchef
  5. chef-server http://docs.opscode.com/server_components.html

Redhat 7的kernel新看点

Posted on 2014-06-22

Redhat 2014的summit关于RHEL 的roadmap中,关于kernel的部分,讲了很有意思的一些新特点,
主要包括,架构,内存管理,调度和锁机制的改进,性能提升,debug,还有container….

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
RHEL 7 Kernel Architecture Support
1) Architectures
Support the following 64 bits Architectures
X86_64, Power, and s390
with 32bit user space compatibility support
2) Theoretical Limits on X86_64
–Logical CPU – maximum 5120 logical CPUs
–Memory – maximum 64T


Resource Management Improvements
1)Linux Containers (LXC) – Fully Supported in RHEL 7 RC
2)Control Groups: cpu, cpuset, memory, block io, network, network prio
3)Libcgroup has been deprecated, replacing with systemd's scope and slices
4)Namespaces: mount, UTS, IPC, PID, network
5)User Namespace – in later releases
6)SELinux – security protection for containers
7)SystemD – provide unit file to help setup container’s resources
8)Docker CLI

其实container才是我感兴趣的地方,Docker公司最近发布的1.0可谓在业界风生水起,

    What is Docker's architecture?

    Docker uses a client-server architecture. The Docker client talks to the
Docker daemon, which does the heavy lifting of building, running, and
distributing your Docker containers. Both the Docker client and the daemon can run on the same system, or you can connect a Docker client to a remote Docker
daemon. The Docker client and service communicate via sockets or through a
RESTful API.


    The Docker daemon

    As shown in the diagram above, the Docker daemon runs on a host machine. The
user does not directly interact with the daemon, but instead through the Docker
client.


    The Docker client

    The Docker client, in the form of the docker binary, is the primary user
interface to Docker. It accepts commands from the user and communicates back and
forth with a Docker daemon.

    Inside Docker

    To understand Docker's internals, you need to know about three components:
        - Docker images.
        - Docker registries.
        - Docker containers.

参考资料:

  1. http://docs.docker.com/introduction/understanding-docker/#what-is-dockers-architecture
  2. Redhat 2014 Summit

ubuntu 14.04虚拟机无法挂载vboxsf的问题

Posted on 2014-06-17

环境:virtualbox 4.3.10
虚拟机: ubuntu 14.04

问题:

今天要挂载一个share folders 突然发现无法挂载,然后查了一下,原来是bad link导致的问题,修复后,正常使用。

1
2
3
4
5
6
7
test@test-VirtualBox1404:~$ sudo mount -t vboxsf vm-mount /mnt/share
mount: wrong fs type, bad option, bad superblock on vm-mount,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount. helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so

解决方法:

1
sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

参考帖子:

http://askubuntu.com/questions/458286/getting-an-error-wrong-fs-type-bad-option-bad-superblock-on-ubuntushared

Local Area Connection doesn't have a valid IP configuration

Posted on 2014-05-31

今天办公突然发现windows7网络链接有问题了,检查网线,网线接口都没有问题,那肯定出在操作系统这边,

网络诊断提示:

1
Local Area Connection doesn't have a valid IP configuration

莫名其妙,google一下,发现有些干货,真的很给力,解决了问题,这样你就不用苦恼的重装系统了(最笨最郁闷的方法)

帖子内容如下:(黑体字体部分就是解决方法)

Hey everyone, I’ve had this problem for days with my home router on windows7. Try these two commands and restart. it worked for me.
Link of Website is below also.

  1. Reset WinSock and TCP/IP Stack
    Open a Command Prompt as administrator:
    Reset WINSOCK entries:
    netsh winsock reset catalog
    
    Reset TCP/IP stack:
    netsh int ip reset reset.log
    
    Reboot the machine
    (you can run both commands first, I tend to put multiple commands in notepad and then copy and paste into the command window).
    I can also confirm that this is the only solution that worked for me. I entered the second command and rebooted computer. Upon restart my internet functionality was returned.
    You can find the original article on the microsoft website at: http://support.microsoft.com/kb/299357

感谢分享,世界才变得更美好。

参考资料:

http://social.technet.microsoft.com/Forums/windows/en-US/55aa9f24-e8ea-4743-8e04-120decfb6122/local-area-connection-doesnt-have-a-valid-ip-configuration-w7?forum=w7itpronetworking

1…101112…26

Kai Qiang Wu

This is a place for thinking and writing

253 posts
32 tags
GitHub
© 2020 Kai Qiang Wu
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4
Visitor Total Visit