`
xumingyong
  • 浏览: 182411 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Ubuntu配置技巧(二)

 
阅读更多

System info


$ getconf -a    ;query system configuration.

how to identify 32bit or 64 bit OS?
# uname -m    ; i686=32bit, x86_64=64bit

how to check ubuntu version
# cat /etc/issue
# cat /etc/lsb-release
# lsb_release -a

File management

# rdev        ;show root device
# last        ;list last users login and logout
# ulimit    ;determine resource limit
# date +%y-%m-%d    ;formatting date
# hdparm -v /dev/sda    ;show or set hard drive parameters
# hdparm -tT /dev/sda    ;test speed of hard drive
# rpm -i    ;install .rpm
# rpm -e    ;erase .rpm
# dpkg -i    ;install .deb
# dpkg -r    ;remove .deb
# dpkg -l
# ifconfig eth0 netmask 255.255.255.128 192.168.203.7
# route −n
# vi /etc/resolv.conf    ;DNS config

System boot

Bootloader is the first software to execute from disk, the purpose is to start Linux Kernel. The most common used is GRUB & LILO.

The init process is the first process started by the Linux kernel during boot. The init process is responsible for starting processes during boot up and when changing runlevels.

The rc subsystem is run by init at each runlevel to start and stop the processes for that runlevel. We examine the concept of runlevels in this chapter. init is the parent of every other process.

# cat /boot/grub/menu.lst    ;for REDHAT, the file is grub.conf in same folder.

When a Linux system is booted, the first process that the kernel starts is /sbin/init. It is always process id (PID) 1 and has a parent process id (PPID) of 0. The init process is always running.

The /etc/inittab file is the configuration file for /sbin/init.
/etc/inittab identifies the processes that init starts, and it can be customized as desired. Few environment variables are set when a process is started by init. The inittab lines have four colon-separated fields:

<id>:<runlevels>:<action>:<command>

Table 1-2. Runlevels

Run Level    Meaning
----------------------------
0        System halt
1        Single user mode
2        Local multiuser without remote network (e.g., NFS)
3        Multiuser with network
4        Not used
5        Multiuser with network and xdm
6        System reboot

# who -r    ;check the run level
# whoami    ;current user

OS hangs

The first step in troubleshooting an interruptible hang is obtaining a stack trace of the offending process or processes by using the Magic SysRq keystroke.

# cat /proc/sys/kernel/sysrq
# echo 1 > /proc/sys/kernel/sysrq

To make this setting persistent, just put an entry into the configuration file:

# /etc/sysctl.conf
kernel.sysrq=1

To view the processor stacks, simply execute the dmesg command or view the syslog.

Performance tools

# top
Its fields can be added or removed, and sorted.
there are some sub-command to customize display, press[f] to select, [q] to quit.

# sar -u 1 1    ;cpu
# sar -d 1 1    ;disk
# sar -n 1 1    ;network

# vmstat -m 1 1    ; [-m] show slabinfo

# iostat
# free        ;show in kilo-bytes
# swapon -s    ;
# lshw        ;list hardware info.
# ipcs        ;show info. about IPC
# vmstat
# mpstat

# cat /proc/stat
# cat /proc/loadavg

Disk & Partition

# dd if=/dev/disk_device_file of=/tmp/disk_device_file.out bs=512 count=1
where disk_device_file is equal to /dev/sdX or /dev/hdX depending on IDE or SCSI devices. Then, after using bvi, the partition info under the MBR should look similar to the following:

EFI is nothing more than a firmware interface for the system's firmware (BIOS) that has the capability to call an OS's bootloader.

# partx /dev/sda    ;review partition table
# parted /dev/sda    ;interactive command same as above, normanlly use [p] sub-command and help, this command are easy to read
# cfdisk -P rst /dev/sda    ;also display MBR
# e2fsck -b 8193 /dev/sda3    ;check ext2/3 partition


# cat /proc/partitions

The /proc filesystem is generated by the kernel and its modules. As such, the layout of the /proc filesystem can change as you install and remove modules. The layout can differ from one system to another because of differences in hardware (say, the presence or absence of a SCSI host adapter) and because of differences in the kernel. Even given the same hardware, different kernels may produce different /proc filesystems.

The most common use for /proc is to deliver information to you on a computer's configuration.

If filesystem corrupt,
# debugfs -w /dev/sda3        ;it take sub-commands
# resize2fs /dev/sda3 200000    ;ony used for ext2fs or ext3fs

SWAP

How to mount a new swap partition
# swapon /dev/sda4        ;manually mount

如果让swap开机就加载,应该改 /etc/fstab文件,加类似如下一行;

/dev/sda4 swap swap defaults 0 0

或者把命令行直接写入 /etc/rc.d/rc.local中也行:

swapon /dev/sda6

如果您的硬盘不能再分区,您可以创建一个swap文件:

# dd if=/dev/zero of=/tmp/swap bs=1024 count=524288         ;创建一个大小为512M 的swap 文件,在/tmp目录中;
                                ;您可以根据自己的需要的大小来创建swap 文件.
# swapon -s        ;display swap used, seem as # cat /proc/swap

Devices

dmesg is a command that reads the kernel ring buffer, which holds the latest kernel messages. dmesg reports the current errors detected by the kernel with respect to the hardware or application.

# dmesg | less    ;less is oppose to more command
# lspci        ;[-v] show more details, [-t] in tree style
# insmod    ;insert new program into kernel
# rmmod        ;remove
# lsmod        ;list
# modprobe    ;load the driver
# modinfo

# cat /proc/modules    ;show modules loaded in kernel

Process

As described previously, the UNIX process model places its threads within the process structure. This structure contains the process's state, process ID (PID), parent process ID (PPID), file table, signal table, thread(s), scheduling, and other information. Thus, there is only one PID for a process that can have many threads. However, when a process calls the pthread_create() subroutine in Linux, it creates another task/PID, which just happens to share the same address space.

# ps
# pstree
# top
# echo $$    ;show shell PID
# strace -o /tmp/ll.strace -f -p 16935    ;system call trace
# lsof        ;list opend files by..

# kill -l    ;list signals
# man 7 signal

# ulimit -a    ;show limits

Backup/Recovery

# tar cvzf /dev/st0 /work
The cvzf switches denote create archive (c), verbose output (v), compress the output file (z), and specified device file (f).

# tar tvzf /dev/st0
The tvzf switches denote list archive (t), verbose output (v), compress the output file (z), and specified device file (f).

# tar xvzf /dev/st0 work/vmware/installer.sh
The tvzf switches denote extract archive (x), verbose output (v), compress the output file (z), and specified device file (f).

# cpio -itv < /dev/st0
# cpio -i "*installer.sh" < /tmp/foo3.out
# /sbin/dump -0uf /tmp/foo4.out /work
# dd if=/dev/hda1 of=/dev/st0 bs=10k

Another possibility is to use tar to zip up the files or directories first and then make them into an ISO and burn them to CD/DVD.
# tar -cvzWf /tmp/home_backup.tar.gz /home/
# mkisofs -o home_backup.iso -JrVv /m_backup.tar.gz
# cdrecord -v -eject -multi speed=8 dev=0,1,0 home_backup.is

rsync is typically used to mirror data between two servers. Here are two examples:
# rsync -e ssh -av raffi@BackupServer.your_domain.com::/home/Backup/xfer/* /destination/xfer

A bare metal backup and recovery utility enables you to make bootable recovery media. Four common utilities are available for Linux:
# mondo / mindi
# partimage
# systemimager
# g4u (Ghost for UNIX)

I Have a Tape, and I Don't Know What It Is . . .
# dd if=/dev/st0 of=/tmp/foo5.out bs=1k count=4
# file /tmp/foo5.out

Printer

Various Printing Needs and the Corresponding lp Commands

Printing Need                        Command
-----------------------------------------------------------------
Submit a print request to the default printer        lp/etc/hosts

Submit a print request to a specific printer        lp -d printera/etc/hosts

Submit two copies of a print request            lp -n 2 /etc/hosts

Submit a print request to print landscape        lp -o landscape/etc/hosts

Send mail after printing                lp -m /etc/hosts

Omit printing the banner page                lp -o nb /etc/hosts

Print a banner page                    lp -o yb/etc/hosts

Print two pages side by side on the paper        lp -o 2up /etc/hosts

Print on both sides of the paper            lp -o duplex /etc/hosts

Print raw output to the printer                lp -o raw /home/user/afile.pcl

Print request from paper tray 2                lp -o tray2/etc/hosts


Various Printing Needs and the Corresponding lpadmin Commands

Printing Need                        Command
------------------------------------------------------------------

Change the system default printer            lpadmin d printqueue

Remove a print queue                    lpadmin -xprintqueue


# lpstat -t
# lpoptions

for Serial port attached printer
# stty -F /dev/ttyS0 -a        ;get serial port info.
# stty -F /dev/ttyS0 onlcr
# stty -F /dev/ttyS0 -onlcr
# stty -F /dev/ttyS0 9600

for USB attached printer
# lspci -v | grep USB
# cat /proc/bus/usb/devices

for Parallel attached printer
# cat /proc/sys/dev/parport/parport0/autoprobe
# dmesg |grep -i lp


for HP JetDirect*****************************
http://localhost:631/
select administration and find new printer...

Networking

# sudo iptables --list
# mii-tool        ;media independant interface
# ethtool        ;??
# ifdown
# ifup
# arp -vn
# ethereal        ;??

Next you disable ICMP:
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

Before we cover the IP address model, we should mention a few Linux kernel parameters, which are listed here.

# ls /proc/sys/net/ipv4/ip*
/proc/sys/net/ipv4/ip_autoconfig
/proc/sys/net/ipv4/ip_default_ttl
/proc/sys/net/ipv4/ip_dynaddr
/proc/sys/net/ipv4/ip_forward
/proc/sys/net/ipv4/ipfrag_high_thresh
/proc/sys/net/ipv4/ipfrag_low_thresh
/proc/sys/net/ipv4/ipfrag_time
/proc/sys/net/ipv4/ip_local_port_range
/proc/sys/net/ipv4/ip_nonlocal_bind
/proc/sys/net/ipv4/ip_no_pmtu_disc

#ipcalc            ;??, calcate ip address

#netstat -rn        ;kernel route table
#netstat -us        ;UDP, statistics

We attempted to increase the network buffer, as indicated here.
# sysctl -w net.core.rmem_max=524288    ;confgure kernel parameters in runtime
# sysctl -w net.core.wmem_max=524288
# sysctl -w net.core.rmem_default=524288
# sysctl -w net.core.wmem_default=524288

# tcpdump -i interface -s 1500 -w /tmp/trace.out
# ip address show
# ip link show        ;check manual

Login

# chage -l username    ;check aging time
# usermod        ;user modify
# sudo pwck        ;check problem with the password file

Profiles:
   1. /etc/profile
   2. ~/.bash_profile
   3. ~/.bash_login
   4. ~/.profile

# sudo su         ;temporarily login as root, the prompt will be #
# sudo -i        ;hand over to root enviroment

Press [CTRL+ALT+F1~F7] to switch different console from TTY1 to TTY6, TTY7 is exit to desktop.

X windows

# type X            ;The type command (a built-in shell command) is used to find programs in the PATH variable
# /usr/X11R6/bin/Xorg -version    ;
# cat /proc/iomem        ;show the video card and the user-space address range mapped to the device, also use [lspci] to check
# xterm -display testmachine.atl.hp.com:0    ;Xclient
# cat ~/.gnome2/*
# sudo X            ;activate X

分享到:
评论

相关推荐

    Ubuntu实战技巧(五大块知识点)精辟

    ### Ubuntu实战技巧精析 #### 一、Ubuntu安装前的准备工作 在安装Ubuntu之前,合理的准备工作至关重要,不仅能确保安装过程的顺利进行,还能避免不必要的数据损失。以下是一些关键步骤: 1. **下载Ubuntu的ISO...

    Ubuntu 命令技巧手册.rar

    《Ubuntu命令技巧手册》是专为Ubuntu用户设计的一份实用指南,它涵盖了广泛的操作系统管理、文件处理、网络通信及系统维护等方面的命令行操作技巧。Ubuntu是一个基于Debian的开源Linux发行版,以其用户友好性和强大...

    比较完整的准最终版ubuntu8.04配置攻略

    **Ubuntu 8.04配置攻略** Ubuntu 8.04,代号“Hardy Heron”,是Ubuntu发行的一个重要版本,它在2008年发布,为用户提供了稳定和可靠的Linux操作系统体验。这个配置攻略旨在帮助用户充分利用Ubuntu 8.04的功能,使...

    Ubuntu8.04安装配置大全

    #### 二、输入法配置 - **SCIM(Simple Common Input Method)**:Ubuntu 8.04默认采用SCIM作为输入法框架。用户可以通过“系统-&gt;首选项-&gt;输入法”来进行设置,支持多种语言输入法,如中文拼音、五笔等。 - **安装...

    Ubuntu配置DNS

    ### Ubuntu配置DNS详解 #### 一、概述 在Ubuntu系统中配置DNS可以帮助用户更高效地进行域名解析,尤其是在网络环境中存在多个DNS服务器的情况下,合理的DNS配置可以提高解析速度,减少延迟,同时也能够增强系统的...

    Ubuntu linux 命令大全 Ubuntu技巧.txt

    ### Ubuntu Linux 命令大全与技巧解析 #### 标题和描述中的知识点: - **Ubuntu Linux 命令大全**:这表明文档包含了大量在 Ubuntu Linux 系统中常用的命令,这些命令可以帮助用户进行系统管理、软件安装、网络...

    Ubuntu命令技巧.pdf

    ### Ubuntu命令技巧知识点详解 #### 一、安装与升级 **1.1 查看软件安装内容** - 使用命令 `dpkg -L &lt;package&gt;` 来查看指定软件包的安装内容。 **1.2 查找软件** - 可以通过 `apt search &lt;keyword&gt;` 命令来搜索...

    ubuntu8.04速成手册1.0.rar ubuntu8.04 ubuntu8安装与配置

    《Ubuntu 8.04速成手册1.0》是一份专为初学者设计的指南,旨在帮助用户快速掌握Ubuntu 8.04的操作系统安装、配置和日常使用技巧。Ubuntu 8.04,代号“Hardy Heron”,是Ubuntu Linux发行版的一个重要版本,发布于...

    ubuntu网络环境配置

    #### 二、Ubuntu网络配置基础 ##### 2.1 网络接口概述 在Ubuntu系统中,网络接口是连接计算机与外部网络的重要组成部分。常见的网络接口包括以太网接口(如`eth0`)和无线接口(如`wlan0`)。通过命令行或图形界面...

    vscode在windows和ubuntu系统下的c++环境配置详细过程

    "vscode在windows和ubuntu系统下的c++环境配置详细过程" ...这篇文章详细地介绍了如何在Windows和Ubuntu系统下配置VSCode的C++环境,并提供了一些常用的快捷键和技巧,帮助开发者更方便地使用VSCode进行C++开发。

    ubuntu 命令技巧手册 完整版

    ### Ubuntu命令技巧手册知识点概述 #### 一、Ubuntu简介与承诺 - **Ubuntu定义**:Ubuntu是一种基于Debian的Linux操作系统,以其用户友好性、稳定性及安全性著称。 - **Ubuntu承诺**:Ubuntu承诺为用户提供免费且...

    ubuntu使用技巧

    在Ubuntu操作系统中,掌握一些实用的技巧可以极大地提升工作效率和用户体验...以上技巧涵盖了Ubuntu中的快捷键使用、软件安装与管理、系统配置以及文件位置等多方面,掌握这些技巧,能让你在Ubuntu环境中更加得心应手。

    ubuntu书(ubuntu的秘密 ubuntu口袋书)

    书中的章节可能涵盖了从安装Ubuntu开始,包括选择安装类型、配置硬件驱动、更新与升级系统,到日常使用中的文件管理、软件安装、网络设置,再到系统安全、故障排查等全面的内容。此外,可能还会深入讨论Ubuntu与其他...

    ubuntu使用技巧.doc

    在Ubuntu操作系统中,掌握一些使用技巧能够极大地提升工作效率和对系统的熟悉程度。下面将详细讲解文档中提及的一些关键命令和操作。 1. **查看软件安装内容** 使用`dpkg -L &lt;package_name&gt;`可以查看已安装软件的...

    Ubuntu 20.04.5 远程桌面配置及管理

    内容概要:本文详细介绍了如何在 Ubuntu 20.04.5 server 版本的操作系统上安装及配置 Gnome 桌面以及基于 vnc 的远程桌面解决方案,同时提供...其它说明:该文档涵盖了完整的配置流程,并附带了一些常见问题解决技巧。

    Ubuntu参考手册14.04 LTS第二版.rar

    《Ubuntu参考手册14.04 LTS第二版》是一份专为Ubuntu 14.04 Long Term Support (LTS)版本用户准备的详细指南。Ubuntu 14.04 LTS,代号“Trusty Tahr”,是Ubuntu操作系统的一个稳定版本,支持周期长达5年,旨在为...

Global site tag (gtag.js) - Google Analytics