分区
xiaowuhello
APache配置笔记-it你好原创-本文不定期更新中
展开Biu

#

# This is the main Apache server configuration file. It contains the

# configuration directives that give the server its instructions.

# See http://httpd.apache.org/docs/2.2/; for detailed information.

# In particular, see

# http://httpd.apache.org/docs/2.2/mod/directives.html;

# for a discussion of each configuration directive.

#

#

# Do NOT simply read the instructions in here without understanding

# what they do. They're here only as hints or reminders. If you are unsure

# consult the online docs. You have been warned.

#

# The configuration directives are grouped into three basic sections:

# 1. Directives that control the operation of the Apache server process as a

# whole (the 'global environment').

# 2. Directives that define the parameters of the 'main' or 'default' server,

# which responds to requests that aren't handled by a virtual host.

# These directives also provide default values for the settings

# of all virtual hosts.

# 3. Settings for virtual hosts, which allow Web requests to be sent to

# different IP addresses or hostnames and have them handled by the

# same Apache server process.

#

# Configuration and logfile names: If the filenames you specify for many

# of the server's control files begin with "/" (or "drive:/" for Win32), the

# server will use that explicit path. If the filenames do *not* begin

# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"

# with ServerRoot set to "/etc/httpd" will be interpreted by the

# server as "/etc/httpd/logs/foo.log".

#

### Section 1: Global Environment

#

# The directives in this section affect the overall operation of Apache,

# such as the number of concurrent requests it can handle or where it

# can find its configuration files.

#

#

#

# Don't give away too much information about all the subcomponents

# we are running. Comment out this line if you don't mind remote sites

# finding out what major optional modules you are running

ServerTokens OS

#

# ServerRoot: The top of the directory tree under which the server's

# configuration, error, and log files are kept.

#

# NOTE! If you intend to place this on an NFS (or otherwise network)

# mounted filesystem then please read the LockFile documentation

# (available at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>;);

# you will save yourself a lot of trouble.

#

# Do NOT add a slash at the end of the directory path.

#

ServerRoot "/etc/httpd"

#

# PidFile: The file in which the server should record its process

# identification number when it starts.

#

PidFile run/httpd.pid

#

# Timeout: The number of seconds before receives and sends time out.

#

Timeout 120

#

# KeepAlive: Whether or not to allow persistent connections (more than

# one request per connection). Set to "Off" to deactivate.

#

KeepAlive Off

#

# MaxKeepAliveRequests: The maximum number of requests to allow

# during a persistent connection. Set to 0 to allow an unlimited amount.

# We recommend you leave this number high, for maximum performance.

#

MaxKeepAliveRequests 100

#

# KeepAliveTimeout: Number of seconds to wait for the next request from the

# same client on the same connection.

#

KeepAliveTimeout 15

##

## Server-Pool Size Regulation (MPM specific)

##

# prefork MPM

# StartServers: number of server processes to start

# MinSpareServers: minimum number of server processes which are kept spare

# MaxSpareServers: maximum number of server processes which are kept spare

# ServerLimit: maximum value for MaxClients for the lifetime of the server

# MaxClients: maximum number of server processes allowed to start

# MaxRequestsPerChild: maximum number of requests a server process serves

<IfModule prefork.c>

StartServers 8

MinSpareServers 5

MaxSpareServers 20

ServerLimit 256

MaxClients 256

MaxRequestsPerChild 4000

</IfModule>

# worker MPM

# StartServers: initial number of server processes to start

# MaxClients: maximum number of simultaneous client connections

# MinSpareThreads: minimum number of worker threads which are kept spare

# MaxSpareThreads: maximum number of worker threads which are kept spare

# ThreadsPerChild: constant number of worker threads in each server process

# MaxRequestsPerChild: maximum number of requests a server process serves

<IfModule worker.c>

StartServers 2

MaxClients 150

MinSpareThreads 25

MaxSpareThreads 75

ThreadsPerChild 25

MaxRequestsPerChild 0

</IfModule>

#

# Listen: Allows you to bind Apache to specific IP addresses and/or

# ports, in addition to the default. See also the *本站禁止HTML标签噢*

# directive.

#

# Change this to Listen on specific IP addresses as shown below to

# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)

#

#Listen 12.34.56.78:80

Listen 80

#

# Dynamic Shared Object (DSO) Support

#

# To be able to use the functionality of a module which was built as a DSO you

# have to place corresponding `LoadModule' lines at this location so the

# directives contained in it are actually available _before_ they are used.

# Statically compiled modules (those listed by `httpd -l') do not need

# to be loaded here.

#

# Example:

# LoadModule foo_module modules/mod_foo.so

#

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule auth_digest_module modules/mod_auth_digest.so

LoadModule authn_file_module modules/mod_authn_file.so

LoadModule authn_alias_module modules/mod_authn_alias.so

LoadModule authn_anon_module modules/mod_authn_anon.so

LoadModule authn_dbm_module modules/mod_authn_dbm.so

LoadModule authn_default_module modules/mod_authn_default.so

LoadModule authz_host_module modules/mod_authz_host.so

LoadModule authz_user_module modules/mod_authz_user.so

LoadModule authz_owner_module modules/mod_authz_owner.so

LoadModule authz_groupfile_module modules/mod_authz_groupfile.so

LoadModule authz_dbm_module modules/mod_authz_dbm.so

LoadModule authz_default_module modules/mod_authz_default.so

LoadModule ldap_module modules/mod_ldap.so

LoadModule authnz_ldap_module modules/mod_authnz_ldap.so

LoadModule include_module modules/mod_include.so

LoadModule log_config_module modules/mod_log_config.so

LoadModule logio_module modules/mod_logio.so

LoadModule env_module modules/mod_env.so

LoadModule ext_filter_module modules/mod_ext_filter.so

LoadModule mime_magic_module modules/mod_mime_magic.so

LoadModule expires_module modules/mod_expires.so

LoadModule deflate_module modules/mod_deflate.so

LoadModule headers_module modules/mod_headers.so

LoadModule usertrack_module modules/mod_usertrack.so

LoadModule setenvif_module modules/mod_setenvif.so

LoadModule mime_module modules/mod_mime.so

LoadModule dav_module modules/mod_dav.so

LoadModule status_module modules/mod_status.so

LoadModule autoindex_module modules/mod_autoindex.so

LoadModule info_module modules/mod_info.so

LoadModule dav_fs_module modules/mod_dav_fs.so

LoadModule vhost_alias_module modules/mod_vhost_alias.so

LoadModule negotiation_module modules/mod_negotiation.so

LoadModule dir_module modules/mod_dir.so

LoadModule actions_module modules/mod_actions.so

LoadModule speling_module modules/mod_speling.so

LoadModule userdir_module modules/mod_userdir.so

LoadModule alias_module modules/mod_alias.so

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule proxy_connect_module modules/mod_proxy_connect.so

LoadModule cache_module modules/mod_cache.so

LoadModule suexec_module modules/mod_suexec.so

LoadModule disk_cache_module modules/mod_disk_cache.so

LoadModule file_cache_module modules/mod_file_cache.so

LoadModule mem_cache_module modules/mod_mem_cache.so

LoadModule cgi_module modules/mod_cgi.so

LoadModule version_module modules/mod_version.so

#

# The following modules are not loaded by default:

#

#LoadModule cern_meta_module modules/mod_cern_meta.so

#LoadModule asis_module modules/mod_asis.so

#

# Load config files from the config directory "/etc/httpd/conf.d".

#

Include conf.d/*.conf

#

# ExtendedStatus controls whether Apache will generate "full" status

# information (ExtendedStatus On) or just basic information (ExtendedStatus

# Off) when the "server-status" handler is called. The default is Off.

#

#ExtendedStatus On

#

# If you wish httpd to run as a different user or group, you must run

# httpd as root initially and it will switch.

#

# User/Group: The name (or #number) of the user/group to run httpd as.

# . On SCO (ODT 3) use "User nouser" and "Group nogroup".

# . On HPUX you may not be able to use shared memory as nobody, and the

# suggested workaround is to create a user www and use that user.

# NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)

# when the value of (unsigned)Group is above 60000;

# don't use Group #-1 on these systems!

#

User apache

Group apache

### Section 2: 'Main' server configuration

#

# The directives in this section set up the values used by the 'main'

# server, which responds to any requests that aren't handled by a

# *本站禁止HTML标签噢* definition. These values also provide defaults for

# any *本站禁止HTML标签噢* containers you may define later in the file.

#

# All of these directives may appear inside *本站禁止HTML标签噢* containers,

# in which case these default settings will be overridden for the

# virtual host being defined.

#

#

# ServerAdmin: Your address, where problems with the server should be

# e-mailed. This address appears on some server-generated pages, such

# as error documents. e.g. admin@your-domain.com

#

ServerAdmin root@localhost

#

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# If this is not set to valid DNS name for your host, server-generated

# redirections will not work. See also the UseCanonicalName directive.

#

# If your host doesn't have a registered DNS name, enter its IP address here.

# You will have to access it by its address anyway, and this will make

# redirections work in a sensible way.

#

#ServerName www.example.com:80

#

# UseCanonicalName: Determines how Apache constructs self-referencing

# URLs and the SERVER_NAME and SERVER_PORT variables.

# When set "Off", Apache will use the Hostname and Port supplied

# by the client. When set "On", Apache will use the value of the

# ServerName directive.

#

UseCanonicalName Off

#

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to other locations.

#

DocumentRoot "/var/www/html"

#

# Each directory to which Apache has access can be configured with respect

# to which services and features are allowed and/or disabled in that

# directory (and its subdirectories).

#

# First, we configure the "default" to be a very restrictive set of

# features.

#

<Directory />

Options FollowSymLinks

AllowOverride None

</Directory>

#

# Note that from this point forward you must specifically allow

# particular features to be enabled - so if something's not working as

# you might expect, make sure that you have specifically enabled it

# below.

#

#

# This should be changed to whatever you set DocumentRoot to.

#

<Directory "/var/www/html">

#

# Possible values for the Options directive are "None", "All",

# or any combination of:

# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important. Please see

# http://httpd.apache.org/docs/2.2/mod/core.html#options

# for more information.

#

Options Indexes FollowSymLinks

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

# Options FileInfo AuthConfig Limit

#

AllowOverride None

#

# Controls who can get stuff from this server.

#

Order allow,deny

Allow from all

</Directory>

#

# UserDir: The name of the directory that is appended onto a user's home

# directory if a ~user request is received.

#

# The path to the end user account 'public_html' directory must be

# accessible to the webserver userid. This usually means that ~userid

# must have permissions of 711, ~userid/public_html must have permissions

# of 755, and documents contained therein must be world-readable.

# Otherwise, the client will only receive a "403 Forbidden" message.

#

# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden

#

<IfModule mod_userdir.c>

#

# UserDir is disabled by default since it can confirm the presence

# of a username on the system (depending on home directory

# permissions).

#

UserDir disable

#

# To enable requests to /~user/ to serve the user's public_html

# directory, remove the "UserDir disable" line above, and uncomment

# the following line instead:

#

#UserDir public_html

</IfModule>

#

# Control access to UserDir directories. The following is an example

# for a site where these directories are restricted to read-only.

#

#<Directory /home/*/public_html>

# AllowOverride FileInfo AuthConfig Limit

# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

# <Limit GET POST OPTIONS>

# Order allow,deny

# Allow from all

# </Limit>

# <LimitExcept GET POST OPTIONS>

# Order deny,allow

# Deny from all

# </LimitExcept>

#</Directory>

#

# DirectoryIndex: sets the file that Apache will serve if a directory

# is requested.

#

# The index.html.var file (a type-map) is used to deliver content-

# negotiated documents. The MultiViews Option can be used for the

# same purpose, but it is much slower.

#

DirectoryIndex index.html index.html.var

#

# AccessFileName: The name of the file to look for in each directory

# for additional configuration directives. See also the AllowOverride

# directive.

#

AccessFileName .htaccess

#

# The following lines prevent .htaccess and .htpasswd files from being

# viewed by Web clients.

#

<Files ~ "^\.ht">

Order allow,deny

Deny from all

</Files>

#

# TypesConfig describes where the mime.types file (or equivalent) is

# to be found.

#

TypesConfig /etc/mime.types

#

# DefaultType is the default MIME type the server will use for a document

# if it cannot otherwise determine one, such as from filename extensions.

# If your server contains mostly text or HTML documents, "text/plain" is

# a good value. If most of your content is binary, such as applications

# or images, you may want to use "application/octet-stream" instead to

# keep browsers from trying to display binary files as though they are

# text.

#

DefaultType text/plain

#

# The mod_mime_magic module allows the server to use various hints from the

# contents of the file itself to determine its type. The MIMEMagicFile

# directive tells the module where the hint definitions are located.

#

<IfModule mod_mime_magic.c>

# MIMEMagicFile /usr/share/magic.mime

MIMEMagicFile conf/magic

</IfModule>

#

# HostnameLookups: Log the names of clients or just their IP addresses

# e.g., www.apache.org (on) or 204.62.129.132 (off).

# The default is off because it'd be overall better for the net if people

# had to knowingly turn this feature on, since enabling it means that

# each client request will result in AT LEAST one lookup request to the

# nameserver.

#

HostnameLookups Off

#

# EnableMMAP: Control whether memory-mapping is used to deliver

# files (assuming that the underlying OS supports it).

# The default is on; turn this off if you serve from NFS-mounted

# filesystems. On some systems, turning it off (regardless of

# filesystem) can improve performance; for details, please see

# http://httpd.apache.org/docs/2.2/mod/core.html#enablemmap

#EnableMMAP off

#

# EnableSendfile: Control whether the sendfile kernel support is

# used to deliver files (assuming that the OS supports it).

# The default is on; turn this off if you serve from NFS-mounted

# filesystems. Please see

# http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile

#

#EnableSendfile off

#

# ErrorLog: The location of the error log file.

# If you do not specify an ErrorLog directive within a *本站禁止HTML标签噢*

# container, error messages relating to that virtual host will be

# logged here. If you *do* define an error logfile for a *本站禁止HTML标签噢*

# container, that host's errors will be logged there and not here.

#

ErrorLog logs/error_log

#

# LogLevel: Control the number of messages logged to the error_log.

# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

#

LogLevel warn

#

# The following directives define some format nicknames for use with

# a CustomLog directive (see below).

#

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%{Referer}i -> %U" referer

LogFormat "%{User-agent}i" agent

# "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this

# requires the mod_logio module to be loaded.

#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

#

# The location and format of the access logfile (Common Logfile Format).

# If you do not define any access logfiles within a *本站禁止HTML标签噢*

# container, they will be logged here. Contrariwise, if you *do*

# define per- *本站禁止HTML标签噢* access logfiles, transactions will be

# logged therein and *not* in this file.

#

#CustomLog logs/access_log common

#

# If you would like to have separate agent and referer logfiles, uncomment

# the following directives.

#

#CustomLog logs/referer_log referer

#CustomLog logs/agent_log agent

#

# For a single logfile with access, agent, and referer information

# (Combined Logfile Format), use the following directive:

#

CustomLog logs/access_log combined

#

# Optionally add a line containing the server version and virtual host

# name to server-generated pages (internal error documents, FTP directory

# listings, mod_status and mod_info output etc., but not CGI generated

# documents or custom error documents).

# Set to "EMail" to also include a mailto: link to the ServerAdmin.

# Set to one of: On | Off | EMail

#

ServerSignature On

#

# Aliases: Add here as many aliases as you need (with no limit). The format is

# Alias fakename realname

#

# Note that if you include a trailing / on fakename then the server will

# require it to be present in the URL. So "/icons" isn't aliased in this

# example, only "/icons/". If the fakename is slash-terminated, then the

# realname must also be slash terminated, and if the fakename omits the

# trailing slash, the realname must also omit it.

#

# We include the /icons/ alias for FancyIndexed directory listings. If you

# do not use FancyIndexing, you may comment this out.

#

Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons">

Options Indexes MultiViews

AllowOverride None

Order allow,deny

Allow from all

</Directory>

#

# WebDAV module configuration section.

#

<IfModule mod_dav_fs.c>

# Location of the WebDAV lock database.

DAVLockDB /var/lib/dav/lockdb

</IfModule>

#

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

#

# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased

# CGI directory exists, if you have that configured.

#

<Directory "/var/www/cgi-bin">

AllowOverride None

Options None

Order allow,deny

Allow from all

</Directory>

#

# Redirect allows you to tell clients about documents which used to exist in

# your server's namespace, but do not anymore. This allows you to tell the

# clients where to look for the relocated document.

# Example:

# Redirect permanent /foo http://www.example.com/bar

#

# Directives controlling the display of server-generated directory listings.

#

#

# IndexOptions: Controls the appearance of server-generated directory

# listings.

#

IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

#

# AddIcon* directives tell the server which icon to show for different

# files or filename extensions. These are only displayed for

# FancyIndexed directories.

#

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*

AddIconByType (IMG,/icons/image2.gif) image/*

AddIconByType (SND,/icons/sound2.gif) audio/*

AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe

AddIcon /icons/binhex.gif .hqx

AddIcon /icons/tar.gif .tar

AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv

AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip

AddIcon /icons/a.gif .ps .ai .eps

AddIcon /icons/layout.gif .html .shtml .htm .pdf

AddIcon /icons/text.gif .txt

AddIcon /icons/c.gif .c

AddIcon /icons/p.gif .pl .py

AddIcon /icons/f.gif .for

AddIcon /icons/dvi.gif .dvi

AddIcon /icons/uuencoded.gif .uu

AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl

AddIcon /icons/tex.gif .tex

AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..

AddIcon /icons/hand.right.gif README

AddIcon /icons/folder.gif ^^DIRECTORY^^

AddIcon /icons/blank.gif ^^BLANKICON^^

#

# DefaultIcon is which icon to show for files which do not have an icon

# explicitly set.

#

DefaultIcon /icons/unknown.gif

#

# AddDescription allows you to place a short description after a file in

# server-generated indexes. These are only displayed for FancyIndexed

# directories.

# Format: AddDescription "description" filename

#

#AddDescription "GZIP compressed document" .gz

#AddDescription "tar archive" .tar

#AddDescription "GZIP compressed tar archive" .tgz

#

# ReadmeName is the name of the README file the server will look for by

# default, and append to directory listings.

#

# HeaderName is the name of a file which should be prepended to

# directory indexes.

ReadmeName README.html

HeaderName HEADER.html

#

# IndexIgnore is a set of filenames which directory indexing should ignore

# and not include in the listing. Shell-style wildcarding is permitted.

#

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

#

# DefaultLanguage and AddLanguage allows you to specify the language of

# a document. You can then use content negotiation to give a browser a

# file in a language the user can understand.

#

# Specify a default language. This means that all data

# going out without a specific language tag (see below) will

# be marked with this one. You probably do NOT want to set

# this unless you are sure it is correct for all cases.

#

# * It is generally better to not mark a page as

# * being a certain language than marking it with the wrong

# * language!

#

# DefaultLanguage nl

#

# Note 1: The suffix does not have to be the same as the language

# keyword --- those with documents in Polish (whose net-standard

# language code is pl) may wish to use "AddLanguage pl .po" to

# avoid the ambiguity with the common suffix for perl scripts.

#

# Note 2: The example entries below illustrate that in some cases

# the two character 'Language' abbreviation is not identical to

# the two character 'Country' code for its country,

# E.g. 'Danmark/dk' versus 'Danish/da'.

#

# Note 3: In the case of 'ltz' we violate the RFC by using a three char

# specifier. There is 'work in progress' to fix this and get

# the reference data for rfc1766 cleaned up.

#

# Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl)

# English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de)

# Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja)

# Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn)

# Norwegian (no) - Polish (pl) - Portugese (pt)

# Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv)

# Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW)

#

AddLanguage ca .ca

AddLanguage cs .cz .cs

AddLanguage da .dk

AddLanguage de .de

AddLanguage el .el

AddLanguage en .en

AddLanguage eo .eo

AddLanguage es .es

AddLanguage et .et

AddLanguage fr .fr

AddLanguage he .he

AddLanguage hr .hr

AddLanguage it .it

AddLanguage ja .ja

AddLanguage ko .ko

AddLanguage ltz .ltz

AddLanguage nl .nl

AddLanguage nn .nn

AddLanguage no .no

AddLanguage pl .po

AddLanguage pt .pt

AddLanguage pt-BR .pt-br

AddLanguage ru .ru

AddLanguage sv .sv

AddLanguage zh-CN .zh-cn

AddLanguage zh-TW .zh-tw

#

# LanguagePriority allows you to give precedence to some languages

# in case of a tie during content negotiation.

#

# Just list the languages in decreasing order of preference. We have

# more or less alphabetized them here. You probably want to change this.

#

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

#

# ForceLanguagePriority allows you to serve a result page rather than

# MULTIPLE CHOICES (Prefer) [in case of a tie] or NOT ACCEPTABLE (Fallback)

# [in case no accepted languages matched the available variants]

#

ForceLanguagePriority Prefer Fallback

#

# Specify a default charset for all content served; this enables

# interpretation of all content as UTF-8 by default. To use the

# default browser choice (ISO-8859-1), or to allow the META tags

# in HTML content to override this choice, comment out this

# directive:

#

AddDefaultCharset UTF-8

# AddType allows you to add to or override the MIME configuration

# file mime.types for specific file types.

#

#AddType application/x-tar .tgz

#

# AddEncoding allows you to have certain browsers uncompress

# information on the fly. Note: Not all browsers support this.

# Despite the name similarity, the following Add* directives have nothing

# to do with the FancyIndexing customization directives above.

#

#AddEncoding x-compress .Z

#AddEncoding x-gzip .gz .tgz

# If the AddEncoding directives above are commented-out, then you

# probably should define those extensions to indicate media types:

#

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

#

# AddHandler allows you to map certain file extensions to "handlers":

# actions unrelated to filetype. These can be either built into the server

# or added with the Action directive (see below)

#

# To use CGI scripts outside of ScriptAliased directories:

# (You will also need to add "ExecCGI" to the "Options" directive.)

#

#AddHandler cgi-script .cgi

#

# For files that include their own HTTP headers:

#

#AddHandler send-as-is asis

#

# For type maps (negotiated resources):

# (This is enabled by default to allow the Apache "It Worked" page

# to be distributed in multiple languages.)

#

AddHandler type-map var

#

# Filters allow you to process content before it is sent to the client.

#

# To parse .shtml files for server-side includes (SSI):

# (You will also need to add "Includes" to the "Options" directive.)

#

AddType text/html .shtml

AddOutputFilter INCLUDES .shtml

#

# Action lets you define media types that will execute a script whenever

# a matching file is called. This eliminates the need for repeated URL

# pathnames for oft-used CGI file processors.

# Format: Action media/type /cgi-script/location

# Format: Action handler-name /cgi-script/location

#

#

# Customizable error responses come in three flavors:

# 1) plain text 2) local redirects 3) external redirects

#

# Some examples:

#ErrorDocument 500 "The server made a boo boo."

#ErrorDocument 404 /missing.html

#ErrorDocument 404 "/cgi-bin/missing_handler.pl"

#ErrorDocument 402 http://www.example.com/subscription_info.html

#

#

# Putting this all together, we can internationalize error responses.

#

# We use Alias to redirect any /error/HTTP_ *本站禁止HTML标签噢* .html.var response to

# our collection of by-error message multi-language collections. We use

# includes to substitute the appropriate text.

#

# You can modify the messages' appearance without changing any of the

# default HTTP_ *本站禁止HTML标签噢* .html.var files by adding the line:

#

# Alias /error/include/ "/your/include/path/"

#

# which allows you to create your own set of files by starting with the

# /var/www/error/include/ files and

# copying them to /your/include/path/, even on a per-VirtualHost basis.

#

Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>

<IfModule mod_include.c>

<Directory "/var/www/error">

AllowOverride None

Options IncludesNoExec

AddOutputFilter Includes html

AddHandler type-map var

Order allow,deny

Allow from all

LanguagePriority en es de fr

ForceLanguagePriority Prefer Fallback

</Directory>

# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var

# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var

# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var

# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var

# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var

# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var

# ErrorDocument 410 /error/HTTP_GONE.html.var

# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var

# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var

# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var

# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var

# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var

# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var

# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var

# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var

# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var

# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

</IfModule>

</IfModule>

#

# The following directives modify normal HTTP response behavior to

# handle known problems with browser implementations.

#

BrowserMatch "Mozilla/2" nokeepalive

BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0

BrowserMatch "RealPlayer 4\.0" force-response-1.0

BrowserMatch "Java/1\.0" force-response-1.0

BrowserMatch "JDK/1\.0" force-response-1.0

#

# The following directive disables redirects on non-GET requests for

# a directory that does not include the trailing slash. This fixes a

# problem with Microsoft WebFolders which does not appropriately handle

# redirects for folders with DAV methods.

# Same deal with Apple's DAV filesystem and Gnome VFS support for DAV.

#

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully

BrowserMatch "MS FrontPage" redirect-carefully

BrowserMatch "^WebDrive" redirect-carefully

BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully

BrowserMatch "^gnome-vfs/1.0" redirect-carefully

BrowserMatch "^XML Spy" redirect-carefully

BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

#

# Allow server status reports generated by mod_status,

# with the URL of http://servername/server-status

# Change the ".example.com" to match your domain to enable.

#

#<Location /server-status>

# SetHandler server-status

# Order deny,allow

# Deny from all

# Allow from .example.com

#</Location>

#

# Allow remote server configuration reports, with the URL of

# http://servername/server-info (requires that mod_info.c be loaded).

# Change the ".example.com" to match your domain to enable.

#

#<Location /server-info>

# SetHandler server-info

# Order deny,allow

# Deny from all

# Allow from .example.com

#</Location>

#

# Proxy Server directives. Uncomment the following lines to

# enable the proxy server:

#

#<IfModule mod_proxy.c>

#ProxyRequests On

#

#<Proxy *>

# Order deny,allow

# Deny from all

# Allow from .example.com

#</Proxy>

#

# Enable/disable the handling of HTTP/1.1 "Via:" headers.

# ("Full" adds the server version; "Block" removes all outgoing Via: headers)

# Set to one of: Off | On | Full | Block

#

#ProxyVia On

#

# To enable a cache of proxied content, uncomment the following lines.

# See http://httpd.apache.org/docs/2.2/mod/mod_cache.html for more details.

#

#<IfModule mod_disk_cache.c>

# CacheEnable disk /

# CacheRoot "/var/cache/mod_proxy"

#</IfModule>

#

#</IfModule>

# End of proxy directives.

### Section 3: Virtual Hosts

#

# VirtualHost: If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at

# <URL:http://httpd.apache.org/docs/2.2/vhosts/>;

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

#

# Use name-based virtual hosting.

#

#NameVirtualHost *:80

#

# NOTE: NameVirtualHost cannot be used without a port specifier

# (e.g. :80) if mod_ssl is being used, due to the nature of the

# SSL protocol.

#

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#

#<VirtualHost *:80>

# ServerAdmin webmaster@dummy-host.example.com

# DocumentRoot /www/docs/dummy-host.example.com

# ServerName dummy-host.example.com

# ErrorLog logs/dummy-host.example.com-error_log

# CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

#配置虚拟主机

NameVirtualHost 192.168.0.254:80

<VirtualHost 192.168.0.254:80>

ServerAdmin webmaster@test.org

DocumentRoot /var/www/html/test.org/

ServerName www.test.org

ErrorLog logs/www.test.org-error_log

CustomLog logs/www.test.org-access_log common

</VirtualHost>

<VirtualHost 192.168.0.254:80>

ServerAdmin webmaster@test.org

DocumentRoot /var/www/html/test.org/t/

ServerName ftp.test.org

ErrorLog logs/ftp.test.org-error_log

CustomLog logs/ftp.test.org-access_log common

</VirtualHost>

[查看全文]
xiaowuhello
tmpwatch :删除临时文件
展开Biu

tmpwatch :删除临时文件

语 法

tmpwatch[必要参数][超时时间][目录]功 能tmpwatch 命令:用来删除指定时间内没有使用过的文件

类似命令: cron ls rm fuser mktemp

相似命令: linux命令

执行权限: 超级用户 普通用户

命令属性: 文件管理

参数必要参数

-a 符号链接也删除

-f 强制删除

-v 显示详细的处理信息

--test 测试

选择参数

范例

范例1:

[root@hnlinux lx138.com]# tmpwatch 100 /tmp/

//删除100小时内没使用过的文件

Linux命令在线查询(http://www.lx138.com),tmpwatch 命令 详解:http://www.lx138.com/page.php?ID=370

[查看全文]
xiaowuhello
Linux下定时备份MySQL数据库的Shell脚本
展开Biu

对任何一个已经上线的网站站点来说,数据备份都是必须的。无论版本更新还是服务器迁移,备份数据的重要性不言而喻。人工备份数据的方式不单耗费大量时间和精力,还灰常不专业的说。于是,有了下面这段脚本的出现。参考了网上的很多教程,外加自己的测试,以下脚本经测试可用。

#!/bin/bash

#Shell Command For Backup MySQL Database Everyday Automatically By Crontab

#Author : Carlos Wong

#Date : 2010-08-24

#配置参数

USER=root #数据库用户名

PASSWORD=××××× #数据库用户密码

DATABASE=TIENIUZAI #数据库名称

WEBMASTER=tieniuzai@qq.com #管理员邮箱地址,用以发送备份失败消息提醒

BACKUP_DIR=/var/www/Data_Backup/topons/ #备份文件存储路径

LOGFILE=/var/www/Data_Backup/topons/data_backup.log #日记文件路径

DATE=`date ‘+%Y%m%d-%H%M’` #日期格式(作为文件名)

DUMPFILE=$DATE.sql #备份文件名

ARCHIVE=$DATE.sql.tgz #压缩文件名

OPTIONS=”-u$USER -p$PASSWORD –opt –extended-insert=false –triggers=false -R –hex-blob –flush-logs –delete-master-logs -B $DATABASE” #mysqldump 参数 详情见帮助 mysqldump -help

#判断备份文件存储目录是否存在,否则创建该目录

if [ ! -d $BACKUP_DIR ] ;

then

mkdir -p “$BACKUP_DIR”

fi

#开始备份之前,将备份信息头写入日记文件

echo ” ” >> $LOGFILE

echo ” ” >> $LOGFILE

echo “———————————————–” >> $LOGFILE

echo “BACKUP DATE:” $(date +”%y-%m-%d %H:%M:%S”) >> $LOGFILE

echo “———————————————– ” >> $LOGFILE

#切换至备份目录

cd $BACKUP_DIR

#使用mysqldump 命令备份制定数据库,并以格式化的时间戳命名备份文件

mysqldump $OPTIONS > $DUMPFILE

#判断数据库备份是否成功

if [[ $? == 0 ]]; then

#创建备份文件的压缩包

tar czvf $ARCHIVE $DUMPFILE >> $LOGFILE 2>&1

#输入备份成功的消息到日记文件

echo “[$ARCHIVE] Backup Successful!” >> $LOGFILE

#删除原始备份文件,只需保 留数据库备份文件的压缩包即可

rm -f $DUMPFILE

else

echo “Database Backup Fail!” >> $LOGFILE

#备份失败后向网站管理者发送邮件提醒,需要mailutils或者类似终端下发送邮件工具的支持

#mail -s “Database DATABASE Daily Backup Fail” $WEBMASTER

fi

#输出备份过程结束的提醒消息

echo “Backup Process Done”

使用:将以上代码保存到: /usr/sbin/DataBackup (文件名随意,只要不跟系统原有的命令同名即可;代码可以放到任何地方,放在sbin目录下只是为了方便执行,sbin目录下的文件/目录可在终端直接调用,类似于windows下PATH变量指定的目录) 为脚本添加可执行权限: sudo chmod +x /usr/sbin/DataBackup 执行脚本: sudo DataBackup 如果需要定时执行备份命令的,只需将下面这段代码放到crontab 文件(sudo vim /etc/crontab)中去就可以了:

01 3 * * * root /usr/sbin/DataBackup #它代表着将于每天3点执行DataBackup脚本

注意:linux 下的shell脚本定义变量的格式为: key=value ,注意他们两者之间的” = “前后不能出现空格,否则系统无法确认该变量。 用红色标注的那行,第一个类似单引号的字符”`”其实不是单引号,它的输入键在键盘ESC键下方。 这个脚本只适合用于一些小站点的备份,因为它是对数据库进行全部备份而不是增量备份,不适合大容量的数据库备份。

Update:2010-08-24 :由于服务器上的MySQL配置文件里 的socket项值为 “/tmp/mysql.sock”, 而mysqldump在链接mysql server的时候会去查找位于/var/lib/mysql/目录下的mysql.sock文件。如果没有则会报错:

mysqldump: Got error: 2002: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

解决方法是:一是,修改mysql配置文件里的socket项的值为 ’/var/lib/mysql/mysql.sock’,不过这种方法需要重启mysql服务,很不厚道。二是,为/tmp/mysql.sock创建一个软链接到/var/lib/mysql/mysql.sock:

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

[查看全文]
xiaowuhello
【转载】基于CentOS构建高性能的LAMP平台
展开Biu

大纲:

一、系统安装

二、编译安装基本环境

三、配置虚拟主机及基本性能调优

四、基本安全设置

五、附录及相关介绍

一、系统安装

1. 分区

/boot 100M左右

SWAP 物理内存的2倍(如果你的物理内存大于4G以上,分配4G即可)

/ 15G

/usr/local 20G (用于安装软件)

/data 剩余所有空间

2. 系统初始化脚本(根据具体需求关闭不需要的服务)

#vi init.sh

-------------------cut begin-------------------------------------------

#welcome

cat << EOF

+--------------------------------------------------------------+

| === Welcome to Centos System init === |

+--------------http://www.linuxtone.org------------------------+

+----------------------Author:NetSeek--------------------------+

EOF

#disable ipv6

cat << EOF

+--------------------------------------------------------------+

| === Welcome to Disable IPV6 === |

+--------------------------------------------------------------+

EOF

echo "alias net-pf-10 off" >> /etc/modprobe.conf

echo "alias ipv6 off" >> /etc/modprobe.conf

/sbin/chkconfig --level 35 ip6tables off

echo "ipv6 is disabled!"

#disable selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

echo "selinux is disabled,you must reboot!"

#vim

sed -i "8 s/^/alias vi='vim'/" /root/.bashrc

echo 'syntax on' > /root/.vimrc

#zh_cn

sed -i -e 's/^LANG=.*/LANG="zh_CN.GB18030"/' /etc/sysconfig/i18n

#tunoff services

#--------------------------------------------------------------------------------

cat << EOF

+--------------------------------------------------------------+

| === Welcome to Tunoff services === |

+--------------------------------------------------------------+

EOF

#---------------------------------------------------------------------------------

for i in `ls /etc/rc3.d/S*`

do

CURSRV=`echo $i|cut -c 15-`

echo $CURSRV

case $CURSRV in

crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld )

echo "Base services, Skip!"

;;

*)

echo "change $CURSRV to off"

chkconfig --level 235 $CURSRV off

service $CURSRV stop

;;

esac

done

-------------------cut end-------------------------------------------

#sh init.sh (执行上面保存的脚本,仍后重启)

二、编译安装基本环境

1. 安装准备

1) 系统约定

软件源代码包存放位置 /usr/local/src

源码包编译安装位置(prefix) /usr/local/software_name

脚本以及维护程序存放位置 /usr/local/sbin

MySQL 数据库位置 /data/mysql/data(可按情况设置)

Apache 网站根目录 /data/www/wwwroot(可按情况设置)

Apache 虚拟主机日志根目录 /data/www/logs(可按情况设置)

Apache 运行账户 www:www (useradd -d /data/www/;chown www.www /data/www/wwwroot)

2) 系统环境部署及调整

检查系统是否正常

# tail -n100 /var/log/messages (检查有无系统级错误信息)

# dmesg (检查硬件设备是否有错误信息)

# ifconfig(检查网卡设置是否正确)

# ping www.33220.cn(检查网络是否正常)

3) 使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)

#rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#yum install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel \

ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \

gettext-devel pam-devel kernel

4) 定时校正服务器时钟,定时与中国国家授时中心授时服务器同步

# crontab -e

加入一行:

15 3 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

2. 编译安装软件包

源码编译安装所需包(Source)

1) GD2

# cd /usr/local/src

# tar xvf gd-2.0.35.tar.gz

# cd gd-2.0.35

# ./configure --prefix=/usr/local/gd2

# make

# make install

2) LibXML2

# cd /usr/local/src

# tar xvf libxml2-2.6.29.tar.bz2

# cd libxml2-2.6.29

# ./configure --prefix=/usr/local/libxml2

# make

# make install

3) LibMcrypt

# cd /usr/local/src

# tar xvf libmcrypt-2.5.8.tar.bz2

# cd libmcrypt-2.5.8

# ./configure --prefix=/usr/local/libmcrypt

# make

# make install

4) Apache日志截断程序

# cd /usr/local/src

# tar xvf cronolog-1.6.2.tar.gz

# cd cronolog-1.6.2

# ./configure --prefix=/usr/local/cronolog

# make

# make install

3. 升级OpenSSL和OpenSSH

# cd /usr/local/src

# tar xvf openssl-0.9.8g.tar.gz

# cd openssl-0.9.8g

# ./config --prefix=/usr/local/openssl

# make

# make test

# make install

# cd ..

# tar xvf openssh-5.0p1.tar.gz

# cd openssh-5.0p1

# ./configure \

"--prefix=/usr" \

"--with-pam" \

"--with-zlib" \

"--sysconfdir=/etc/ssh" \

"--with-ssl-dir=/usr/local/openssl" \

"--with-md5-passwords"

# make

# make install

1) 禁用 SSH V1 协议

找到#Protocol 2,1改为:Protocol 2

2) 禁用服务器端GSSAPI

找到以下两行,并将它们注释:

GSSAPIAuthentication yes

GSSAPICleanupCredentials yes

3) 禁用 DNS 名称解析

找到:#UseDNS yeas改为:UseDNS no

4)禁用客户端 GSSAPI

# vi /etc/ssh/ssh_config 找到:GSSAPIAuthentication yes 将这行注释掉。

最后,确认修改正确后重新启动 SSH 服务

# service sshd restart

# ssh -v

确认 OpenSSH 以及 OpenSSL 版本正确。

以上SSH配置可利用以下脚本自动修改:

-------------------cut begin-------------------------------------------

#init_ssh

ssh_cf="/etc/ssh/sshd_config"

sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf

sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf

#client

sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf

echo "ssh is init is ok.............."

-------------------cut end---------------------------------------------

三、编译安装A.M.P环境

1.下载软件编译安装

1)下载软件

# cd /usr/local/src

httpd-2.2.8.tar.gz

mysql-5.0.51b.tar.gz

php-5.2.6.tar.bz2

ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz

2) 安装MySQL

查看分析你的CPU型号:

http://gentoo-wiki.com/Safe_Cflags 查找您的GCC编译参数.

确定系统CPU类型:

# cat /proc/cpuinfo | grep "model name"

执行后会看到系统中CPU的具体型号,记下CPU型号。

# tar xvf mysql-5.0.51b.tar.gz

# cd mysql-5.0.51b

# vi mysql.sh

-------------------cut begin-------------------------------------------

CHOST="i686-pc-linux-gnu"

CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"

CXXFLAGS="${CFLAGS}"

./configure \

"--prefix=/usr/local/mysql" \

"--localstatedir=/data/mysql/data" \

"--with-comment=Source" \

"--with-server-suffix=-LinuxTone" \

"--with-mysqld-user=mysql" \

"--without-debug" \

"--with-big-tables" \

"--with-charset=utf8" \

"--with-collation=utf8_chinese_ci" \

"--with-extra-charsets=all" \

"--with-pthread" \

"--enable-static" \

"--enable-thread-safe-client" \

"--with-client-ldflags=-all-static" \

"--with-mysqld-ldflags=-all-static" \

"--enable-assembler" \

"--without-isam" \

"--without-innodb" \

"--without-ndb-debug"

make && make install

mkdir -p /data/mysql/data

useradd mysql -d /data/mysql -s /sbin/nologin

/usr/local/mysql/bin/mysql_install_db --user=mysql

cd /usr/local/mysql

chown -R root:mysql .

chown -R mysql /data/mysql/data

cp share/mysql/my-huge.cnf /etc/my.cnf

cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld

chmod 755 /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

/etc/rc.d/init.d/mysqld start

cd /usr/local/mysql/bin

for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done

-------------------cut end---------------------------------------------

#sh mysql.sh 即可开始编译.

3) 编译安装Apache

# cd /usr/local/src

# tar xvf httpd-2.2.8.tar.gz

# cd httpd-2.2.8

./configure \

"--prefix=/usr/local/apache2" \

"--with-included-apr" \

"--enable-so" \

"--enable-deflate=shared" \

"--enable-expires=shared" \

"--enable-rewrite=shared" \

"--enable-static-support" \

"--disable-userdir"

make

make install

echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local

4.)编译安装PHP

# cd /usr/local/src

# tar xjvf php-5.2.6.tar.bz2

# cd php-5.2.6

./configure \

"--prefix=/usr/local/php" \

"--with-apxs2=/usr/local/apache2/bin/apxs" \

"--with-config-file-path=/usr/local/php/etc" \

"--with-mysql=/usr/local/mysql" \

"--with-libxml-dir=/usr/local/libxml2" \

"--with-gd=/usr/local/gd2" \

"--with-jpeg-dir" \

"--with-png-dir" \

"--with-bz2" \

"--with-freetype-dir" \

"--with-iconv-dir" \

"--with-zlib-dir " \

"--with-openssl=/usr/local/openssl" \

"--with-mcrypt=/usr/local/libmcrypt" \

"--enable-soap" \

"--enable-gd-native-ttf" \

"--enable-ftp" \

"--enable-mbstring" \

"--enable-exif" \

"--disable-ipv6" \

"--disable-cgi" \

"--disable-cli" #禁掉ipv6,禁掉cli模式,提升速度和安全性.请根据具体需求定制相关的编译数.

make

make install

mkdir /usr/local/php/etc

cp php.ini-dist /usr/local/php/etc/php.ini

5)Xcache的安装.

#tar xvf xcache-1.2.2.tar.gz

#/usr/local/php/bin/phpize

./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/bin/php-config \

--enable-inline-optimization --disable-debug

#vi /usr/local/php/etc/php.ini (将以下内容加入php.ini最后面)

-------------------cut begin-------------------------------------------

[xcache-common]

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so

[xcache.admin]

xcache.admin.user = "admin"

;如何生成md5密码: echo -n "password"| md5sum

xcache.admin.pass = "035d849226a8a10be1a5e0fec1f0f3ce" #密码为52netseek

[xcache]

; Change xcache.size to tune the size of the opcode cache

xcache.size = 24M

xcache.shm_scheme = "mmap"

xcache.count = 4

xcache.slots = 8K

xcache.ttl = 0

xcache.gc_interval = 0

; Change xcache.var_size to adjust the size of variable cache

xcache.var_size = 8M

xcache.var_count = 1

xcache.var_slots = 8K

xcache.var_ttl = 0

xcache.var_maxttl = 0

xcache.var_gc_interval = 300

xcache.test = Off

xcache.readonly_protection = On

xcache.mmap_path = "/tmp/xcache"

xcache.coredump_directory = ""

xcache.cacher = On

xcache.stat = On

xcache.optimizer = Off

[xcache.coverager]

xcache.coverager = On

xcache.coveragedump_directory = ""

-------------------cut end---------------------------------------------

[查看全文]
xiaowuhello
【转载】Linux运维的一些常见问题及解决方法
展开Biu

今晚有空把最近运维中遇到的一些问题及解决方法总结下,写的比较匆忙,可能有些问题和错误,请各位看官指正。

——————————————————————————————————————————

1.shell脚本死活不执行

问题:某天研发某同事找我说帮他看看他写的shell脚本,死活不执行,报错。我看了下,脚本很简单,也没有常规性的错误,报“: bad interpreter: No such file or directory”错。一

看这错,我就问他是不是在windows下编写的脚本,然后在上传到linux服务器的……果然。

原因:在DOS/Windows里,文本文件的换行符为rn,而在*nix系统里则为n,所以DOS/Windows里编辑过的文本文件到了*nix里,每一行都多了个^M。

解决:1)重新在linux下编写脚本;2)vi :% s/r//g :% s/^M//g (^M输入用Ctrl+v, Ctrl+m)

——————————————————————————————————————————

2.crontab输出

问题:/var/spool/clientmqueue目录占用空间超过100G

原因:cron中执行的程序有输出内容,输出内容会以邮件形式发给cron的用户,而sendmail没有启动所以就产生了/var/spool/clientmqueue目录下的那些文件,日积月累可能撑破磁盘。

解决:1)直接手动删除:ls |xargs rm -f ; 2)彻底解决:在cron的自动执行语句后加上 >/dev/null 2>&1

——————————————————————————————————————————

3.telnet很慢

问题:某天研发某同事说10.50访问10.52memcached服务异常,让我们检查下看网络/服务/系统是否有异常。检查发现系统正常,服务正常,10.50ping10.52也正常,但10.50telnet10.52很慢。同时发现该机器的namesever是不起作用的。

原因:because your PC doesn’t do a reverse DNS lookup on your IP then… when you telnet/ftp into your linux box, it’ll do a dns lookup on you。

解决:1)修改/etc/hosts使hostname和ip对应; 2)在/etc/resolv.conf注释掉nameserver或者找一个“活的”nameserver。

——————————————————————————————————————————

4.Read-only file system

问题:同事在mysql里建表建不成功,提示如下:

mysql>create table wosontest (colddname1 char(1));

ERROR 1005 (HY000): Can’t create table ‘wosontest’ (errno: 30)

经检查mysql用户权限以及相关目录权限没问题;用perror 30提示信息为:OS error code 30: Read-only file system

可能原因:1)文件系统损坏;2)磁盘又坏道;3)fstab文件配置错误,如分区格式错误错误(将ntfs写成了fat)、配置指令拼写错误等。

解决:1)由于是测试机,重启机器后恢复;2)网上说用mount可解决。

——————————————————————————————————————————

5.文件删了磁盘空间没释放

问题:某天发现某台机器df -h已用磁盘空间为90G,而du -sh /*显示所有使用空间加起来才30G,囧。

原因:可能某人直接用rm删除某个正在写的文件,导致文件删了但磁盘空间没释放的问题

解决:

1)最简单重启系统或者重启相关服务。

2)干掉进程

/usr/sbin/lsof|grep deleted

ora 25575 data 33u REG 65,65 4294983680 /oradata/DATAPRE/UNDOTBS009.dbf (deleted)

从lsof的输出中,我们可以发现pid为25575的进程持有着以文件描述号(fd)为 33打开的文件/oradata/DATAPRE/UNDOTBS009.dbf。在我们找到了这个文件之后可以通过结束进程的方式来释放被占用的空间:echo > /proc/25575/fd/33

3)删除正在写的文件一般用 cat /dev/null > file

——————————————————————————————————————————

6.find文件

问题:在tmp目录下有大量包含picture_*的临时文件,每天晚上2:30对一天前的文件进行清理。之前在crontab下跑如下脚本,但是发现脚本效率很低,每次执行时负载猛涨,影响到其他服务。

#!/bin/sh

find /tmp -name “picture_*” -mtime +1 -exec rm -f {} ;

原因:目录下有大量文件,用find很耗资源。

解决:

#!/bin/sh

cd /tmp

time=`date -d “2 day ago” “+%b %d”`

ls -l|grep “picture” |grep “$time”|awk ‘{print $NF}’|xargs rm -rf

——————————————————————————————————————————

7.获取不了网关mac地址

问题:从2.14到3.65(映射地址2.141)网络不通,但是从3端的其他机器到3.65网络OK。

原因:

# arp

Address HWtype HWaddress Flags Mask Iface

192.168.3.254 ether incomplet CM bond0

表面现象是机器自动获取不了网关MAC地址,网络工程师说是网络设备的问题,具体不清。

解决:arp绑定,arp -i bond0 -s 192.168.3.254 00:00:5e:00:01:64

——————————————————————————————————————————

8.问题:某天研发某同事说网站前端+1环境http无法启动,我上去看了下。报如下错:

/etc/init.d/httpd start

Starting httpd: [Sat Jan 29 17:49:00 2011] [warn] module antibot_module is already loaded, skipping

Use proxy forward as remote ip : true.

Antibot exclude pattern : .*.[(js|css|jpg|gif|png)]

Antibot seed check pattern : login

(98)Address already in use: make_sock: could not bind to address [::]:7080

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:7080

no listening sockets available, shutting down

Unable to open log [FAILED]

原因:

1)端口被占用:表面看是7080端口被占用,于是netstat -npl|grep 7080看了下发现7080没有占用;

2)在配置文件中重复写了端口,如果在以下两个文件同时写了Listen 7080

/etc/httpd/conf/http.conf

/etc/httpd/conf.d/t.10086.cn.conf

解决:注释掉/etc/httpd/conf.d/t.10086.cn.conf的Listen 7080,重启,OK。

——————————————————————————————————————————

9.too many open file终极解决方案

echo “” >> /etc/security/limits.conf

echo “* soft nproc 65535″ >> /etc/security/limits.conf

echo “* hard nproc 65535″ >> /etc/security/limits.conf

echo “* soft nofile 65535″ >> /etc/security/limits.conf

echo “* hard nofile 65535″ >> /etc/security/limits.conf

echo “” >> /root/.bash_profile

echo “ulimit-n 65535″ >> /root/.bash_profile

echo “ulimit -u 65535″ >> /root/.bash_profile

最后重启机器 或者执行 ulimit -u 655345 && ulimit -n 65535

——————————————————————————————————————————

10.ibdata1和mysql-bin

问题:2.51磁盘空间报警,经查发现ibdata1和mysql-bin日志占用空间太多(其中ibdata1超过120G,mysql-bin超过80G)

原因:ibdata1是存储格式,在INNODB类型数据状态下,ibdata1用来存储文件的数据和索引,而库名的文件夹里的那些表文件只是结构而已。

innodb存储引擎有两种表空间的管理方式,分别是:

1)共享表空间(可拆分为多个小的表空间文件),这个是我们目前多数数据库使用的方法;

2)独立表空间,每一个表有一个独立的表空间(磁盘文件)

对于两种管理方式,各有优劣,具体如下:

①共享表空间:

优点:可以将表空间分成多个文件存放到不同的磁盘上(表空间文件大小不受表大小的限制,一个表可以分布在不同步的文件上)。

缺点:所有数据和索引存放在一个文件中,则随着数据的增加,将会有一个很大的文件,虽然可以把一个大文件分成多个小文件,但是多个表及索引在表空间中混合存储,这样如果对于一个表做了大量删除操作后表空间中将有大量空隙。对于共享表空间管理的方式下,一旦表空间被分配,就不能再回缩了。当出现临时建索引或是创建一个临时表的操作表空间扩大后,就是删除相关的表也没办法回缩那部分空间了。

②独立表空间:在配置文件(my.cnf)中设置: innodb_file_per_table

特点:每个表都有自已独立的表空间;每个表的数据和索引都会存在自已的表空间中。

优点:表空间对应的磁盘空间可以被收回(Drop table操作自动回收表空间,如果对于删除大量数据后的表可以通过:alter table tbl_name engine=innodb;回缩不用的空间。

缺点:如果单表增加过大,如超过100G,性能也会受到影响。在这种情况下,如果使用共享表空间可以把文件分开,但有同样有一个问题,如果访问的范围过大同样会访问多个文件,一样会比较慢。如果使用独立表空间,可以考虑使用分区表的方法,在一定程度上缓解问题。此外,当启用独立表空间模式时,需要合理调整innodb_open_files参数的设置。

解决:

1)ibdata1数据太大:只能通过dump,导出建库的sql语句,再重建的方法。

2)mysql-bin Log太大:

①手动删除:

删除某个日志:mysql>PURGE MASTER LOGS TO ‘mysql-bin.010′;

删除某天前的日志:mysql>PURGE MASTER LOGS BEFORE ’2010-12-22 13:00:00′;

②在/etc/my.cnf里设置只保存N天的bin-log日志

expire_logs_days = 30 //Binary Log自动删除的天数

[查看全文]
xiaowuhello
mysql负载均衡完美解决方案
展开Biu

Author:gaojinbo

Time:2011-2-14

mysql负载均衡完美解决方案V1.0

1.环境:

mysql 5

ubuntu10.04 x86_64

mdb1 eth0 192.168.5.11

mdb2 eth0 192.168.5.12

sdb1 eth0 192.168.5.21

sdb2 eth0 192.168.5.22

sdb3 eth0 192.168.5.23

sdb4 eth0 192.168.5.24

haproxy

eth0 192.168.5.10 (mdb vip write)

eth1 192.168.5.20 (sdb vip read)

说明:mdb vip用于DB的写,sdb vip用于DB读,实现读写分离和负载均衡,带故障检测自动切换

2.架构图

web1 web2 web3

| | |

—————————-

|

haproxy(lb db write/read)

|

———————————-

| |

mdb1 mdb2

| |

————– —————-

| | | |

sdb1 sdb2 sdb3 sdb4

说明:

1)mdb1和mdb1配置成主-主模式,相互同步,通过haproxy提供一个lb的写ip

2)sdb1和sdb2配置为mdb1的从,sdb3和sdb4配置为mdb2的从

3)sdb1,sdb2,sdb3,sdb4这4台从库,通过haproxy提供一个lb的读ip

4) 当mdb2停止复制,mdb1为主库,haproxy停止发送请求到mdb2和sdb3,sdb4

5) 当mdb1停止复制,mdb2为主库,haproxy停止发送请求到mdb1和sdb1,sdb2

6) 当mdb1和mdb2同时停止复制,这时2台主库变成readonly模式,数据库不能写入

7)当mdb2 offline时,mdb1进入backup mode,停止发送请求到mdb2,sdb3,sdb4

8)当mdb1 offline时,mdb2进入backup mode,停止发送请求到mdb1,sdb1,sdb2

9) 当mdb1 mdb2同时offline,整个DB停止工作

3.安装mysql-server

登录mdb1,mdb2,sdb1,sdb2,sdb3,sdb4,输入以下命令进行安装:

apt-get install mysql-server -y

安装时会提示输入mysql root用户密码,输入gaojinbo.com

修改mysql配置,监听所有接口

vi /etc/mysql/my.cnf

修改为:

bind-address = 0.0.0.0

重启mysql

/etc/init.d/mysql restart

4.配置mdb1,mdb2主-主同步

1)mdb1:

vi /etc/mysql/my.cnf

server-id = 1

log_bin = mysql-bin

log-slave-updates #很重要,从前一台机器上同步过来的数据才能同步到下一台机器

expire_logs_days = 10

max_binlog_size = 100M

auto_increment_offset = 1

auto_increment_increment = 2

2)mdb2:

vi /etc/mysql/my.cnf

server-id = 2

log_bin = mysql-bin

log-slave-updates #很重要,从前一台机器上同步过来的数据才能同步到下一台机器

expire_logs_days = 10

max_binlog_size = 100M

auto_increment_offset = 2

auto_increment_increment = 2

3)mdb1和mdb2:

重启mysql

/etc/init.d/mysql restart

添加复制用户

mysql -uroot -pgaojinbo.com

GRANT REPLICATION SLAVE ON *.* TO ‘repl’@’192.168.5.%’ IDENTIFIED BY ‘gaojinbo’;

记录日志文件和pos

mysql -uroot -pgaojinbo.com

show master status\G

4)mdb1:

change master to master_host=’192.168.5.12′,master_port=3306,master_user=’repl’,master_password=’gaojinbo’,master_log_file=’mysql-bin.000003′,master_log_pos=106;

start slave;

show slave status\G

说明:mysql-bin.000003和106是主库配置第3)步记录的信息

出现以下内容,说明同步ok

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

5)mdb2:

change master to master_host=’192.168.5.11′,master_port=3306,master_user=’repl’,master_password=’gaojinbo’,master_log_file=’mysql-bin.000001′,master_log_pos=249;

start slave;

show slave status\G

说明:mysql-bin.000001和249是主库配置第3)步记录的信息

出现以下内容,说明同步ok

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

6)测试主-主同步

mdb1:

mysql -uroot -pgaojinbo.com

show databases;

create database gaojinbo;

mdb2:

mysql -uroot -pgaojinbo.com

show databases;

即可看到在mdb1上建立的数据库gaojinbo

至此mdb1,mdb2主-主配置完成!

5.4台从库配置

sdb1-4配置(注:server-id不能相同):

vi /etc/mysql/my.cnf

server-id = 3

log_bin = mysql-bin

重启mysql

/etc/init.d/mysql restart

sdb1和sdb2配置成mdb1的从库:

mysql -uroot -pgaojinbo.com

change master to master_host=’192.168.5.11′,master_port=3306,master_user=’repl’,master_password=’gaojinbo’,master_log_file=’mysql-bin.000001′,master_log_pos=345;

start slave;

show slave status\G

说明:mysql-bin.000001和345是主库配置第3)步记录的信息

出现以下内容,说明同步ok

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

sdb3和sdb4配置成mdb2的从库:

change master to master_host=’192.168.5.12′,master_port=3306,master_user=’repl’,master_password=’gaojinbo’,master_log_file=’mysql-bin.000003′,master_log_pos=106;

start slave;

show slave status\G

说明:mysql-bin.000003和106是主库配置第3)步记录的信息

出现以下内容,说明同步ok

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

测试:

mdb1:

mysql -uroot -pgaojinbo.com

show databases;

create database eossc;

在其他DB上,这时会看到刚建立的数据库eossc

至此4台从数据库配置完成!

6.编写mysql检测脚本

1)mdb1和mdb2:

vi /etc/xinetd.d/mysqlchk

#

# /etc/xinetd.d/mysqlchk

#

service mysqlchk_write

{

flags = REUSE

socket_type = stream

port = 9200

wait = no

user = nobody

server = /opt/mysqlchk_status.sh

log_on_failure += USERID

disable = no

only_from = 192.168.5.0/24 # recommended to put the IPs that need

# to connect exclusively (security purposes)

}

service mysqlchk_replication

{

flags = REUSE

socket_type = stream

port = 9201

wait = no

user = nobody

server = /opt/mysqlchk_replication.sh

log_on_failure += USERID

disable = no

only_from = 192.168.5.0/24 # recommended to put the IPs that need

# to connect exclusively (security purposes)

}

添加服务端口

vi /etc/services

mysqlchk_write 9200/tcp #mysqlchk_write

mysqlchk_replication 9201/tcp #mysqlchk_replication

mdb1上操作:

vi /opt/mysqlchk_status.sh

#!/bin/bash

MYSQL_HOST="192.168.5.11"

MYSQL_PORT="3306"

MYSQL_USERNAME="root"

MYSQL_PASSWORD="gaojinbo.com"

ERROR_MSG=`/usr/bin/mysql –host=$MYSQL_HOST –port=$MYSQL_PORT –user=$MYSQL_USERNAME –password=$MYSQL_PASSWORD -e "show databases;" 2>/dev/null`

if [ "$ERROR_MSG" != "" ]

then

# mysql is fine, return http 200

/bin/echo -e "HTTP/1.1 200 OK\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL is running.\r\n"

/bin/echo -e "\r\n"

else

# mysql is down, return http 503

/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL is *down*.\r\n"

/bin/echo -e "\r\n"

fi

vi /opt/mysqlchk_replication.sh

#!/bin/bash

MYSQL_HOST="192.168.5.11"

MYSQL_PORT="3306"

MYSQL_USERNAME="root"

MYSQL_PASSWORD="gaojinbo.com"

/usr/bin/mysql –host=$MYSQL_HOST –port=$MYSQL_PORT –user=$MYSQL_USERNAME –password=$MYSQL_PASSWORD -e "show slave status\G;" >/tmp/check_repl.txt

iostat=`grep "Slave_IO_Running" /tmp/check_repl.txt |awk ‘{print $2}’ `

sqlstat=`grep "Slave_SQL_Running" /tmp/check_repl.txt |awk ‘{print $2}’ `

#echo iostat:$iostat and sqlstat:$sqlstat

if [ "$iostat" = "No" ] || [ "$sqlstat" = "No" ];

then

# mysql is down, return http 503

/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL replication is *down*.\r\n"

/bin/echo -e "\r\n"

else

# mysql is fine, return http 200

/bin/echo -e "HTTP/1.1 200 OK\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL replication is running.\r\n"

/bin/echo -e "\r\n"

fi

测试同步检测脚本:

mysql -uroot -pgaojinbo.com

stop slave sql_thread; #或者 stop slave io_thread;

/opt/mysqlchk_replication.sh

mdb2上操作:

添加和mdb1一样的脚本,把

/opt/mysqlchk_status.sh 里面的192.168.5.11修改为192.168.5.12

/opt/mysqlchk_replication.sh 里面的192.168.5.11修改为192.168.5.12

2)sdb1,sdb2,sdb3,sdb4上操作:

vi /etc/xinetd.d/mysqlchk

#

# /etc/xinetd.d/mysqlchk

#

service mysqlchk_replication

{

flags = REUSE

socket_type = stream

port = 9201

wait = no

user = nobody

server = /opt/mysqlchk_replication.sh

log_on_failure += USERID

disable = no

only_from = 192.168.5.0/24 # recommended to put the IPs that need

# to connect exclusively (security purposes)

}

vi /opt/mysqlchk_replication.sh

#!/bin/bash

MYSQL_HOST="192.168.5.21"

MYSQL_PORT="3306"

MYSQL_USERNAME="root"

MYSQL_PASSWORD="gaojinbo.com"

/usr/bin/mysql –host=$MYSQL_HOST –port=$MYSQL_PORT –user=$MYSQL_USERNAME –password=$MYSQL_PASSWORD -e "show slave status\G;" >/tmp/check_repl.txt

iostat=`grep "Slave_IO_Running" /tmp/check_repl.txt |awk ‘{print $2}’ `

sqlstat=`grep "Slave_SQL_Running" /tmp/check_repl.txt |awk ‘{print $2}’ `

#echo iostat:$iostat and sqlstat:$sqlstat

if [ "$iostat" = "No" ] || [ "$sqlstat" = "No" ];

then

# mysql is down, return http 503

/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL replication is *down*.\r\n"

/bin/echo -e "\r\n"

else

# mysql is fine, return http 200

/bin/echo -e "HTTP/1.1 200 OK\r\n"

/bin/echo -e "Content-Type: Content-Type: text/plain\r\n"

/bin/echo -e "\r\n"

/bin/echo -e "MySQL replication is running.\r\n"

/bin/echo -e "\r\n"

fi

注:脚本/opt/mysqlchk_replication.sh里面的ip

sdb1 MYSQL_HOST="192.168.5.21"

sdb2 MYSQL_HOST="192.168.5.22"

sdb3 MYSQL_HOST="192.168.5.23"

sdb4 MYSQL_HOST="192.168.5.24"

添加服务端口

vi /etc/services

mysqlchk_replication 9201/tcp #mysqlchk_replication

3)所有DB上操作:

增加检测脚本执行权限

chmod +x /opt/mysql*.sh

重启系统

reboot

查看监听端口

netstat -antup|grep xinetd

tcp 0 0 0.0.0.0:9200 0.0.0.0:* LISTEN 903/xinetd

tcp 0 0 0.0.0.0:9201 0.0.0.0:* LISTEN 903/xinetd

注:sdb只有9201监听

[查看全文]
xiaowuhello
Linux下关注硬盘的健康状态 【转载】
展开Biu

Linux下关注硬盘的健康状态

smartmontools

CentOS 5.3默认安装,smartmontools-5.38-2.el5.i386,可以执行rpm -q smartmontools或yum info smartmontools或yum list smartmontools查看。

使用方法:

命令行执行smartctl -h查看帮助信息,更详细的帮助信息可以通过man smartctl命令获得。

smartctl -i /dev/sda //查看硬盘的基本信息

smartctl -H /dev/sda //查看硬盘的健康状态

smartctl -c /dev/sda //查看smart功能,如错误记录、离线盘面扫描、自检所需时间等信息。

smartctl -l selftest /dev/sda //查看上一次硬盘selftest结果

smartctl -l error /dev/sda //查看最近5条错误记录

smartctl -t TEST //执行磁盘测试,TEST为所要执行的测试名,如offline, short, long

smartctl -X //退出磁盘测试

smartctl -A /dev/sda //查看厂商数据

几种硬盘自检功能的说明:

1、offline

2、short

3、long

4、select,N-M

5、select,N+SIZE

6、conveyance

在执行硬盘自检的过程中如何监视进度:

如果smart -c /dev/sda命令返回的信息有说"Suspend Offline collection upon new command",那么可以通过执行smart -c /dev/sda在"Self-test execution status:"这一项来跟踪自检的进度;否则若"Abort Offline collection upon new command",则在自检的过程中不能执行其他命令,否则自检过程将被终止。

关于执行自检测试的模式:

-C选项:对于short/long以及ATA硬盘的conveyance/selective自检,-C选项表示执行captive mode自检,对应于SCSI硬盘的foregroud mode。

其他:

smartd一个守护进程,收集分析磁盘的SMART参数,并可以根据设定将其发给指定用户。通常可以用来监视硬盘状态,当存在危险情况时提醒用户备份数据。

配置文件:/etc/smartd.conf

[查看全文]
xiaowuhello
【转载】RHCE 排错强化训练!
展开Biu

############################################### #

#

# #

#

作者:kkmangnn(kkmangnn@gmail.cn)

# #

#

#

欢迎转载,但请保留此段

# #

#

##

###############################################

系统安装: 分两种情况

1)、没有lvm,手动设置分区

,以这个为主。下图是这种方式的/etc/fstab文件

2)、有lvm,系统默认方式安装,下图是默认方式安装的/etc/fstab文件,不同情况在具体问题中有说明

几种故障,包括但不止于:

一、grub.conf文件丢失

二、grub目录丢失

三、boot目录丢失

四、/etc/fstab 文件丢失

五、/etc/inittab 文件丢失

六、mount 文件被修改

七、综合实验

一、grub.conf文件丢失

启动时提示

1 没有LVM情况

[size=+0]2 LVM的情况 注意上下两种情况区别在 root= “

这一句。具体内容参照/etc/fstab文件中的内容

重启利用光盘进入rescue模式

二,grub目录丢失

正常grub 目录下的文件

重启进入系统提示:

在提示符中按照grub文件丢失的处理方式进入系统。提示:

重启进入rescue模式,并chroot 进入真实环境模式

进入/boot/grub目录,发现目录内容是空的,需要在chroot环境下重新安装grub: grub-install /dev/sda

参照grub.conf文件丢失的方式,重新写入grub.conf文件

1 没有LVM情况

2 LVM的情况 注意上下两种情况区别在 root= “

这一句。具体内容参照/etc/fstab文件中的内容

重启正常系统

三、boot目录丢失

重新进入系统,提示

发现找不到vmlinuz 等文件

进入rescue模式,发现/boot下面没有任何文件

需要重新安装kernel 包,然后安装grub-install ,最后编辑grub.conf文件

这里通过启用网络,从ftp服务器上下载rpm包,然后安装到系统中,具体步骤:

1 chroot /mnt/sysimage

2 service network restart

( 3 )

lftp 192.168.0.254 ; 通过ftp登录系统,

( 4 )

(5 ) 退出chroot模式

6)安装rpm

rpm –ivh --force --root /mnt/sysimage /mnt/sysimage/kernel-2.6.18-53.el5.i686.rpm

(7) 输入exit 重启系统,正常进入系统

四、/etc/fstab 文件丢失

删除/etc/fstab文件,关机再开机,如果直接重启,会发现没有/etc/fstab文件也可以进入系统

(1)

没有lvm情况,开机提示:注意两个红色的FAILED

mkdir /test

#vi /test/etc/fstab

/dev/sda1

/boot

ext3

defaults 0 0

/dev/sda2

/

ext3

defaults 0 0

/dev/sda3

/home

ext3

defaults 0 0

devpts

/dev/pts

devpts

gid=5,mode=620 0 0

/dev/sda5

swap

swap

defaults 0 0

(2)

lvm的情况

进入系统后,lvm vgchange -ay

重新编辑etc/fstab 文件,本实验中,该文件位于/test/etc/fstab

重启正常进入系统

五、/etc/inittab 文件丢失

重启系统提示:

进入rescue模式

重新安装initscripts-8.45.17.EL-1.i386.rpm 参照修复/boot/grub目录方式从ftp服务器上下载rpm包,然后安装。

六、mount 文件被修改

重启提示:

进入rescue模式

rpm -Vf --root /mnt/sysimage /bin/mount

发现有问题

rpm -qf --root /mnt/sysimage /bin/mount

查找该文件属于哪个RPM安装包

七、综合: BT实验,所有上面的故障一起出现

[查看全文]