lnmp 記錄

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
wget http://mirrors.kernel.org/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm

rpm -ivh epel-release-5-4.noarch.rpm
yum -y install lrzsz


chkconfig --list | awk '{print $1}'

for i in `chkconfig --list | awk '{print $1}'`;do chkconfig $i off;done
for i in sshd syslog network crond;do chkconfig $i on;done
yum -y install *vim*
vim /etc/ssh/sshd_config

cat /sys/block/sda/queue/scheduler
elevator=deadline
vim /etc/grub.conf

yum list | grep xfs
yum -y install *xfs*

yum -y install @Base  還是用下面這種 個人不喜歡這種寫法
yum -y groupinstall "Base"

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool libtool-libs gmp-devel  unzip libcap fontconfig fontconfig-devel libXpm libXpm-devel

yum install libXpm.i686 libXpm-devel.i686 libjpeg.i686 libjpeg-devel.i686 libpng.i686 libpng-devel.i686   freetype.i686 freetype-devel.i686 -y

yum install libXpm.i386 libXpm-devel.i386 libjpeg.i386 libjpeg-devel.i386 libpng.i386 libpng-devel.i386   freetype.i386 freetype-devel.i386 -y

vim /etc/ld.so.conf.d/lnmp.conf
/usr/local/lib
/usr/local/lib64
ldconfig

tar -xf libevent-2.0.22-stable.tar.gz
./configure && make && make install

tar -xf libiconv-1.14.tar.gz
./configure && make && make install

tar -xf libmcrypt-2.5.8.tar.gz
./configure && make && make install
cd libltdl/
./configure --enable-ltdl-install && make && make install

tar -xf mhash-0.9.9.9.tar.gz
./configure && make && make install

tar -xf mcrypt-2.6.8.tar.gz
./configure && make && make install

/data0 nginx 目錄

tar -xf nginx-0.8.55.tar.gz
./configure --prefix=/usr/local/nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module

make && make install
mkdir -p /data0
chmod a+w /data0/
mkdir -pv /data0/web

vim /etc/profile.d/nginx.sh
export PATH=$PATH:/usr/local/nginx/sbin
chmod +x /etc/profile.d/nginx.sh


MySQL
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M mysql
tar -xf mysql-5.5.45-linux2.6-x86_64.tar.gz
ln -sv mysql-5.5.45-linux2.6-x86_64 mysql
cd mysql
chown -R mysql.mysql .
chown -R mysql.mysql /data1
mkdir etc
cp ~/my.cnf .
chown -R mysql.mysql .
scripts/mysql_install_db --defaults-file=/usr/local/mysql/etc/my.cnf
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf &
vim /etc/man.config
MANPATH /usr/local/mysql/man

ln -sv /usr/local/mysql/include /usr/include/mysql
vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib

vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin

chmod +x /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
格式化XFS
mkfs.xfs -f /dev/sdb1
/dev/sdb1               /data1                  xfs     defaults,noatime,nodiratime,nobarrier      1 2

PHP

tar -xf php-5.4.45.tar.bz2
./configure --prefix=/usr/local/php  \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib \
--with-zlib-dir \
--with-openssl \
--with-curl \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-jpeg-dir \
--with-png-dir \
--with-xpm-dir \
--with-freetype-dir \
--enable-mbstring \
--with-mcrypt \
--with-mhash \
--with-iconv-dir=/usr \
--enable-zip \
--enable-fpm \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/usr/local/php/lib/ \
--with-bz2 \
--enable-xml \
--with-libxml-dir=/usr \
--enable-sysvshm \
--enable-sockets \
--enable-sysvsem \
--enable-bcmath \
--enable-shmop \
--enable-inline-optimization \
--with-curlwrappers \
--enable-mbregex \
--enable-pcntl \
--enable-soap \
--with-xmlrpc \
--enable-maintainer-zts


make ZEND_EXTRA_LIBS='-liconv'
make install

cp php.ini-development /usr/local/php/lib/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod a+x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
vim /usr/local/php/etc/php-fpm.conf

pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid

vim /usr/local/php/lib/php.ini
cgi.fix_pathinfo=0

wget http://pecl.php.net/get/pthreads-0.0.45.tgz
cd pthreads-0.0.45
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install


wget http://pecl.php.net/get/memcache-2.2.7.tgz

tar -xf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

tar -xf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

tar -xf ImageMagick-6.9.0-1.tar.bz2
cd ImageMagick-6.9.0-1
./configure
make && make install

tar -xf imagick-3.2.0b2.tgz
cd imagick-3.2.0b2
ls -l
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

vim /usr/local/php/lib/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"
extension = memcache.so
extension = imagick.so
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator

/usr/local/php/bin/php -m

chmod -R a+w /data0
mkdir -pv /data0/web/www.test155.com

隱藏nginx php 版本信息
nginx
server_tokens off;
fastcgi_param  SERVER_SOFTWARE    nginx;
php
expose_php = Off
重啓nginx php-fpm

可以改動內核參數 :
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000



------------------------------------------------
避免Too many open files in system這個問題:
ulimit -SHn 65535
vim /etc/security/limits.conf
*               soft   nproc           65535
*               hard   nproc           65535
*               soft   nofile          65535
*               hard   nofile          65535


------------------------------------------------
php支持多線程:
--enable-maintainer-zts
編譯必須加上上面參數

在擴展這個:pthreads-master.zip 和memcache 一樣的擴展方式
wget http://pecl.php.net/get/pthreads-0.0.45.tgz
cd pthreads-0.0.45
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install



my.cnf 配置
[root@localhost ~]# cat my.cnf
#這個MySQL配置原版來源於MySQL管理之道一書作者書中所寫
#此配置有幾個目錄需要先建立起來
#這個是datadir /data1/data /data1/tmp
#二進制日誌目錄 /data1/logs
#錯誤日誌 慢查詢日誌 等/data1/logs
#從72G 內存到1G 內存 改小了innodb_buffer_pool_size innodb_buffer_pool_instances
#innodb_read_io_threads innodb_write_io_threads 此2個參數一般爲cpu核數的2倍
#myisam_max_sort_file_size = 1G 改爲和內存一樣大小
[client]
port = 3306
socket = /data1/mysql.sock

[mysqld]
server_id = 22
port = 3306
user = mysql
#MySQL安裝目錄
basedir = /usr/local/mysql
#MySQL數據目錄
datadir = /data1/data
tmpdir = /data1/data
socket = /data1/mysql.sock
skip_external_locking
skip_name_resolve
#默認存儲引擎
default_storage_engine = innodb
#服務器字符集
character_set_server = utf8
wait_timeout = 100
connect_timeout = 20
interactive_timeout = 100
back_log = 500
myisam_recover
event_scheduler = ON

###############binlog###############
log-bin = /data1/logs/mysql-bin
binlog_format = row
max_binlog_size = 128M
binlog_cache_size = 2M
expire_logs_days = 5


##############slow log################
slow_query_log = 1
slow_query_log_file = /data1/logs/mysql.slow
long_query_time = 2

###############error log###############
log-error = /data1/logs/error.log

###############per_thread_buffers###############
max_connections = 1024
max_user_connections = 1000
max_connect_errors = 10000
key_buffer_size = 64M
max_allowed_packet = 128M
table_cache = 3096
table_open_cache = 6144
table_definition_cache = 4096
sort_buffer_size = 512K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
join_buffer_size = 512K
tmp_table_size = 64M
max_heap_table_size = 64M
query_cache_type = 0
query_cache_size = 0
bulk_insert_buffer_size = 32M
thread_cache_size = 64
thread_stack = 256K

###############innodb##############
innodb_data_home_dir = /data1/data
innodb_log_group_home_dir = /data1/logs
innodb_data_file_path = ibdata1:2G:autoextend
innodb_buffer_pool_size = 512M
innodb_buffer_pool_instances = 1
innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 1024M
innodb_log_buffer_size = 64M
innodb_log_files_in_group = 3
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 10
innodb_sync_spin_loops = 40
innodb_max_dirty_pages_pct = 90
innodb_support_xa = 1
innodb_thread_concurrency = 0
innodb_thread_sleep_delay = 500
innodb_file_io_threads = 4
innodb_concurrency_tickets = 1000
log_bin_trust_function_creators = 1
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_io_capacity = 2000
innodb_file_format = barracuda
innodb_purge_threads = 1
innodb_purge_batch_size = 32
innodb_old_blocks_pct = 75
innodb_change_buffering = all
transaction_isolation = READ-COMMITTED

[mysqldump]
quick
max_allowed_packet = 128M
myisam_max_sort_file_size = 1G

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 256K
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open_files_limit = 28192


nginx 配置:
[root@localhost ~]# cat nginx.conf
user nobody;
worker_processes 8;
error_log logs/nginx_error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 204800;
events
{
        use epoll;
        worker_connections 204800;
}
http
{
        include mime.types;
        default_type application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 8m;
        sendfile on;
        tcp_nopush on;
        keepalive_timeout 30;
        server_tokens off;


        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;

        open_file_cache max=204800 inactive=20s;
        open_file_cache_min_uses 1;
        open_file_cache_valid 30s;
        tcp_nodelay on;
        gzip on;
        gzip_min_length 1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml;
        gzip_vary on;


        server {
                listen       80;
                server_name  www.test155.com;
                root /data0/web/www.test155.com;
                index index.html index.htm index.php;

                location ~ .*\.php?$ {
                        fastcgi_pass   127.0.0.1:9000;  
                        fastcgi_index  index.php;
                        fastcgi_intercept_errors on;
                        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
                        include        fastcgi_params;
                        fastcgi_param HTTPS on;
                }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)?$ {
                        expires 7d;
                }

                location ~ .*\.(js|css)?$ {
                        expires 1d;
                }

                location = /status {
                        stub_status on;
                        access_log   off;
                }

                log_format access '$remote_addr -- $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" $http_x_forwarded_for';
                access_log /data0/web/access_www.test155.com.log access;

        }
}








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章