Gentoo快速安装步骤

Standard

英文原文: http://www.gentoo.org/doc/en/gentoo-x86-quickinstall.xml
中文整理如下:

1.下载ISO
到 http://www.gentoo.org/main/en/mirrors.xml 下载 /gentoo/releases/x86/current-iso/install-x86-minimal-*.iso (约80多兆)

2.配置网卡

livecd root # net-setup eth0
(有界面)

3.为了安装时方便可启动sshd并修改root密码

livecd root # /etc/init.d/sshd start
(有些命令比较长,开了ssh方便你从SecureCRT往上copy代码)
livecd root # passwd

4.分区格式化

livecd root # cfdisk /dev/sda
(有界面)
 
分成下面这样就行了
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          12       96358+  83  Linux
/dev/sda2              13          74      498015   82  Linux swap / Solaris
/dev/sda3              75         652     4642785   83  Linux
 
然后格式化
livecd ~ # mke2fs /dev/sda1
livecd ~ # mke2fs -j /dev/sda3
livecd ~ # mkswap /dev/sda2 && swapon /dev/sda2

5.Mount文件系统

livecd ~ # mount /dev/sda3 /mnt/gentoo
livecd ~ # mkdir /mnt/gentoo/boot
livecd ~ # mount /dev/sda1 /mnt/gentoo/boot
livecd ~ # cd /mnt/gentoo

6.下载stage3文件

cd /mnt/gentoo/
livecd gentoo # links http://www.gentoo.org/main/en/mirrors.xml
(links文字化网页浏览器,找到releases/x86/current/目录,选中stage3文件回车下载)
livecd gentoo # tar xjpf stage3*

7.下载Portage

cd /mnt/gentoo/usr
livecd usr # links http://www.gentoo.org/main/en/mirrors.xml
(找到snapshots/目录并下载portage-latest.tar.bz2)
livecd usr # tar xjf portage-latest*

8.Chroot

livecd usr # cd /
livecd / # mount -t proc proc /mnt/gentoo/proc
livecd / # mount -o bind /dev /mnt/gentoo/dev
livecd / # cp -L /etc/resolv.conf /mnt/gentoo/etc/
livecd / # chroot /mnt/gentoo /bin/bash
livecd / # env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...

9.修改时区

livecd / # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
livecd / # date

10.修改host及域名

livecd / # cd /etc
livecd etc # echo "127.0.0.1 yemaosheng.com yemaosheng localhost" > hosts
livecd etc # sed -i -e 's/HOSTNAME.*/HOSTNAME="yemaosheng"/' conf.d/hostname
(Use defined host name and check)
livecd etc # hostname yemaosheng
livecd etc # hostname -f
yemaosheng.com

11.选最快的镜像站点

livecd etc # emerge mirrorselect
livecd etc # mirrorselect -D -s 5 -b 10

12.内核编译

livecd etc # emerge gentoo-sources
(漫长下载过程)
livecd etc # cd /usr/src/linux
livecd linux # make menuconfig
(有界面)
livecd linux # make -j2
livecd linux # make modules_install
livecd linux # cp arch/i386/boot/bzImage /boot/kernel

13.fstab配置

livecd linux # cd /etc
livecd etc # nano -w fstab
/dev/sda1   /boot     ext2    noauto,noatime     1 2
/dev/sda3   /         ext3    noatime            0 1
/dev/sda2   none      swap    sw                 0 0

14.网络配置

livecd etc # cd conf.d
livecd conf.d # echo 'config_eth0=( "192.168.0.10/24" )' >> net
livecd conf.d # echo 'routes_eth0=( "default via 192.168.0.1" )' >> net
livecd conf.d # rc-update add net.eth0 default
livecd conf.d # rc-update add sshd default

15.设root密码

livecd conf.d # passwd

16.修改/etc/conf.d/clock

livecd conf.d # nano -w /etc/conf.d/clock
TIMEZONE="Asia/Shanghai"

17.安装系统工具

livecd conf.d # emerge syslog-ng vixie-cron
livecd conf.d # rc-update add syslog-ng default
(日志)
livecd conf.d # rc-update add vixie-cron default
(定时)
 
如果需要可安装:
livecd conf.d # emerge slocate
(方便你找文件)
livecd conf.d # emerge dhcpcd
(DHCP客户端)
livecd conf.d # emerge ppp
(PPPoE ADSL拨号)

18.配置系统引导

livecd conf.d # emerge grub
 
livecd conf.d # nano -w /boot/grub/grub.conf
default 0
timeout 10
title Gentoo
root (hd0,0)
kernel /boot/kernel root=/dev/sda3
 
livecd conf.d # grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

19.拿出光盘并重启

livecd conf.d # exit
livecd / # umount /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo
livecd / # reboot

20.重启进入系统后建个有su权限的用户

yemaosheng ~ # useradd -m -G users,wheel -s /bin/bash userman
yemaosheng ~ # passwd userman

注:
1.以上安装步骤在真实机器上通过,但VMware上安装后启动失败,解决方法可参考:http://www.gentoo-wiki.info/HOWTO_Install_Gentoo_on_VMware
2.关于VMware克隆虚拟机无法启动网卡的问题.因为VMware虚拟机克隆后变换了虚拟网卡的mac地址,而系统加载网卡驱动后会去读一个缓存文件,此文件包含了克隆前网卡的mac地址,所以现有的网卡mac地址和文件里的不同系统就拒绝启动.只要把这个文件删除后重启系统就可以了.这个文件是: /etc/udev/rules.d/70-persistent-net.rules

转载请注明出处: http://yemaosheng.com

linux系统性能测试工具

Standard
wget http://hermit.org/Linux/Benchmarking/unixbench-5.1.2.tar.gz
tar zxvf unixbench-5.1.2.tar.gz
cd unixbench-5.1.2
make
./run

http://hermit.org/Linux/Benchmarking/README-5.1.2.txt

Linux系统常用信息查看命令

Standard

系统
# uname -a # 查看内核/操作系统/CPU信息
# head -n 1 /etc/issue # 查看操作系统版本
# cat /proc/cpuinfo # 查看CPU信息
# hostname # 查看计算机名
# lspci -tv # 列出所有PCI设备
# lsusb -tv # 列出所有USB设备
# lsmod # 列出加载的内核模块
# env # 查看环境变量

资源
# free -m # 查看内存使用量和交换区使用量
# df -h # 查看各分区使用情况
# du -sh <目录名> # 查看指定目录的大小
# grep MemTotal /proc/meminfo # 查看内存总量
# grep MemFree /proc/meminfo # 查看空闲内存量
# uptime # 查看系统运行时间、用户数、负载
# cat /proc/loadavg # 查看系统负载

磁盘和分区
# mount | column -t # 查看挂接的分区状态
# fdisk -l # 查看所有分区
# swapon -s # 查看所有交换分区
# hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)
# dmesg | grep IDE # 查看启动时IDE设备检测状况

网络
# ifconfig # 查看所有网络接口的属性
# iptables -L # 查看防火墙设置
# route -n # 查看路由表
# netstat -lntp # 查看所有监听端口
# netstat -antp # 查看所有已经建立的连接
# netstat -s # 查看网络统计信息

进程
# ps -ef # 查看所有进程
# top # 实时显示进程状态

用户
# w # 查看活动用户
# id <用户名> # 查看指定用户信息
# last # 查看用户登录日志
# cut -d: -f1 /etc/passwd # 查看系统所有用户
# cut -d: -f1 /etc/group # 查看系统所有组
# crontab -l # 查看当前用户的计划任务

服务
# chkconfig –list # 列出所有系统服务
# chkconfig –list | grep on # 列出所有启动的系统服务

程序
# rpm -qa # 查看所有安装的软件包

另外这里还有些命令

LD_DEBUG

Standard

The dynamic library loader used in linux (part of glibc) has some neat tricks. One of these is that you can set an environment variable called

LD_DEBUG

to show how symbols (variables and functions, for example) are resolved for a dynamic executable. This can sometimes help resolve obscure bugs where your application isn’t doing what you expect (assuming it is caused by symbols being resolved differently to what you were expecting).

This is very useful if you get segmentation violations or aborts for a program – this can sometimes be caused by linking against the wrong version of a library. This is also a really good way to understand what happens when you run any program! It has some self-documentation – for the impatient, you can do

$ LD_DEBUG=help /path/to/some/dynamic/executable

eg

$ LD_DEBUG=help ls

prints out:

Valid options for the LD_DEBUG environment variable are:

libs display library search paths
reloc display relocation processing
files display progress for input file
symbols display symbol table processing
bindings display information about symbol binding
versions display version dependencies
all all previous options combined
statistics display relocation statistics
help display this help message and exit

To direct the debugging output into a file instead of standard output a
filename can be specified using the LD_DEBUG_OUTPUT environment variable.

As a quick example of what it does:

$ LD_DEBUG=all ls 2>&1 > /dev/null | less

13442:
13442: file=librt.so.1; needed by ls
13442: find library=librt.so.1; searching
13442: search cache=/etc/ld.so.cache
13442: trying file=/lib/librt.so.1
13442:
13442: file=librt.so.1; generating link map
13442: dynamic: 0x400263ec base: 0x40020000 size: 0x00010d14
13442: entry: 0x400219c0 phdr: 0x40020034 phnum: 6
13442:
13442:
13442: file=libc.so.6; needed by ls
13442: find library=libc.so.6; searching
13442: search cache=/etc/ld.so.cache
13442: trying file=/lib/libc.so.6
13442:
13442: file=libc.so.6; generating link map
13442: dynamic: 0x40146ce4 base: 0x40031000 size: 0x0011ab00
13442: entry: 0x4004a184 phdr: 0x40031034 phnum: 6
13442:

13442: checking for version `GLIBC_2.2′ in file /lib/librt.so.1 required by file ls
13442: checking for version `GLIBC_2.1′ in file /lib/libc.so.6 required by file ls
13442: checking for version `GLIBC_2.2.3′ in file /lib/libc.so.6 required by file ls

13442: relocation processing: /lib/libpthread.so.0 (lazy)
13442: symbol=_errno; lookup in file=ls
13442: symbol=_errno; lookup in file=/lib/librt.so.1
13442: symbol=_errno; lookup in file=/lib/libc.so.6
13442: symbol=_errno; lookup in file=/lib/libpthread.so.0
13442: symbol=_errno; lookup in file=/lib/ld-linux.so.2
13442: binding file /lib/libpthread.so.0 to /lib/libc.so.6: normal symbol `_errno’ [GLIBC_2.0]
13442: symbol=_h_errno; lookup in file=ls
13442: symbol=_h_errno; lookup in file=/lib/librt.so.1
13442: symbol=_h_errno; lookup in file=/lib/libc.so.6
13442: symbol=_h_errno; lookup in file=/lib/libpthread.so.0
13442: symbol=_h_errno; lookup in file=/lib/ld-linux.so.2
13442: binding file /lib/libpthread.so.0 to /lib/libc.so.6: normal symbol `_h_errno’ [GLIBC_2.0]

In other words, every single function and external variable in the standard library that ls(1) uses must be located each time it is run (kind of obvious, really).

$ ldd /bin/ls
librt.so.1 => /lib/librt.so.1 (0x40020000)
libc.so.6 => /lib/libc.so.6 (0x40031000)
libpthread.so.0 => /lib/libpthread.so.0 (0x4014c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

yum安装svn+trac+apache

Standard
#
# 转载请注明出处: http://yemaosheng.com
# 将以下代码直接贴到命令行中运行即可
#
 
#改用国内的yum源
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.save
wget http://centos.ustc.edu.cn/CentOS-Base.repo
sed -i 's#gpgcheck=1#gpgcheck=0#' CentOS-Base.repo
 
#安装subversion及apache和python的相应模块
yum install -y subversion mod_dav_svn mod_python python-setuptools
 
#下载安装python模板clearsilver
wget http://dag.wieers.com/rpm/packages/clearsilver/clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i clearsilver-0.10.4-1.el5.rf.i386.rpm
wget http://dag.wieers.com/rpm/packages/clearsilver/python-clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm
 
#建svn及trac目录
mkdir /srv/svn
mkdir /srv/trac/
 
#安装Trac
wget http://ftp.edgewall.com/pub/trac/Trac-0.11.4.tar.gz
tar zxvf Trac-0.11.4.tar.gz
cd Trac-0.11.4
python setup.py build && python setup.py install
 
#新建svn项目
svnadmin create /srv/svn/project
#新建trac项目
trac-admin /srv/trac/project initenv
#按提示操作,`Path to repository` is: /srv/svn/project
 
#改文件所属为apache
chown -R apache.apache /srv/svn/project
chown -R apache.apache /srv/trac/project
 
#新建svn的apache配置文件
echo -e "<Location /svn/project>\nDAV svn\nSVNPath /srv/svn/project\nAuthType Basic\nAuthName \"project Repository\"\nAuthzSVNAccessFile /srv/svn/svn-acl-conf\nAuthUserFile /srv/svn/project.htpasswd\nRequire valid-user\n</Location>" >> /etc/httpd/conf.d/subversion.conf
#生成svn的用户名密码
touch /srv/svn/project.htpasswd
htpasswd -m /srv/svn/project.htpasswd svnroot
#生成svn用户所对应的acl权限
echo -e "[project:/]\nsvnroot =  rw" >> /srv/svn/svn-acl-conf
echo -e "<Location /trac/project>\nSetHandler mod_python\nPythonHandler trac.web.modpython_frontend\nPythonOption TracEnv /srv/trac/project\nPythonOption TracUriRoot /trac/project\n</Location>\n<Location "/trac/project/login">\nAuthType Basic\nAuthName \"trac\"\nAuthUserFile /srv/trac/project.htpasswd\nRequire valid-user\n</Location>" >> /etc/httpd/conf.d/trac.conf
 
#生成trac的用户名密码
touch /srv/trac/project.htpasswd
htpasswd -m /srv/trac/project.htpasswd tracroot
#生成tracroot用户的权限
trac-admin /srv/trac/project permission add tracroot TRAC_ADMIN
 
#重启apache
service httpd restart
 
#SVN: http://127.0.0.1/svn/project/
#Trac: http://127.0.0.1/trac/project/

备份脚本

#!/bin/sh
svnadmin hotcopy /srv/svn/project /srv/svn_bak/project/
cd /srv/svn_bak
tar -zcvf /srv/svn_bak/project_svn_.`date +%Y-%m-%d_%T`.tar.gz project/
rm -rf /srv/svn_bak/project/
 
trac-admin /srv/trac/project hotcopy /srv/trac_bak/project/
cd /srv/trac_bak
tar -zcvf /srv/trac_bak/project_trac_.`date +%Y-%m-%d_%T`.tar.gz project/
rm -rf /srv/trac_bak/project/