安装LINUX
1.导航界面 【回车】
2.是否将CD数据拷贝到磁盘上安装 【跳过】
3.LINUX安装界面 【下一步】
4.选择语言 【英文】
5.键盘 【美国标准键盘】
6.选择类型 【自定义】
7.磁盘分配 【自动分区】
8.自动分区 【删除所有分区】
9.引导装载 【下一步】
10.
网络配置【DHCP】
11.选择系统默认语言 【英文】
12.选择时区 【北京】
13.设置管理员密码 【321321】
14.选择安装包 LINUX开发工具,系统配置工具
15.开始安装
网络配置
Netconfig图形界面设置网络,
重启network后生效。
网络服务启动
脚本/etc/init.d/network从新启动才能生效
扩展:#/etc/rc.d/init.d/networkstart启动network
#/etc/rc.d/init.d/networkstop停止network
#/etc/rc.d/init.d/networkrestart重启network
#ifconfigeth0down停止eth0
接口#ifconfigeth0up开启eth0接口
Ifdown网络接口名称停止某个网络接口。
Ifup网络接口名称开启某个网络接口。
设置Ip
netcofnig
/etc/rc.d/init.d/networkstart
ifconfigeth0up
设置防火墙
vi/etc/sysconfig/iptables
重启防火墙
/etc/init.d/iptablesrestart
查看防火墙
/etc/init.d/iptablesstatus
创建目录
Mkdir/home/soft/
wgethttp://memcached.googlecode.com/files/memcached-1.2.7.tar.gz
wgethttp://apache.etoak.com/httpd/httpd-2.2.11.tar.gz
wgethttp://www.zlib.net/zlib-1.2.3.tar.gz
wgethttp://jaist.dl.sourceforge.net/sourceforge/libpng/libpng-1.4.0beta53.tar.gz
wgethttp://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.1.10.tar.gz
wgethttp://ftp.gnu.org/pub/gnu/gettext/gettext-0.17.tar.gz
wgethttp://www.libgd.org/releases/gd-2.0.35.tar.gz
wgethttp://cn2.php.net/get/php-5.2.9.tar.gz/from/cn.php.net/mirror
安装Mysql5.0.37
开始安装和编译代码:
groupaddmysql
useradd-gmysqlmysql
tarzxvfmysql-5.0.37.tar.gz
cdmysql-5.0.37
./configure--prefix=/usr/local/webserver/mysql
make
makeinstall
scripts/mysql_install_db
chown-Rroot:mysql/usr/local/webserver/mysql
chown-Rmysql:mysql/usr/local/webserver/mysql/var
chgrp-Rmysql/usr/local/webserver/mysql
cpsupport-files/my-medium.cnf/etc/my.cnf
cp/usr/local/webserver/mysql/share/mysql/mysql.server/usr/local/webserver/mysql/share/mysql/mysqld
chmoda+x/usr/local/webserver/mysql/share/mysql/mysqld
mysqladmin-urootpass
word"321321"
启动服务方法
/usr/local/webserver/mysql/share/mysql/mysqldstart
停止服务方法
/usr/local/webserver/mysql/bin/mysqladminshutdown
cp/usr/local/webserver/mysql/include/mysql/mysql.h/usr/local/webserver/mysql/
设置成开机自启动
在/etc/rc.d/rc.local文件中加入一行
/usr/local/webserver/mysql/share/mysql/mysqldstart
这样每次重新启动系统以后,mysql也会随系统一起启动.
安装Memcache+libevent
tarzxvflibevent-1.4.9-stable.tar.gz
cdlibevent-1.4.9-stable
./configure--prefix=/usr/&&make&&makeinstall
cd../
tarzxvfmemcached-1.2.7.tar.gz
cdmemcached-1.2.7
./configure--prefix=/usr/local/server/memcached--with-libevent=/usr/&&make&&makeinstall
/usr/local/server/memcached/bin/memcached-l192.168.8.1-d-p10000-unobody-m128
cd../
表示用daemon的方式启动memcached,监听在192.168.8.1的10000端口上,运行用户为nobody,为其分配128MB的内存
安装PHP扩展包
tarzxvfzlib-1.2.3.tar.gz
cdzlib-1.2.3
./configure
make
makeinstall
cd../
tarzxvflibpng-1.4.0beta53.tar.gz
cdlibpng-1.4.0beta53
cdscripts/
mvmakefile.
linux../makefile
cd../
make
makeinstall
cd../
tarzxvffreetype-2.1.10.tar.gz
cdfreetype-2.1.10
./configure
make&&makeinstall
cd../
tarzxvfjpegsrc.v6b.tar.gz
cdjpeg-6b/
./configure--enable-shared
make
maketest
mkdir/usr/local/man
mkdir/usr/local/man/man1
makeinstall
cd../
tarzxvfgettext-0.17.tar.gz
cdgettext-0.17
./configure--prefix=/usr
cp/usr/lib/libattr.*/lib/
make
makeinstall
cd../
tarzxvfgd-2.0.35.tar.gz
cdgd-2.0.35
./configure--with-png--with-freetype--with-jpeg
make&&makeinstall
cpgd.h/usr/
cd../
tarzxvflibiconv-1.12.tar.gz
cdlibiconv-1.12
./configure--prefix=/usr/local/iconv
make
makeinstall
cd../
tarzxvflibmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure
make
makeinstall
/sbin/ldconfig
cdlibltdl/
./configure--enable-ltdl-install
make
makeinstall
cd../../
tarzxvfmhash-0.9.9.tar.gz
cdmhash-0.9.9
./configure
make
makeinstall
cd../
ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la
ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so
ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4
ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8
ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a
ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
tarzxvfmcrypt-2.6.8.tar.gz
cdmcrypt-2.6.8/
/sbin/ldconfig
./configure
make
makeinstall
cd../
安装PHP
tarzxvfphp-5.2.9.tar.gz
gzip-cdphp-5.2.8-fpm-0.5.10.diff.gz|patch-dphp-5.2.9-p1
cdphp-5.2.9
./configure--prefix=/usr/local/webserver/php--with-mysql=/usr/local/webserver/mysql--with-freetype--with-png--with-gd--with-jpeg--with-zlib--enable-magic-quotes--with-iconv--without-sqlite--with-mcrypt--with-iconv=/usr/local/iconv--without-pdo-sqlite--with-gettext=/usr--with-curl--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring--with-mhash--enable-pcntl--enable-sockets--with-config-file-path=/usr/local/webserver/php/etc--disable-dom--disable-simplexml--enable-roxen-zts
makeZEND_EXTRA_LIBS='-liconv'
makeinstall
cpphp.ini-dist/usr/local/webserver/php/etc/php.ini
编译安装PHP5扩展模块
tarzxvfmemcache-2.2.5.tgz
cdmemcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure--with-php-config=/usr/local/webserver/php/bin/php-config
make
makeinstall
cd../
tarjxvfeaccelerator-0.9.5.3.tar.bz2
cdeaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/usr/local/webserver/php/bin/php-config
make
makeinstall
cd../
tarzxvfPDO_MYSQL-1.0.2.tgz
cdPDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure--with-php-config=/usr/local/webserver/php/bin/php-config--with-pdo-mysql=/usr/local/webserver/mysql
make
makeinstall
cd../
配置eAccelerator加速PHP
mkdir-p/usr/local/webserver/eaccelerator_cache
修改PHP.ini
vi/usr/local/webserver/php/etc/php.ini
手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir="./"
修改为extension_dir="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension="memcache.so"
extension="pdo_mysql.so"
再查找output_buffering=Off
修改为output_buffering=On
按shift+g键跳到
配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
修改配置文件
vi/etc/sysctl.conf
输入
以下内容kernel.shmmax=134217728
然后执行以下命令使配置生效
/sbin/sysctl-p
创建www用户和组,虚拟主机使用的目录:
/usr/sbin/groupaddwww
/usr/sbin/useradd-gwwwwww
mkdir-p/data0/htdocs/www
chmod+w/data0/htdocs/www
chown-Rwww:www/data0/htdocs/www
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
rm-f/usr/local/webserver/php/etc/php-fpm.conf
vi/usr/local/webserver/php/etc/php-fpm.conf
输入以下内容(如果您安装Nginx+PHP用于程序调试,请将以下的<valuename="display_errors">0</value>改为<valuename="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx会报状态为500的空白错误页):
<?xmlversion="1.0"?>
<configuration>
Allrelativepathsinthisconfigarerelativetophp'sinstallprefix
<sectionname="global_options">
Pidfile
<valuename="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>
Errorlogfile
<valuename="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>
Loglevel
<valuename="log_level">notice</value>
WhenthisamountofphpprocessesexitedwithSIGSEGVorSIGBUS...
<valuename="emergency_restart_threshold">10</value>
...inalessthanthisintervaloftime,agracefulrestartwillbeinitiated.
Usefultoworkaroundaccidentalcurruptionsinaccelerator'ssharedmemory.
<valuename="emergency_restart_interval">1m</value>
Timelimitonwaitingchild'sreactiononsignalsfrommaster
<valuename="process_control_timeout">5s</value>
Setto'no'todebugfpm
<valuename="daemonize">yes</value>
</section>
<workers>
<sectionname="pool">
Nameofpool.Usedinlogsandstats.
<valuename="name">default</value>
Addresstoacceptfastcgirequestson.
Validsyntaxis'ip.ad.re.ss:port'orjust'port'or'/path/to/unix/socket'
<valuename="listen_address">127.0.0.1:9000</value>
<valuename="listen_options">
Setlisten(2)backlog
<valuename="backlog">-1</value>
Setpermissionsforunixsocket,ifoneused.
InLinuxread/writepermissionsmustbesetinordertoallowconnectionsfromwebserver.
ManyBSD-derrivedsystemsallowconnectionsregardlessofpermissions.
<valuename="owner"></value>
<valuename="group"></value>
<valuename="mode">0666</value>
</value>
Additionalphp.inidefines,specifictothispoolofworkers.
<valuename="php_defines">
<valuename="sendmail_path">/usr/sbin/sendmail-t-i</value>
<valuename="display_errors">1</value>
</value>
Unixuserofprocesses
<valuename="user">www</value>
Unixgroupofprocesses
<valuename="group">www</value>
Processmanagersettings
<valuename="pm">
Setsstyleofcontrolingworkerprocesscount.
Validvaluesare'static'and'apache-like'
<valuename="style">static</value>
Setsthelimitonthenumberofsimultaneousrequeststhatwillbeserved.
EquivalenttoApacheMaxClientsdirective.
EquivalenttoPHP_FCGI_CHILDRENenvironmentinoriginalphp.fcgi
Usedwithanypm_style.
<valuename="max_children">128</value>
Settingsgroupfor'apache-like'pmstyle
<valuename="apache_like">
Setsthenumberofserverprocessescreatedonstartup.
Usedonlywhen'apache-like'pm_styleisselected
<valuename="StartServers">20</value>
Setsthedesiredminimumnumberofidleserverprocesses.
Usedonlywhen'apache-like'pm_styleisselected
<valuename="MinSpareServers">5</value>
Setsthedesiredmaximumnumberofidleserverprocesses.
Usedonlywhen'apache-like'pm_styleisselected
<valuename="MaxSpareServers">35</value>
</value>
</value>
Thetimeout(inseconds)forservingasinglerequestafterwhichtheworkerprocesswillbeterminated
Shouldbeusedwhen'max_execution_time'inioptiondoesnotstopscriptexecutionforsomereason
'0s'means'off'
<valuename="request_terminate_timeout">0s</value>
Thetimeout(inseconds)forservingofsinglerequestafterwhichaphpbacktracewillbedumpedtoslow.logfile
'0s'means'off'
<valuename="request_slowlog_timeout">0s</value>
Thelogfileforslowrequests
<valuename="slowlog">logs/slow.log</value>
Setopenfiledescrlimit
<valuename="rlimit_files">51200</value>
Setmaxcoresizerlimit
<valuename="rlimit_core">0</value>
Chroottothisdirectoryatthestart,absolutepath
<valuename="chroot"></value>
Chdirtothisdirectoryatthestart,absolutepath
<valuename="chdir"></value>
Redirectworkers'stdoutandstderrintomainerrorlog.
Ifnotset,theywillberedirectedto/dev/null,accordingtoFastCGIspecs
<valuename="catch_workers_output">yes</value>
Howmuchrequestseachprocessshouldexecutebeforerespawn.
Usefultoworkaroundmemoryleaksin3rdpartylibraries.
Forendlessrequestprocessingpleasespecify0
EquivalenttoPHP_FCGI_MAX_REQUESTS
<valuename="max_requests">500</value>
Commaseparatedlistofipv4addressesofFastCGIclientsthatallowedtoconnect.
EquivalenttoFCGI_WEB_SERVER_ADDRSenvironmentinoriginalphp.fcgi(5.2.2+)
MakessenseonlywithAF_INETlisteningsocket.
<valuename="allowed_clients">127.0.0.1</value>
PassenvironmentvariableslikeLD_LIBRARY_PATH
All$VARIABLEsaretakenfromcurrentenvironment
<valuename="environment">
<valuename="HOSTNAME">$HOSTNAME</value>
<valuename="PATH">/usr/local/bin:/usr/bin:/bin</value>
<valuename="TMP">/tmp</value>
<valuename="TMPDIR">/tmp</value>
<valuename="TEMP">/tmp</value>
<valuename="OSTYPE">$OSTYPE</value>
<valuename="MACHTYPE">$MACHTYPE</value>
<valuename="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www
ulimit-SHn51200
/usr/local/webserver/php/sbin/php-fpmstart
安装Nginx0.7.47
安装Nginx所需的pcre库:
tarzxvfpcre-7.8.tar.gz
cdpcre-7.8/
./configure
make&&makeinstall
cd../
tarzxvfnginx-0.7.47.tar.gz
cdnginx-0.7.47/
./configure--user=www--group=www--prefix=/usr/local/webserver/nginx--without-http_memcached_module--without-http_map_module--without-http_geo_module--without-http_autoindex_module--with-http_stub_status_module--with-http_ssl_module
make&&makeinstall
cd../
mkdir-p/data1/logs
chmod+w/data1/logs
chown-Rwww:www/data1/logs
rm-f/usr/local/webserver/nginx/conf/nginx.conf
vi/usr/local/webserver/nginx/conf/nginx.conf
输入以下内容
userwwwwww;
worker_processes8;
error_log/data1/logs/nginx_error.logcrit;
pid/usr/local/webserver/nginx/nginx.pid;
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile51200;
events
{
useepoll;
worker_connections51200;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
#charsetgb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
#limit_zonecrawler$binary_remote_addr10m;
server
{
listen80;
server_nameblog.s135.com;
indexindex.htmlindex.htmindex.php;
root/data0/htdocs/blog;
#limit_conncrawler20;
location~.*\.(php|php5)?$
{
#fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefcgi.conf;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
}
location~.*\.(js|css)?$
{
expires1h;
}
log_formataccess'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
access_log/data1/logs/access.logaccess;
}
server
{
listen80;
server_namewww.s135.com;
indexindex.htmlindex.htmindex.php;
root/data0/htdocs/www;
location~.*\.(php|php5)?$
{
#fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefcgi.conf;
}
log_formatwwwlogs'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
access_log/data1/logs/wwwlogs.logwwwlogs;
}
}
在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi/usr/local/webserver/nginx/conf/fcgi.conf
输入以下内容
fastcgi_paramGATEWAY_INTERFACECGI/1.1;
fastcgi_paramSERVER_SOFTWAREnginx;
fastcgi_paramQUERY_STRING$query_string;
fastcgi_paramREQUEST_METHOD$request_method;
fastcgi_paramCONTENT_TYPE$content_type;
fastcgi_paramCONTENT_LENGTH$content_length;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_paramSCRIPT_NAME$fastcgi_script_name;
fastcgi_paramREQUEST_URI$request_uri;
fastcgi_paramDOCUMENT_URI$document_uri;
fastcgi_paramDOCUMENT_ROOT$document_root;
fastcgi_paramSERVER_PROTOCOL$server_protocol;
fastcgi_paramREMOTE_ADDR$remote_addr;
fastcgi_paramREMOTE_PORT$remote_port;
fastcgi_paramSERVER_ADDR$server_addr;
fastcgi_paramSERVER_PORT$server_port;
fastcgi_paramSERVER_NAME$server_name;
#PHPonly,requiredifPHPwasbuiltwith--enable-force-cgi-redirect
fastcgi_paramREDIRECT_STATUS200;
启动Nginx
ulimit-SHn51200
/usr/local/webserver/nginx/sbin/nginx
配置开机自动启动Nginx+PHP
vi/etc/rc.local
在末尾增加以下内容
ulimit-SHn51200
/usr/local/webserver/php/sbin/php-fpmstart
/usr/local/webserver/nginx/sbin/nginx
优化Linux内核参数
vi/etc/sysctl.conf
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=300
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=1
net.ipv4.ip_local_port_range=500065000
使配置立即生效
/sbin/sysctl-p
编写每天定时切割Nginx日志的脚本
vi/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
增写以下内容
#!/bin/bash
#Thisscriptrunat00:00
#TheNginxlogspath
logs_path="/usr/local/webserver/nginx/logs/"
mkdir-p${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/
mv${logs_path}access.log${logs_path}$(date-d"yesterday"+"%Y")/$(date-d"yesterday"+"%m")/access_$(date-d"yesterday"+"%Y%m%d").log
kill-USR1`cat/usr/local/webserver/nginx/nginx.pid`
设置crontab,每天凌晨00:00切割nginx访问日志
crontab-e
输入以下内容
0000***/bin/bash/usr/local/webserver/nginx/sbin/cut_nginx_log.sh