Linux configuration and optimization

Source: Internet
Author: User
Article title: Linux configuration and optimization. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: Zhang Wensheng
  
  
Linux, as a free UNIX-like operating system, is receiving increasing attention. As a Linux enthusiast, I have compared various Linux distribution kits and installed various Linux distribution kits out of study, but each installation is complete, A lot of configuration and optimization work takes a lot of time, and it is very easy to omit some details. This document uses RedHat 6.1 as an example to describe how to install and use RedHat. The following practices are applicable to various liunx release kits.
  
I. hard disk partitioning
How to create hard disk partitions and swap partitions in Linux is beyond the scope of this article. However, my experience is that when installing Linux, you must create separate partitions to store your private data, it can also be used to back up system configuration files (such as domain name servers and Samba configuration files) for later configuration.
  
2. edit the/etc/inittab file
Most Linux releases have six Virtual Consoles. In fact, three are sufficient and can save valuable memory space. Edit the/etc/inittab file and add # to the front of the following three lines #.
4: 2345: respawn:/sbin/mingetty tty4
5: 2345: respawn:/sbin/mingetty tty5
6: 2345: respawn:/sbin/mingetty tty6
Run init q to re-read the/etc/inittab file and disable the Virtual Console tty4, tty5, and tty6. If you do not consider system security, you can use the fourth virtual console to view various system information, edit the/etc/syslog. conf file, and add the following to the last line:
*. */Dev/tty4
Then run killall-HUP syslog.
  
3. create or edit the/etc/inputrc,/etc/profile, and/etc/bashrc files.
In recent years, the trend of personal computers has shifted from the command line to the graphical mode, using the mouse, but shell still has a strong vitality in Linux. There are several shell types, including bash, ksh, tcsh, zsh, and ash. bash is the most used. You only need to edit the/etc/inputrc file, set the INPUTRC environment variables, and use the Tab command to complete the full function. This allows you to implement the DOSKEY function similar to MSDOS. In this way, various operations on files and directories are as convenient and fast as possible. (Attached to the/etc/inputrc file)
__________________________________________________________________
Set bell-style none # don't beep
Set meta-flag on # allow 8-bit input
Set convert-meta off # don't strip 8-bit characters
Set output-meta on # display 8-bit characters correctly
Set horizontal-scroll-mode On # scroll long command lines
Set show-all-if-ambiguous On # after TAB is pressed
  
"\ E [1 ~ ": Beginning-of-line # home
"\ E [2 ~ ": Insert-last-argument # insert
"\ E [3 ~ ": Delete-char # delete
"\ E [4 ~ ": End-of-line # end
"\ E [5 ~ ": Backward-kill-word # page up
"\ E [6 ~ ": Kill-word # page down
  
# Define F7 F8 like msdos doskey
"\ E [18 ~ ": History-search-forward # F7
"\ E [19 ~ ": History-search-backward # F8
__________________________________________________________________
  
Edit the/etc/profile file and insert the following content at the end of the file:
_________________________________________________
# Add by zws
# Customize less
# LESS = '-M-Q-R'
PS1 = "[\ u @ \ h \ w] \ $"
INPUTRC =/etc/inputrc
LESS = '-M-R' #-r for ls | less supports color.
LESSEDIT = "% E? Lt + % lt. % f"
LESSOPEN = "| lesspipe. sh % s"
LESSCHARSET = latin1
PAGER = less
Export LESS LESSEDIT LESSOPEN LESSCHARSET INPUTRC
_________________________________________________
  
Create the/usr/bin/lesspipe. sh file with the following content:
__________________________________________________________________________
#! /Bin/sh
# This is a preprocessor for 'less'. It is used when this environment
# Variable is set: LESSOPEN = "| lesspipe. sh % s"
Lesspipe (){
Case "$1" in
* .Tar.bz2) bzip2-cd $1 $1 2>/dev/null | tar tvvf -;;
*. Tar) tar tf $1 2>/dev/null; # View contents of. tar and. tgz files
*. Tgz | * .tar.gz | *. tar. Z | *. tar. z) tar ztf $1 2>/dev/null ;;
*. Z | *. z | *. gz) gzip-dc $1 2>/dev/null; # View compressed files correctly
*. Zip) unzip-l $1 2>/dev/null; # View archives
*. Arj) unarj l $1 2>/dev/null ;;
*. Rpm) rpm-qpil $1 2>/dev/null ;;
*. Cpio) cpio -- list-F $1 2>/dev/null ;;
*. Bz2) bzip2-dc $1 2>/dev/null; # View compressed files correctly
*. 1 | *. 2 | *. 3 | *. 4 | *. 5 | *. 6 | *. 7 | *. 8 | *. 9 | *. n | *. l | *. man) FILE = 'File-L $1'
FILE = 'echo $ FILE | cut-D'-f 2'
If ["$ FILE" = "troff"]; then
Groff-s-p-t-e-Tascii-mandoc $1
Fi ;;
*) File $1 | grep text>/dev/null;
If [$? = 1]; then # it's not some kind of text
Strings $1
Fi ;;
Esac
}
Lesspipe $1
_____________________________________________________________________ In this way, you can use less to view the information and content of the above file format.
Note: Use the chmod 755/usr/bin/lesspipe. sh command to set this file to executable!
Example of the/etc/bashrc file:
____________________________________________
#/Etc/bashrc
  
# System wide functions and aliases
# Environment stuff goes in/etc/profile
  
# For some unknown reason bash refuses to inherit
# PS1 in some circumstances that I can't figure out.
# Putting PS1 here ensures that it gets loaded every time.
# PS1 = "[\ u @ \ h \ w] \ $"
  
Eval 'dircolors-B'
Alias ls = 'ls -- color = yes-F-n' # color supported by ls
Alias l = 'ls -- color = yes-l-F-n' # l
Alias cp = 'CP-I'
Alias mv = 'MV-I'
Alias rm = 'rm-I'
Alias df = 'df-H'
Alias ln = 'ln-I'
Lrpm () # list information on an. rpm file
{
If [$ #! = 0]; then rpm-qilf 'which $ 1' | less; fi
}
Lsrpm () # list information on an. rpm file
{
If [$ #! = 0]; then rpm-qif 'which $ 1' | less; fi
}
Set-o noclobber # Avoid overwriting and rewriting files
____________________________________________
  
4. edit the/etc/rc. local file
If you need to customize your login information, be sure to modify/etc/rc. d/rc. local file, because each execution of/etc/rc. d/rc. for local files, you must modify the/etc/issue and/etc/issue.net files. you can annotate these commands, edit and customize your/etc/issue file, and speed up the Linux boot process, add the following content:
Echo "base = 0xd8000000 size = 0x800000 type = write-combining">/proc/mtrr
# Enable NumLock
For tty in/dev/tty [1-3]; do
Setleds-D + num <$ tty
Done
Note: For the first line of commands, see The/usr/src/linux/Documentation/mtrr.txt file.
  
5. customize the vim environment
In the Linux environment, there are many editors, including emacs, vim, and joe. for those who have never used UNIX or Linux, it is recommended that you find a few reference books to learn how to use these editors. after installing Linux, you will not be confused when editing and viewing some configuration files. In particular, vi is hard to grasp at the beginning. it is best to get the guidance from a professional. once you get started, it is like driving a high-speed Mercedes-Benz racing car, for beginners, you can go to OS versions such as iis98. after decompression, you can learn and use vi in a familiar environment.
The following is an example of/usr/share/vim/vimrc:
___________________________________________________________
"" (For Chinese)
"Set file encoding format as 'prc' for Simplified Chinese
"Valid values for 'set fe = 'is ansi, japan, korea, prc, taiwan
"We set fe to prc for default, if you need single-byte editing,
"Just type ': set fe = ansi' will do the work.
  
Set fe = prc
  
"" (For Chinese)
"" Set r0000on, you must set this to ensure
"" The Chinese functionality of gvim
Set ru
  
"" For syntax color
If & term = "xterm"
Set term = rxvt
Set t_Co = 8
Set t_Sb = ^ [4% dm
Set t_Sf = ^ [3% dm
Endif
Syntax on
  
"" Set visual bell and disable screen flash
": Set vb t_vb =
  
Set bs = 2
  
"" Toggle on/off highlightsearch
Map : Set hls! Set hls?
  
"" Toggle on/off paste mode
Map : Set paste! Set paste?
  
"" You can toggle the syntax on/off with this command
If has ("syntax_items") | syntax off | else | syntax on | endif
Map : If has ("syntax_items ") Syntax off Else Syntax on Endif
  
"" Set non-compatible with vi
Set nocompatible
  
"" Set backup extension
"S
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.