灵魂机器

终有一天机器也有灵魂


  • 首页

  • 分类

  • 归档

  • 标签

给CentOS安装UEK内核

发表于 2014-01-31   |   分类于 DevOps   |  

最近给CentOS 6.5 安装了docker,不过每次运行都会报警:

WARNING: You are running linux kernel version 2.6.32-431.3.1.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.8.0.

给CentOS 升级内核,有三种途径,一种是yum官方源里有更新的版本,一种途径是自己编译,另一种途径是使用别人编译好了的内核。

CentOS yum源是出了名的更新慢,目前没有 3.8版内核,第二种途径很麻烦,工作量很大,因此本文用第三种。例如UEK,Oracle提供了一个公共的yum源,http://public-yum.oracle.com/

##添加yum源

UEK的稳定版还是 2.6 内核的,beta版的内核是3.8的,所以我们使用beta源

sudo wget http://public-yum.oracle.com/beta/public-yum-ol6-beta.repo -P /etc/yum.repos.d

由于UEK3还没有加入到正式版本中,还目前属于测试阶段,,需要手工将 enabled=0改为 enabled=1

sudo vim /etc/yum.repos.d/public-yum-ol6-beta.repo

##添加GPG key

sudo wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

##更新yum源

sudo yum update

##列出所有的kernel

yum list kernel*
阅读全文 »

Spark开发环境的配置

发表于 2014-01-30   |   分类于 Spark   |  

软件版本:Spark 0.9

配置Spark开发环境,其实分为三个层次,一种是针对运维人员,把Spark安装部署到集群;一种是针对普通开发者,引入Spark的jar包,调用Spark提供的接口,编写分布式程序,写好后编译成jar,就可以提交到Spark集群去运行了;第三种是针对Spark开发者,为了给Spark贡献代码,需要git clone Spark的代码,然后导入IDE,为Spark开发代码。

##1 部署Spark集群
这种是运维人员在生产环境下,搭建起一个Spark集群。

###(可选)创建新用户 Spark
一般我倾向于把需要启动daemon进程,对外提供服务的程序,即服务器类的程序,安装在单独的用户下面。这样可以做到隔离,运维方面,安全性也提高了。

创建一个新的group,

$ sudo groupadd spark

创建一个新的用户,并加入group,

$ sudo useradd -g spark spark

给新用户设置密码,

$ sudo passwd spark

在每台机器上创建 spark 新用户,并配置好SSH无密码,参考我的另一篇博客,SSH无密码登录的配置

假设有三台机器,hostname分别是 master, worker01, worker02。

###1.1 下载 Spark 预编译好的二进制包
如果你需要用到HDFS,则要针对Hadoop 1.x 和Hadoop 2.x 选择不同的版本。这里我选择 Hadoop 2.x 版。

spark@master $ wget http://d3kbcqa49mib13.cloudfront.net/spark-0.9.0-incubating-bin-hadoop1.tgz
spark@master $ tar zxf spark-0.9.0-incubating-bin-hadoop1.tgz -C ~/local/opt

###1.2 将tgz压缩包scp到所有机器,解压到相同的路径

spark@master $ scp spark-0.9.0-incubating-bin-hadoop1.tgz spark@worker01:~
spark@master $ ssh worker01
spark@worker01 $ tar zxf spark-0.9.0-incubating-bin-hadoop1.tgz -C ~/local/opt
spark@worker01 $ exit
spark@master $ scp spark-0.9.0-incubating-bin-hadoop1.tgz spark@worker02:~
spark@master $ ssh worker02
spark@worker02 $ tar zxf spark-0.9.0-incubating-bin-hadoop1.tgz -C ~/local/opt
spark@worker02 $ exit

###1.3 修改配置文件
Spark 0.9 以后,配置文件简单多了,只有一个必须要配置,就是 conf/slaves 这个文件。在这个文件里添加slave的hostname。

###1.4 拷贝配置文件到所有slave

spark@master $ spark@master $ scp ./conf/slaves spark@worker01:~/local/opt/spark-0.9.0-incubating-bin-hadoop1/conf
spark@master $ spark@master $ scp ./conf/slaves spark@worker02:~/local/opt/spark-0.9.0-incubating-bin-hadoop1/conf

###1.5 启动Spark集群

spark@master $ ./sbin/start-all.sh
阅读全文 »

我的Ansible playbook

发表于 2014-01-29   |   分类于 DevOps   |  

前提,安装好Ansible,参考我的上一篇博客,Ansible 快速入门

---
- hosts: all
  sudo: True
  remote_user: work
  vars:
    ant_version: 1.9.3
    maven_version: 3.1.1
    scala_version: 2.10.3
    sbt_version: 0.12.4

  tasks:
  ########## for CentOS and RedHat ##########
    - name: Install the libselinux-python package  # because ansible needs it
      yum: name=libselinux-python state=installed
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: Disable SELinux in conf file
      selinux: state=disabled
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: update YUM repositories
      shell: 'yum -y update'
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: Install OpenJDK
      yum: name=java-1.7.0-openjdk-devel state=present
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: Set JAVA_HOME environment variable
      lineinfile: dest='/etc/profile' regexp='^#?\s*export JAVA_HOME=(.*)$' line='export JAVA_HOME=/usr/lib/jvm/java' state=present
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: install the 'Development tools' package group
      yum: name="@Development tools" state=present
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

    - name: upgrade all packages
      shell: 'yum -y upgrade'
      when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'


  ########## for Ubuntu and Debian ##########
    - name: Run "apt-get update" to update the source list
      apt: update_cache=yes
      when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

    - name: Install OpenJDK
      apt: pkg=openjdk-7-jdk state=present
      when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

    - name: Set JAVA_HOME environment variable
      lineinfile: dest='/etc/profile' regexp='^#?\s*export JAVA_HOME=(.*)$' line='export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64' state=present
      when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

    - name: Install build-essential
      apt: pkg=build-essential state=present
      when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

    - name: Update all packages to the latest version
      apt: upgrade=dist
      when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'


  ########## Common opreations for all OS ##########
    # Create local directories
    - file: path=~/local/bin state=directory
      sudo: no
    - file: path=~/local/sbin state=directory
      sudo: no
    - file: path=~/local/src state=directory
      sudo: no
    - file: path=~/local/opt state=directory
      sudo: no
    - file: path=~/local/var state=directory
      sudo: no
    - lineinfile: dest=~/.bashrc regexp='^#?\s*export PATH=(.*)/local/bin(.*)$' line="export PATH=$PATH:$HOME/local/bin" state=present
      sudo: no
    - lineinfile: dest=~/.bashrc regexp='^#?\s*export PATH=(.*)/local/sbin(.*)$' line="export PATH=$PATH:$HOME/local/sbin" state=present
      sudo: no

    - name: Set CLASSPATH and PATH environment variables
      lineinfile: $item
      with_items:
        - dest='/etc/profile' regexp='^#?\s*export CLASSPATH=(.*)$' line='export CLASSPATH=.:$JAVA_HOME/lib/*.jar:$JAVA_HOME/jre/lib/*.jar' state=present
        - dest='/etc/profile' regexp='^#?\s*export PATH=(.*)JAVA_HOME(.*)$' line="export PATH=$PATH:$JAVA_HOME/bin" state=present

    ###### Since Ant in yum and apt is too old, download the .tar.bz2 file and install it
    # Install Apache Ant
    - name: Download Apache Ant
      get_url: url=http://mirror.cc.columbia.edu/pub/software/apache//ant/binaries/apache-ant-{{ant_version}}-bin.tar.bz2 dest=/tmp/apache-ant-{{ant_version}}-bin.tar.bz2
    - name: Untar Ant
      shell: chdir=/tmp creates=/opt/apache-ant-{{ant_version}} tar -jxf apache-ant-{{ant_version}}-bin.tar.bz2 -C /opt
    - lineinfile: dest=/etc/profile regexp='^#?\s*export ANT_HOME=(.*)$' line='export ANT_HOME=/opt/apache-ant-{{ant_version}}' state=present
    - lineinfile: dest=/etc/profile regexp='^#?\s*export PATH=(.*)ANT_HOME(.*)$' line="export PATH=$PATH:$ANT_HOME/bin" state=present

    # Install Apache Maven, since there is no Maven package in yum and apt repo
    - name: Download Apache Maven
      get_url: url=http://apache.claz.org/maven/maven-3/3.1.1/binaries/apache-maven-{{maven_version}}-bin.tar.gz dest=/tmp/apache-maven-{{maven_version}}-bin.tar.gz
    - name: Untar Maven
      shell: chdir=/tmp creates=/opt/apache-maven-{{maven_version}} tar -zxf apache-maven-{{maven_version}}-bin.tar.gz -C /opt
    - lineinfile: dest=/etc/profile regexp='^#?\s*export MAVEN_HOME=(.*)$' line='export MAVEN_HOME=/opt/apache-maven-{{maven_version}}' state=present
    - lineinfile: dest=/etc/profile regexp='^#?\s*export PATH=(.*)MAVEN_HOME(.*)$' line="export PATH=$PATH:$MAVEN_HOME/bin" state=present

    # Install the scala compiler, because the scala compiler in yum and apt repo is too old
    - name: Download Scala
      get_url: url=http://www.scala-lang.org/files/archive/scala-{{scala_version}}.tgz dest=/tmp/scala-{{scala_version}}.tgz
    - name: Untar Scala
      shell: chdir=/tmp creates=/opt/scala-{{scala_version}} tar -zxf scala-{{scala_version}}.tgz -C /opt
    - lineinfile: dest=/etc/profile regexp='^#?\s*export SCALA_HOME=(.*)$' line='export SCALA_HOME=/opt/scala-{{scala_version}}' state=present
    - lineinfile: dest=/etc/profile regexp='^#?\s*export PATH=(.*)SCALA_HOME(.*)$' line="export PATH=$PATH:$SCALA_HOME/bin" state=present

    # Install sbt
    - name: Download sbt
      get_url: url=http://repo.scala-sbt.org/scalasbt/sbt-native-packages/org/scala-sbt/sbt//{{sbt_version}}/sbt.tgz dest=/tmp/sbt-{{sbt_version}}.tgz
    - name: Untar sbt
      shell: chdir=/tmp creates=/opt/sbt-{{sbt_version}} tar -zxf sbt-{{sbt_version}}.tgz -C /opt
    - name: Rename sbt directory
      shell: chdir=/opt creates=/opt/sbt-{{sbt_version}} mv sbt/ sbt-{{sbt_version}}/
    - lineinfile: dest=/etc/profile regexp='^#?\s*export SBT_HOME=(.*)$' line='export SBT_HOME=/opt/sbt-{{sbt_version}}' state=present
    - lineinfile: dest=/etc/profile regexp='^#?\s*export PATH=(.*)SBT_HOME(.*)$' line="export PATH=$PATH:$SBT_HOME/bin" state=present

    # Install Go
    - name: Download Go
      get_url: url=https://go.googlecode.com/files/go1.2.linux-amd64.tar.gz dest=/tmp/go1.2.linux-amd64.tar.gz
    - name: Untar Go
      shell: chdir=/tmp creates=/opt/go tar -zxf go1.2.linux-amd64.tar.gz -C /opt
    - lineinfile: dest=/etc/profile regexp='^#?\s*export GOROOT=(.*)$' line='export GOROOT=/opt/go' state=present
    - lineinfile: dest=/etc/profile regexp='^#?\s*export PATH=(.*)GOROOT(.*)$' line="export PATH=$PATH:$GOROOT/bin" state=present

Restore Octopress at a new computer

发表于 2014-01-28   |   分类于 Tools   |  

OS: Ubuntu 12.04 64-bit

##1. Install ruby

###1.1 Install ruby via RVM

$ \curl -sSL https://get.rvm.io | bash -s stable --ruby

###1.2 Integrating RVM with gnome-terminal
/etc/profile, ~/.bash_profile are for login shell, and ~/.bashrc is for interactive shell, and RVM’s path is added to ~/.bash_profile, so you need to set the shell as a login shell.

###1.3 Give it a try
Exit current shell, and open a new shell,

ruby -v

You have successfully installed ruby.

##2. Install Python

$ sudo apt-get install -y python

Because Pygments syntax highlighting needs Python.

##3. Clone your blog to the new machine
First you need to clone the source branch to the local octopress folder.

$ git clone -b source [email protected]:username/username.github.com.git octopress
阅读全文 »

Ansible 快速入门

发表于 2014-01-27   |   分类于 DevOps   |  

Ansible 是一个比Puppet, Chef 更轻量的provisioning 工具,不需要启动daemon进程。这点跟跟pssh差不多,但是比pssh更加强大。

##前提

  • 所使用的remote_user要能够SSH无密码登录到所有机器,配置方法见SSH无密码登录的配置
  • remote_use sudo的时候不需要密码,配置方法如下,

    sudo chmod +w /etc/sudoers
    sudo vim /etc/sudoers
    

    找到 root ALL=(ALL:ALL) ALL,在下面添加一行

    username    ALL=(ALL:ALL) NOPASSWD:ALL
    

    保存退出,然后恢复为只读,

    sudo chmod +w /etc/sudoers 
    

如果忘记了以上两点,运行任何ansible命令的时候,会卡住不动很久。

如果发现在 “GATHERING FACTS”这里卡住,多半是sudo需要密码,试试加上-K选项,例如ansible-playbook -K playbook.yml,参考Running ansible on local Linux desktop hangs on Gathering Facts。

-vvvv表示调试模式,加上后会输出很多中间信息,帮助你调试。

##1. 安装Ansible
只需要在一台机器上安装,其他机器不需要安装任何东西,这就是ansible比puppet, chef方便的地方。

sudo yum install ansible

或者

sudo apt-get install ansible

在/etc/ansible/hosts添加想要操作的机器(这个hosts文件也叫做Inventory),且这些机器都是能SSH无密码登录的,然后测试一下:

ansible all -a "/bin/echo hello"

如果都成功了,说明安装成功。

使用ansible有两种方式:Ad-hoc command 和 playbook。前者用于临时类批量操作,后者用于配置管理,类似与Puppet。

##2. Ad-Hoc Commands
Ad-hoc命令的形式一般如下:

ansible groupname -m module -a arguments
阅读全文 »

/boot 目录空间不足

发表于 2014-01-26   |   分类于 DevOps   |  

今天在服务器上执行 sudo yum -y update的时候报错:

… needs 18MB on the /boot filesystem

1. 列出所有的内核文件

rpm -q kernel
kernel-2.6.32-431.el6.x86_64
kernel-2.6.32-431.3.1.el6.x86_64

发现有多个内核,因此可以删除所有不再使用的内核文件,来释放空间。

##2. 查看当前正在使用的内核

uname -r
2.6.32-431.3.1.el6.x86_64

注意,如果你是刚刚 yum -y update过,需要重启一下,内核才会更新,不重启的话uname -r还是显示的旧的。

##3. 删除没有使用的内核

rpm -e 2.6.32-431.el6.x86_64
rpm -e xxx

将rpm -q kernel显示的内核复制粘贴到xxx位置。

4. 手动删除其他文件

把所有未使用的版本全部删除。

sudo rm -rf /lib/modules/2.6.32-431.el6.x86_64
sudo rm -rf /usr/src/kernels/2.6.32-431.el6.x86_64
sudo rm -rf /usr/src/kernels/2.6.32-431.el6.x86_64.debug
sudo rm /boot/*2.6.32-431*

##5. 删除grub里的条目
上面的步骤做完了后,最后,把grub里未使用的内核删掉,条目序号是从0开始编号的,删除条目后,记得把default设置为正确的序号。

##6. 再执行 yum update

sudo yum -y update

##参考资料
boot目录空间不足

yum update -y,提示/boot 空间不足的解决方法

如何卸载自己编译的内核?【已解决,方法见6L】

Rdesktop 快速入门

发表于 2014-01-25   |   分类于 DevOps   |  

rdesktop是一款Linux下兼容Windows Remote Desktop Protocal(RDP)协议的客户端,可以用它连接开启了3389的windows机器。输入rdesktop可以看到该命令的所有选项,其中最常用的选项如下:

-u: user name
-p: password (- to prompt)
-f: full-screen mode
-g: desktop geometry (WxH)
-x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)

举几个例子,

rdesktop -u feng -p 123456 -xl -f 192.168.1.250

这条命令表示,-xl表示客户端和win机器在同一个局域网,因此可以画质调节到最好,-f表示全屏,这条命令最好在局域网下使用。

rdesktop -u feng -p 123456 -xm -f 192.168.1.250

跟上一条命令相比,把-xl换成了-xm,画质调节到最差

rdesktop -u feng -p 123456 -xm -g 1024x768 192.168.1.250

跟上一条命令相比,将全屏改成了分辨率1024x768

集群时间同步--架设内网NTP服务器

发表于 2014-01-24   |   分类于 DevOps   |  

环境:CentOS 6.5

对于一个Linux集群,集群内的机器保持时间同步是很重要的,不然会出现很多问题。

本文主要描述如何在集群内架设一台NTP服务器,其他机器都与这台服务器保持时间同步。

##1 安装NTP
在所有机器上执行,

$ sudo yum install ntp

###2 调整时区
把所有机器的时区调整为上海时区,即”+8000”时区。

先看一下机器的时区是否是对的,

$ date -R

如果不是”+8000”,则要修改时区,

$ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

###3 (可选)同步BIOS时间
Linux系统上面BIOS时间与linux系统时间是分开的,所以调整了时间之后,还需要使用hwclock才能将修改过的时间写入BIOS中。

在/etc/sysconfig/ntpd中添加一行:

SYNC_HWCLOCK=yes

##4 配置NTP服务器
选择一台能够上网的机器作为NTP服务器,以后这台服务器提供时间同步服务,集群内的其他机器不需要上网去跟公共的NTP服务器同步了。

阅读全文 »

CentOS 6.5 升级内核到 3.10.28

发表于 2014-01-23   |   分类于 DevOps   |  

本文适用于CentOS 6.4, CentOS 6.5,亲测可行,估计也适用于其他Linux发行版。

1. 准备工作

1.1 下载源码包

Linux内核版本有两种:稳定版和开发版 ,Linux内核版本号由3个数字组成:r.x.y

  • r: 主版本号
  • x: 次版本号,偶数表示稳定版本;奇数表示开发中版本。
  • y: 修订版本号 , 表示修改的次数

去 http://www.kernel.org 首页,可以看到有stable, longterm等版本,longterm是比stable更稳定的版本,会长时间更新,因此我选择 3.10.28,

wget  https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.28.tar.xz

###1.2 解压

tar -xf linux-3.10.28.tar.xz

###1.3 更新当前系统

sudo yum update
sudo yum upgrade

###1.4 安装编译内核所需要的软件包

sudo yum groupinstall "Development Tools" # 一口气安装编译时所需的一切工具
sudo yum install ncurses-devel #必须这样才能让 make *config 这个指令正确地执行。
sudo yum install qt-devel #如果你没有 X 环境,这一条可以不用
sudo yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel #创建 CentOS-6 内核时需要它们

##2 配置文件

###2.1 查看当前系统内核

uname -r
2.6.32-358.11.1.el6.x86_64

###2.2 将当前系统的配置文件拷贝到当前目录

cp /boot/config-2.6.32-358.11.1.el6.x86_64 .config

###2.3 使用旧内核配置,并自动接受每个新增选项的默认设置

sh -c 'yes "" | make oldconfig'

make oldconfig会读取当前目录下的.config文件,在.config文件里没有找到的选项则提示用户填写,然后备份.config文件为.config.old,并生成新的.config文件,参考 http://stackoverflow.com/questions/4178526/what-does-make-oldconfig-do-exactly-linux-kernel-makefile

##3 编译

sudo make -j8 bzImage #生成内核文件
sudo make -j8 modules #编译模块
sudo make -j8 modules_install #编译安装模块

要严格按照这个顺序进行编译,不能合并成一句,sudo make -j8 bzImage modules modules_install。

-j后面的数字是线程数,用于加快编译速度,一般的经验是,有多少G内存,就填写那个数字,例如有8G内存,则为-j8。

##4 安装

sudo make install

如果出现了 ERROR: modinfo: could not find module xxx,数量少的话,可以忽略。

##5 修改Grub引导顺序

安装完成后,需要修改Grub引导顺序,让新安装的内核作为默认内核。

编辑 grub.conf文件,

sudo vim /etc/grub.conf

数一下刚刚新安装的内核在哪个位置,从0开始,然后设置default为那个数字,一般新安装的内核在第一个位置,所以设置default=0。

##6 重启

sudo reboot

重启后,看一下当前内核版本号,

uname -r
3.10.28

成功啦!!

##7 如果失败,则重新循环

如果失败,重新开始的话,要清理上次编译的现场

make mrproper #清理上次编译的现场 

然后转到第2步,重新开始。

参考资料

  • How to upgrade the kernel on CentOS
  • CentOS 6.4 升级到 3.x Kernel
  • CentOS Linux 升级内核步骤和方法

在Centos 6.5上安装docker

发表于 2014-01-22   |   分类于 Docker   |  

1 Enable EPEL Repo on CentOS

参考 Enable EPEL Repo on CentOS 5 and CentOS 6

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2 Install docker

yum install docker-io --enablerepo=epel

3 启动 docker daemon 进程

sudo docker -d &

这时,有警告,说内核版本过低,

WARNING: You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.8.0.

如果你在公司,且公司内部都是通过代理上网,则可以把代理服务器告诉docker,用如下命令(参考这里):

sudo HTTP_PROXY=http://xxx:port docker -d &

4 升级内核

见我的另一篇博客,CentOS 6.4 升级内核到 3.11.6

5 下载 ubuntu 镜像

sudo docker pull ubuntu

6 运行 hello world

sudo docker run ubuntu /bin/echo hello world
hello world

安装成功了!!

1234…6
soulmachine

soulmachine

一些技术笔记

60 日志
14 分类
9 标签
RSS
GitHub Twitter 微博 知乎
Links
  • 连城
  • 笨狗随手留下
  • 阎栋
  • 并行实验室
  • JavaChen
  • 沈峰
  • 李海鹏
  • Eric
  • 梁兄的技术博客
  • 王孝舒的博客
  • ForeverLee
  • CMU张宇
© 2017 soulmachine
由 Hexo 强力驱动
主题 - NexT.Pisces