mysql兩主多從+heartbeat+nginx+php+vanish+haproxy+redis+sphinx+nfs+inotify+rsync

一.依賴環境安裝
yum install gcc-c++  gcc ncurses-devel bison
tar zxvf cmake-2.8.9.tar.gz
cd cmake-2.8.9
./configure
make;make install
二.mysql安裝與配置
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.5.27.tar.gz
cd mysql-5.5.27
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.27 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0
make;make install
=======================mysql配置=================================
cd /usr/local/mysql-5.5.27/
cp ./support-files/my-huge.cnf /etc/my.cnf
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
mkdir -p /data/mysql
mkdir -p /data/mysql/3306/logs/binlog/
chown -R mysql:mysql /data/mysql
/usr/local/mysql-5.5.27/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.27 --datadir=/data/mysql/3306/data
mv /etc/my.cnf /data/mysql/3306/
ln -s /data/mysql/3306/my.cnf /etc/my.cnf

service mysqld start
cp -rf /usr/local/mysql-5.5.27/bin/* /usr/bin/
mysqladmin -uroot password 'pinla2012'
======================主從配置============================
【master1】
====主數據庫設置====
vim /etc/my.cnf
在mysqld中追加
#********master1*********
server-id=1
log-bin=mysql-bin
read-only=0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#binlog-do-db=pinladb
binlog_ignore_db=mysql
binlog_ignore_db=test
binlog_ignore_db=information_schema
replicate-ignore-db=test
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-slave-updates
slave-skip-errors=all
auto_increment_increment=2
auto_increment_offset=1

service mysqld restart
mysql -uroot -p
GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER,RELOAD ON *.* TO pinla_backup@'%'IDENTIFIED by 'pinla2012';
==pinla_backup賬號測試==
mysql -h192.168.10.240 -upinla_backup -p

change master to master_host='192.168.10.245',master_user='pinla_backup',master_password='pinla2012';
flush privileges;
slave start;
show slave status\G

【master2】
#********master2*********
server-id=2
log-bin=mysql-bin
read-only=0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
#binlog-do-db=pinladb
binlog_ignore_db=mysql
binlog_ignore_db=test
binlog_ignore_db=information_schema
replicate-ignore-db=test
#replicate-ignore-db=mysql
#replicate-ignore-db=information_schema
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2

service mysqld restart
mysql -uroot -p
GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER,RELOAD ON *.* TO pinla_backup@'%'IDENTIFIED by 'pinla2012';
==pinla_backup賬號測試==
mysql -h192.168.10.245 -upinla_backup -p

change master to master_host='192.168.10.240',master_user='pinla_backup',master_password='pinla2012';
flush privileges;
slave start;
show slave status\G

show processlist \G;

【slave】
===從數據庫設置====
#****slave******
server-id=11
log-bin=mysql-bin
binlog_format=mixed
replicate-ignore-db=test
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
relay-log=db-server-2-relay-bin
log-slave-updates
===設置備份點===
mysql -uroot -p
slave stop;
change master to master_host='192.168.10.243',master_user='pinla_backup',master_password='pinla2012';
slave start;
show slave status\G
==================heartbeat配置===========================
vip:192.168.10.244
master1-eth3:192.168.10.240
#master1-eth2:10.10.10.100
master1-eth2:192.168.10.242
#master2-eth0:10.10.10.200
master2-eth0:192.168.10.243
master2-eth1:192.168.10.245

1.雙master服務器網卡設置
使用網線直接連接兩個master,並且配置兩個服務器的IP
2.安裝HA與HA依賴包
yum install libnet heartbeat* heartbeat-devel heartbeat-pils heartbeat-stonith heartbeat-ldirectord ipvsadm
cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
==配置心跳加密方式:authkeys==
vim /etc/ha.d/authkeys
auth 1
1 crc

chmod 600 /etc/ha.d/authkeys
==配置心跳的監控:haresources==
vim /etc/ha.d/haresources
追加
PL100 IPaddr::192.168.10.245/16/eth0 ipvsadm mysqld
#PL100 爲主主機名(可以使用uname -n獲得) ipvsadm mysqld爲啓動心跳同時啓動該服務。
#IPaddr:: 爲VIP
mkdir -p /var/log/ha_log
chmod 777 /var/log/ha_log
==配置心跳的配置文件:ha.cf==
vi /etc/ha.d/ha.cf
#ha的日誌文件記錄位置
logfile /var/log/ha_log/ha-log.log
#使用eth3做心跳監測
bcast eth3
#設定心跳(監測)時間時間爲2秒
keepalive 2
warntime 10
deadtime 30
initdead 120
hopfudge 1
#使用udp端口694進行心跳監測
udpport 694
#開啓爲主節點恢復後自動強佔資源(該模式很有可能出現腦裂)
auto_failback off
#節點1,必須要與 uname -n 指令得到的結果一致。
node PL100
#節點2
node PL102
ping 192.168.10.1 #通過ping網關來監測心跳是否正常
#respawn hacluster /usr/lib/heartbeat/ipfail
#apiauth ipfail gid=root uid=root
debugfile /var/log/ha_log/ha-debug.log

#創建日誌文件
touch /var/log/ha_log/ha-log.log
==設置ipvsadm的巡迴監測==
ipvsadm -A -t 192.168.10.244:3306 -s rr
ipvsadm -a -t 192.168.10.244:3306 -r 10.10.10.100:3306 -m
ipvsadm -a -t 192.168.10.244:3306 -r 10.10.10.200:3306 -m
ipvsadm --save
執行後則開始進行監測
ipvsadm --list
service heartbeat start
chkconfig --add heartbeat
==防火牆設置==
iptables -I INPUT -p udp --dport 694 -j ACCEPT
=======到此爲止以上爲mysql+hearbeat配置========
三.nginx+php
1.php配置
#PHP 5.3.3開始已經集成了PHP-FPM
==依賴環境安裝==
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make
make install
cd ..
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make;make install
cd ./libltdl
./configure --enable-ltdl-install 
make;make install
cd ../..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make;make install
yum install libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel mysql-devel
==php安裝==
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
ln -s /usr/local/mysql-5.5.27/lib/libmysqlclient.so.18  /usr/lib64/
chmod 755 /usr/lib64/
tar zxvf php-5.3.16.tar.gz
cd php-5.3.16
./configure --prefix=/usr/local/php-5.3.16 --with-config-file-path=/usr/local/php-5.3.16/etc  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath  --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex  --enable-fpm  --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pdo_mysql --with-mysql=/usr/local/mysql-5.5.27/ --with-mysqli
make ZEND_EXTRA_LIBS='-liconv'
make install
#make時若報錯make: *** [sapi/fpm/php-fpm] Error 1
#找到Makefile文件,在EXTRA_LIBS最後添加-lresolv
EXTRA_LIBS = -lcrypt -lcrypt -lrt -lmysqlclient -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lresolv

cp php.ini-production /usr/local/php-5.3.16/etc/php.ini
#因爲php5.3開始自帶fpm,使用自帶的管理腳本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
#設置開機自啓動
chkconfig php-fpm on
cp /usr/local/php-5.3.16/etc/php-fpm.conf.default /usr/local/php-5.3.16/etc/php-fpm.conf
vim /usr/local/php-5.3.16/etc/php-fpm.conf
追加
pid = run/php-fpm.pid
修改
user = nobody
group = nobody

user = www
group = www

==安裝eAccelerator==
#如需要安裝則進行安裝,其起到php程序的加速
tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac
/usr/local/php-5.3.16/bin/phpize
#若報錯
Cannot find autoconf.需安裝autoconf
yum install autoconf
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php-5.3.16/bin/php-config
make;make install
vim /usr/local/php-5.3.16/etc/php.ini
追加
extension_dir = "/usr/local/php-5.3.16/lib/php/extensions/no-debug-non-zts-20090626/"
cgi.fix_pathinfo=0

mkdir -p /usr/local/eaccelerator_cache
vi /usr/local/php-5.3.16/etc/php.ini
追加
[eaccelerator]
zend_extension="/usr/local/php-5.3.16/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
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"

==安裝APC==
tar zxvf APC-3.1.9.tgz
cd APC-3.1.9
/usr/local/php-5.3.16/bin/phpize
./configure --with-php-config=/usr/local/php-5.3.16/bin/php-config
make;make install
2.nginx安裝
yum install pcre-devel
groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /data/wwwroot
chmod +w /data/wwwroot
mkdir -p /data/nginxlogs
chmod 755 /data/nginxlogs
chown -R www:www /data/wwwroot
tar zxvf nginx-1.2.3.tar.gz
cd nginx-1.2.3
./configure --user=www --group=www --prefix=/usr/local/nginx-1.2.3 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module  --with-pcre
make;make install
mkdir /usr/local/nginx-1.2.3/conf/vhost/
rm -f /usr/local/nginx-1.2.3/conf/nginx.conf
==基本的nginx配置==
vim /usr/local/nginx-1.2.3/conf/nginx.conf
參照nginx.conf
==vhost設置===
cd /usr/local/nginx-1.2.3/conf/vhost
vim www.pinla.com.conf
參照nginx_vhost_www.pinla.com.conf
==爲不同的vhost創建目錄==
mkdir -p /data/wwwroot/www.pinla.com/
==創建管理腳本==
vim /etc/init.d/nginx
內容詳見nginx_管理腳本.sh中
chmod +x /etc/init.d/nginx
chkconfig nginx on

==========================環境說明=================================
直接輸入以下命令,會得到相應的結果
service nginx restart #重啓nginx
service mysqld restart #重啓mysql
service php-fpm restart #重啓php-fpm
service php-fpm stop #停止php-fpm
service php-fpm start #啓動php-fpm
 
各站點的根目錄是 /data/wwwroot/
應用的目錄是 /usr/local/
各配置文件的存放位置是:
php: /usr/local/php-5.3.16/etc/
mysql: /etc/
nginx: /usr/local/nginx-1.2.3/conf/
==安裝zend擴展==
tar zxvf ZendFramework-1.12.0.tar.gz
mkdir /usr/local/nginx-1.2.3/Library
mv ZendFramework-1.12.0/library/ /usr/local/nginx-1.2.3/Library/
vim /usr/local/php-5.3.16/etc/php.ini
修改爲
include_path = ".:/php/includes:/usr/local/nginx-1.2.3/Library:/data/wwwroot/www.pinla.com/Library"


==redis安裝配置==
tar zxvf redis-2.4.16.tar.gz
cd redis-2.4.16
make;make install
cp redis.conf /etc/
vim /etc/redis.conf
修改daemonize no爲daemonize yes
#開啓
redis-server /etc/redis.conf
echo "redis-server /etc/redis.conf ">>/etc/rc.local
echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf
sysctl -p
#測試
redis-benchmark
#登陸
redis-cli
==安裝和配置redis-php的擴展==
unzip  nicolasff-phpredis-2.2.2-38-g6f7087f.zip
cd nicolasff-phpredis-6f7087f/
/usr/local/php-5.3.16/bin/phpize
./configure --with-php-config=/usr/local/php-5.3.16/bin/php-config
make;make install
#安裝完成後會輸出類似下邊的
#/usr/local/php-5.3.16/lib/php/extensions/no-debug-non-zts-20090626/
#若extension_dir = "/usr/local/php-5.3.16/lib/php/extensions/no-debug-non-zts-20090626/"已在PHP目錄中則無需添加,若無需添加
vim /usr/local/php-5.3.16/etc/php.ini
在PHP擴展目錄中追加
extension = redis.so

==安裝配置sphinx==
yum install  automake libtool
【mmseg】
tar zxvf coreseek-4.1-beta.tar.gz
cd coreseek-4.1-beta/mmseg-3.2.14 
./configure --prefix=/usr/local/mmseg3
make;make install
提示config.status: error: cannot find input file: src/Makefile.in
執行以下命令:
aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean
【csft】
cd coreseek-4.1-beta/csft-4.1
sh buildconf.sh
./configure --prefix=/usr/local/sphinx --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib
make;make install
vim /usr/local/sphinx/etc/pinla.conf
[測試]
cd ../testpack
cat var/test/test.xml
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
#生成索引
/usr/local/sphinx/bin/indexer --config  /usr/local/sphinx/etc/pinla.conf --all
#啓動服務
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/pinla.conf
#網絡索引測試
/usr/local/sphinx/bin/search --config /usr/local/sphinx/etc/pinla.conf

#crontab -e    加入crontab五分鐘重新索引
*/5 * * * */usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/pinla.conf --rotate --all
==安裝php sphinx client 擴展==

tar zxvf sphinx-2.0.5-release.tar.gz
cd ./sphinx-2.0.5-release/api/libsphinxclient/
#vim sphinxclient.c                   
    找到
    void sock_close ( int sock );
    改爲
    static void sock_close ( int sock );
 
./configure --prefix=/usr/local/sphinxclient
make&&make install

tar zxvf sphinx-1.2.0.tgz
cd sphinx-1.2.0
/usr/local/php-5.3.16/bin/phpize
./configure --with-php-config=/usr/local/php-5.3.16/bin/php-config --with-sphinx=/usr/local/sphinxclient
make&&make install
#安裝完成後會提示模塊已寫入的路徑
/usr/local/php-5.3.16/lib/php/extensions/no-debug-non-zts-20090626/
vim /usr/local/php-5.3.16/etc/php.ini
追加
extension = sphinx.so
#重啓PHP
service php-fpm restart


#創建主索引
/usr/local/sphinx/bin/indexer shop  --config /usr/local/sphinx/etc/pinla.conf --rotate
#創建增量索引:
/usr/local/sphinx/bin/indexer delta --config /usr/local/sphinx/etc/pinla.conf  --rotate
#合併
/usr/local/sphinx/bin/indexer --merge shop delta -c /usr/local/sphinx/etc/pinla.conf --rotate
#查詢索引
/usr/local/sphinx/bin/search --config /usr/local/sphinx/etc/pinla.conf  -a 米娜
#計劃任務
*/5 * * * * /usr/local/sphinx/bin/indexer delta --config /usr/local/sphinx/etc/pinla.conf --rotate;/usr/local/sphinx/bin/indexer --merge shop delta -c /usr/local/sphinx/etc/pinla.conf --rotate
30 2 * * * /usr/local/sphinx/bin/indexer shop  --config /usr/local/sphinx/etc/pinla.conf --rotat


====安裝配置fastdfs_client======
tar zxvf FastDFS_v3.11.tar.gz
cd FastDFS
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
./make.sh install
cd ./php_client
/usr/local/php-5.3.16/bin/phpize
./configure --with-php-config=/usr/local/php-5.3.16/bin/php-config
make&&make install
mkdir -p /data/fdfs_data
vim /usr/local/php-5.3.16/etc/php.ini
追加
extension=fastdfs_client.so
fastdfs_client.base_path = /tmp
fastdfs_client.connect_timeout = 2
fastdfs_client.network_timeout = 60
fastdfs_client.log_level = info
fastdfs_client.log_filename =
fastdfs_client.http.anti_steal_secret_key =
fastdfs_client.tracker_group_count = 1
fastdfs_client.tracker_group0 = /etc/fdfs/client.conf

vim /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/data/fdfs_data
tracker_server=192.168.10.225:22122
log_level=info
http.tracker_server_port=8080

 

九.haproxy配置
tar zxvf haproxy-1.4.21.tar.gz
cd haproxy-1.4.21
uname -a //查看linux內核版本
make TARGET=linux26 PREFIX=/usr/local/haproxy-1.4.21
make install PREFIX=/usr/local/haproxy-1.4.21

==配置haproxy==
mkdir -p /usr/local/haproxy-1.4.21/conf
vim /usr/local/haproxy-1.4.21/conf/haproxy.conf
#參考haproxy.conf
   
==配置haproxy服務腳本==
mkdir /usr/local/haproxy-1.4.21/init.d/
mkdir -p /usr/local/haproxy-1.4.21/run/
#開啓
/usr/local/haproxy-1.4.21/sbin/haproxy -f /usr/local/haproxy-1.4.21/conf/haproxy.conf
或者腳本
vim /usr/local/haproxy-1.4.21/init.d/haproxy
#參考haproxy_啓動腳本.sh

chmod +x /usr/local/haproxy-1.4.21/init.d/haproxy
echo "net.ipv4.ip_nonlocal_bind=1" >>/etc/sysctl.conf
sysctl -p
==啓動haproxy==
/usr/local/haproxy/init.d/haproxy start
==配置haproxy日誌==
mkdir /usr/local/haproxy/log
touch /usr/local/haproxy/log/haproxy.log
vim /etc/syslog.conf
追加
SYSLOGD_OPTIONS="-m 0 -r -x"
local3.*                                                /usr/local/haproxy/log/haproxy.log

/etc/init.d/syslog restart
/usr/local/haproxy/init.d/haproxy stop
/usr/local/haproxy/init.d/haproxy start

=====varnish安裝與配置========
yum install pkgconfig
tar zxvf varnish-3.0.2.tar.gz
cd varnish-3.0.2
./configure --prefix=/usr/local/varnish-3.0.2
make && make install
cp redhat/varnish.initrc /etc/init.d/varnish
cp redhat/varnish.sysconfig /etc/sysconfig/varnish
cp redhat/varnish_reload_vcl /usr/local/varnish-3.0.2/bin/

mv   /usr/local/varnish-3.0.2/bin/varnish_reload_vcl /usr/local/varnish-3.0.2/bin/varnish_reload_vcl_back
vim /usr/local/varnish-3.0.2/bin/varnish_reload_vcl
#參照varnish_reload_vcl_config

groupadd varnish
useradd -s /bin/false -M varnish -g varnish
mkdir /data/varnish_logs /data/varnish_cache
chown -R varnish.varnish /data/varnish_logs
chown -R varnish.varnish  /data/varnish_cache
chmod +w /data/varnish_cache
chmod +w /data/varnish_logs


vim /usr/local/varnish-3.0.2/etc/varnish/pinla.vcl
#參照pinla_vcl_config
======服務啓動=======
/usr/local/varnish-3.0.2/sbin/varnishd -n /data/varnish_cache -f /usr/local/varnish-3.0.2/etc/varnish/pinla.vcl -a 0.0.0.0:8080 -s file,/data/varnish_cache/varnish_cache.data,50G -g varnish -u varnish -w30000,51200,50 -T 0.0.0.0:3000 -p thread_pool_min=200 -p thread_pool_max=4000 -p thread_pools=4 -p thread_pool_add_delay=2 -p listen_depth=4096 -p lru_interval=20

==配置啓動腳本==
mv /etc/sysconfig/varnish /etc/sysconfig/varnish_back
vim /etc/sysconfig/varnish
#參照varnish_config
vim /etc/init.d/varnish
修改
exec="/usr/local/varnish-3.0.2/sbin/varnishd"
reload_exec="/usr/local/varnish-3.0.2/bin/varnish_reload_vcl"

chmod 755 /etc/init.d/varnish
#開啓
service varnish start
service varnish stop

===配置varnish日誌腳本===
#需要rotatelogs工具(可通過安裝apache獲得)
yum install httpd
vim /etc/init.d/varnishncsa
#日誌腳本可參考varnishncsa.txt
chmod 755 /etc/init.d/varnishncsa

#開啓/關閉日誌
/etc/init.d/varnishncsa start
/etc/init.d/varnishncsa stop

#不用腳本的方式
#啓動varnishncsa用來將Varnish訪問日誌寫入日誌文件
/usr/local/varnish-3.0.2/bin/varnishncsa -n /data/varnish_cache -w /data/varnish_logs/varnish.log &

#查看varnish緩存狀態及命中率
/usr/local/varnish-3.0.2/bin/varnishstat -n /data/varnish_cache
#基於端口的管理varnish
telnet 127.0.0.1 3000

=========nfs安裝配置============
mkdir /data/static
mkdir /data/wwwroot
echo "/data/static  *(rw,sync,no_root_squash)" >> /etc/exports
#開啓NFS和portmap服務
service nfs start
service portmap start
chkconfig --level 3 nfs  on
chkconfig --level 3 portmap on
#客戶端掛載
#開啓portmap服務
service portmap start
如果portmap服務未啓,則在mount時會報錯:
chkconfig --level 3 portmap on
mkdir /data/static
mount  -t nfs 192.168.10.225:/data/static  /data/static/
#加入rc.loacl
echo "mount  -t nfs 192.168.10.225:/data/static  /data/static/">>/etc/rc.local

===========inotify+rsync=========
#NFS服務器
#查看是否支持,若存在該目錄則支持
ll /proc/sys/fs/inotify
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify-3.14
make
make install
#生成SSH KEY
ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/
scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/
#客戶機
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
service sshd restart
#NFS服務器端
#編寫腳本
mkdir /data/shell
vim /data/shell/inotifyrsync.sh
#腳本內容詳見inotifyrsync.sh文件內
chmod +x /data/shell/inotifyrsync.sh
#將腳本放至後臺運行
nohup /data/shell/inotifyrsync.sh &
#使腳本開機自動運行
echo "/data/shell/inotifyrsync.sh &" >> /etc/rc.local


=======nginx添加IP庫=====
yum install *GeoIP*

tar zxvf GeoIP-1.4.8.tar.gz
cd GeoIP-1.4.8
./configure
make;make install
#編譯nginx的擴展
cd nginx-1.2.3
./configure --user=www --group=www --prefix=/usr/local/nginx-1.2.3 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module  --with-pcre --with-http_geoip_module
make;make install

gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz
mv GeoIP.dat /usr/local/nginx-1.2.3/conf/
mv GeoLiteCity.dat /usr/local/nginx-1.2.3/conf/
vim  /usr/local/nginx-1.2.3/conf/nginx.conf
在http中追加
    geoip_country  GeoIP.dat;
    geoip_city     GeoLiteCity.dat;

在server中追加
if ( $http_cookie !~* PL_IPCITY ) {
    add_header Set-Cookie "PL_IPCITY=$geoip_city;Domain=.pinla.com;Path=/" ;  
}
fastcgi_param PL_IPCITY $geoip_city;

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