日期:2012-03-11 14:47:00 来源:本站整理
CentOS下nginx、resin、memcached整合[Linux安全]
本文“CentOS下nginx、resin、memcached整合[Linux安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
因公司运营环境需求,需求nginx、resin整合,nginx负责处理静态部份,resin负责处理动态部份
系统环境:CentOS 5.6 X64
#安装常用组件
yum -y install gcc gcc-c++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel 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 libidn libidn-devel openldap \
openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel bison
#---------------------------- 利用cmake编译安装mysql ----------------------------------
#利用Tcmalloc 优化nginx、mysql
#64位操作系统请先安装 libunwind库,32位操作系统不要安装.libunwind库为基于64位CPU和操作系统的程序供应了基本的仓库辗转开解功效,此中包含用于输出仓库跟踪的API、用于以编程方法辗转开解仓库的API以及支持C++非常处理机制的API
/opt
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
tar -zxvf libunwind-0.99.tar.gz
./configure
make
make install
cd /opt
tar -zxvf 谷歌-perftools-1.7.tar.gz
cd 谷歌-perftools-1.7/
./configure
make;make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
cd ../
tar -zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./bootstrap
gmake
gmake install
cd ../
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql -s /sbin/nologin
mkdir -p /data/mysql/{data,binlog,relaylog,mysql}
chown -R mysql:mysql /data/mysql
cd /opt
tar zxvf mysql-5.5.13.tar.gz
cd mysql-5.5.13/
rm -rf CMakeCache.txt
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_TCP_PORT=3306
make;make install
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
#编辑mysql配置文件
vi /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
character_set_server = utf8
collation-server = utf8_general_ci
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /data/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql/data
log-error = /data/mysql/mysql_error.log
pid-file = /data/mysql/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 6M
join_buffer_size = 8M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 256K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
long_query_time = 3
log-slave-updates
log-bin = /data/mysql/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 100M
relay-log-index = /data/mysql/relaylog/relaylog
relay-log-info-file = /data/mysql/relaylog/relaylog
relay-log = /data/mysql/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 384M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 100G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip_external_locking
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306
server-id = 1
skip-innodb
log-slow-queries = /data/mysql/slow.log
long_query_time = 2
[mysqldump]
quick
max_allowed_packet = 32M
#初始化mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
#操纵TCMalloc提高mysql在高并发下的性能
vi /usr/local/mysql/bin/mysqld_safe
#在# executing mysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
#利用lsof号令查看tcmalloc能否起效
/usr/sbin/lsof -n | grep tcmalloc
#设置mysql启动文件
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql/data
chmod 700 /etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqld start
/sbin/chkconfig --add mysqld
/sbin/chkconfig --level 2345 mysqld on
ln -s /usr/local/mysql/bin/mysql /sbin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
#设置root密码(753951)
/sbin/mysqladmin -u root password 753951
#/usr/local/mysql/bin/mysqladmin -u root -p password 456 --改正root已设置好的密码
#配置库文件搜索途径
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
/sbin/ldconfig
#增添/usr/local/mysql/bin到环境变量PATH中
export PATH=$PATH:/usr/local/mysql/bin
#增添mysql管理帐户
#mysql -h localhost -u root -p753951
#msqyl> use mysql;
#msqyl> grant all on *.* to 'kerry'@'192.168.9.100' identified by '852741';
#msqyl> flush privileges;
#msqyl> exit;
#---------------------------- 安装resin、JDK -------------------------#
cd /opt
mv jdk-6u29-linux-x64.bin /usr/local/
#设置环境变量
cat >>/etc/profile<<EOF
export JAVA_HOME=/usr/local/jdk1.6.0_25
export CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
EOF
source /etc/profile
#查看java版本
java -version
tar -zxvf resin-4.0.26.tar.gz
cd resin-4.0.26
./configure --prefix=/usr/local/resin
make;make install
#启动resin
/usr/local/resin/bin/resin.sh start
#设置resin开机启动
cp -r init.d/resin /etc/init.d/resin
chmod +x /etc/init.d/resin
/sbin/chkconfig --add resin
/sbin/chkconfig --level 2345 resin on
#---------------------------- 安装nginx ------------------------------#
cd /opt
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www -s /sbin/nologin
mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12/
./configure
make;make install
cd ../
tar -zxvf nginx-1.0.13.tar.gz
cd nginx-1.0.13
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-谷歌_perftools_module
make;make install
cd ../
mkdir -p /data/logs
chmod +w /data/logs
chown -R www:www /data/logs
#编辑nginx配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
cat >>/usr/local/nginx/conf/nginx.conf<<EOF
user www www;
worker_processes 8;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#利用Tcmalloc优化nginx性能
谷歌_perftools_profiles /var/tmp/tcmalloc;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
#工作情势及衔接数上限
events
{
use epoll;
worker_connections 65535;
}
#设定http服务器,操纵它的反向代理功效供应负载均衡支持
http
{
#设定mime范例
include mime.types;
default_type application/octet-stream;
#charset gb2312;
#设定恳求缓冲
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#设置客户端可以上传文件大小的限制
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# 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;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
###禁止通过ip拜候站点
server{
server_name _;
return 404;
}
server
{
listen 80;
server_name www.king.com;
index index.html index.htm index.jsp index.do;#设定拜候的默许首页地
以上是“CentOS下nginx、resin、memcached整合[Linux安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论