一、环境
系统:Red Hat Enterprise Linux Server release 6.4
所需软件包:
nginx-1.6.3.tar.gz
mysql-5.5.41.tar.gz
mysql-5.5.41.tar.gz
libiconv-1.14.tar.gz
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
libevent-1.4.14b-stable.tar.gz
memcached-1.4.24.tar.gz
二、安装
1、nginx的安装
1)、编译安装
sduo groupadd nginx
sudo useradd -s /sbin/nologin -g nginx nginx
sudo yum -y install pcre* openssl*
tar zxf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure \
--prefix=/usr/local/services/nginx-1.6.3 \
--sbin-path=/usr/local/services/nginx-1.6.3/sbin/nginx \
--conf-path=/usr/local/services/nginx-1.6.3/conf/nginx.conf \
--error-log-path=/usr/local/services/nginx-1.6.3/logs/error.log \
--pid-path=/usr/local/services/nginx-1.6.3/logs/nginx.pid \
--lock-path=/usr/local/services/nginx-1.6.3/logs/nginc.lock \
--http-fastcgi-temp-path=/usr/local/services/nginx-1.6.3/fastcgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
make&&make install
2)启动nginx服务
cd /usr/local/services
ln -sf nginx-1.6.3 nginx
sudo ./nginx/sbin/nginx
sudo netstat -antlp|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4690/nginx
2、mysql的安装
1)、编译安装
sudo groupadd mysql
sudo useradd -s /sbin/nologin -g mysql mysql
sudo yum -y install ncurses-devel gcc gcc-c++ bison cmake
tar zxf mysql-5.5.41.tar.gz
cd mysql-5.5.41
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/services/mysql5.5.41 \
-DMYSQL_DATADIR=/usr/local/services/mysql5.5.41/var/data \
-DMYSQL_UNIX_ADDR=/usr/local/services/mysql5.5.41/var/data/mysql.sock \
-DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all -DWITH_DEBUG=0 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1
_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1
make&&make install
2)创建编译时所用目录,及常用命令链接
cd /usr/local/services/
ln -sf mysql5.5.41 mysql
cd mysql
sudo chown -R mysql.mysql ./*
sudo mkdir -p /data/tsp/mysql
ln -s /data/tsp/mysql var
sudo mkdir -p /usr/local/services/mysql/var/{binlog,data,logs,redolog,relaylog}
sudo ln -sf /usr/local/services/mysql/bin/mysql /usr/local/bin/
sudo ln -sf /usr/local/services/mysql/bin/mysqldump /usr/local/bin/
sudo ln -sf /usr/local/services/mysql/bin/mysqlbinlog /usr/local/bin/
sudo ln -sf /usr/local/services/mysql/bin/mysqladmin /usr/local/bin/
sudo ln -sf /usr/local/services/mysql/include/ /usr/include/mysql
sudo chown -R mysql.mysql /usr/local/services/mysql/var
3)初始化
sudo vim /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/local/services/mysql/lib
sudo ldconfig -v
sudo scripts/mysql_install_db --user=mysql --datadir=/usr/local/services/mysql/var/data --basedir=/usr/local/services/mysql
4)服务开机启动,获取配置文件
cd support-files/
sudo cp mysql.server /etc/init.d/mysqld
sudo chmod +x /etc/init.d/mysqld
sudo chkconfig --add mysqld
sudo chkconfig mysqld on
sudo cp my-medium.cnf my.cnf
5)编辑配置文件
sudo chown user.group /etc/my.cnf
vim /etc/my.cnf
[client]
port = 3306
socket = /usr/local/services/mysql/var/data/mysql.sock
[mysqld]
bind-address = 0.0.0.0
port = 3306
socket = /usr/local/services/mysql/var/data/mysql.sock
pid-file = /usr/local/services/mysql/var/logs/mysql.pid
character-set-server = utf8
basedir = /usr/local/services/mysql
datadir = /usr/local/services/mysql/var/data
skip-external-locking
skip-name-resolve
lower_case_table_names = 1
log-bin-trust-function-creators = 1
max_connections = 6000
max_user_connections = 6000
max_connect_errors = 4000
wait_timeout = 86400
interactive_timeout = 86400
table_open_cache = 512
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 32M
#default-storage-engine = InnoDB
#sql_mode="STRICT_ALL_TABLES,NO_AUTO_CREATE_USER"
server-id = 1
log-short-format
log-error = /usr/local/services/mysql/var/logs/mysql.log
slow_query_log
long_query_time = 2
slow_query_log_file = /usr/local/services/mysql/var/logs/mysql-slow.log
log-bin = /usr/local/services/mysql/var/binlog/mysql-bin
log_bin_trust_function_creators=1
binlog_format = MIXED
expire_logs_days = 10
# INNODB Specific options
innodb_data_home_dir = /usr/local/services/mysql/var/data
innodb_log_group_home_dir = /usr/local/services/mysql/var/redolog
innodb_additional_mem_pool_size = 10M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:100M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 128M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 50
innodb_file_per_table = 1
# MyISAM Specific options
key_buffer_size = 384M
read_buffer_size = 4M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
myisam_recover
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
default-character-set = utf8
no-auto-rehash
socket = /usr/local/services/mysql/var/data/mysql.sock
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
6)启动mysql
sudo service mysqld start
Starting MySQL. [ OK ]
3、安装PHP的扩展插件
1)、安装libiconv
对文本进行编码间的转换,用它来处理中文各种编码之间的转换
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/services/libiconv-1.14
make&& make install
2)、安装libmcrypt 实现加密功能的库
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/services/libmcrypt-2.5.8
make&&make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
3)、安装mhash
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local/services/mhash-0.9.9.9
make&& make install
4)、对库文件做链接
sudo ln -sf /usr/local/services/libmcrypt-2.5.8/lib/libmcrypt* /usr/local/lib
sudo ln -sf /usr/local/services/mhash-0.9.9.9/lib/libmhash.* /usr/local/lib
sudo ln -sf /usr/local/services/libmcrypt-2.5.8/include/mcrypt.h /usr/include/mcrypt.h
sudo ldconfig -v
4、安装PHP
1)、编译安装
sudo yum -y install libxml2* libcurl* libjpeg* libpng* freetype* openldap*
sudo cp -frp /usr/lib64/libldap* /usr/lib/
tar zxf php-5.5.30.tar.gz
cd php-5.5.30
./configure \
--prefix=/usr/local/services/php-5.5.30 \
--with-config-file-path=/usr/local/services/php-5.5.30/etc \
--with-mysql=/usr/local/services/mysql \
--with-mysqli=/usr/local/services/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local/services/libiconv-1.14 \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--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
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/services/php/etc/php.ini
2)、配置
cd /usr/local/services/
ln -sf php-5.5.30 php
cd php/etc
cp php-fpm.conf.default php-fpm.conf
sudo groupadd www
sudo useradd -g www www
vim php-fpm.conf
[global]
pid=run/php-fpm.pid
error_log=log/php-fpm.log
log_level=error
daemonize=yes
[www]
user=www
group=www
listen=127.0.0.1:9000
pm=dynamic
pm.max_children=32
pm.start_servers=15
pm.min_spare_servers=5
pm.max_spare_servers=32
3)、启动PHP服务
cd php-5.5.30/sapi/fpm
sudo cp init.d.php-fpm /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm
sudo chkconfig --add php-fpm
sudo chkconfig php-fpm on
/etc/init.d/php-fpm start
ps -ef|grep php
4)、编辑nginx
vim /usr/local/services/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
5)、编译fastcgi_params
加入一行fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
vim /usr/local/services/nginx/conf/fastcgi_params
5、重启服务,进行测试
sudo /usr/local/services/nginx/sbin/nginx -s reload
/etc/init.d/php-fpm restart
vim /usr/local/services/nginx/html/index.php
<?php
phpinfo();
?>
测试数据库链接正常否
vim /usr/local/services/nginx/html/linkdb.php
<?php
$links=mysql_connect("localhost","root","");
if($links){
echo "link db ok!";
}
else{
echo "link db no!";
}
?>
6、memcached安装
1)
tar xf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/services/libs/libevent-1.4.14b
make
make install
cd /usr/local/services/libs/
test ! -h /usr/local/services/libs/libevent && ln -s libevent-1.4.14b libevent
tar xf memcached-1.4.24.tar.gz
cd memcached-1.4.24
./configure --prefix=/usr/local/services/memcached-1.4.24 --with-libevent=/usr/local/services/libs/libevent
make
make install
启动memcached
/memcached -l "192.168.9.87" -p 11211 -d -m 256 -c 65536 -d
2)
使用php自带的pecl安装程序
# /usr/local/services/php/bin/pecl install memcache
vim /usr/local/services/php/etc/php.ini 增加两行
extension_dir = "/usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20060922/"
extension="memcache.so"
sudo /etc/init.d/php-fpm restart
验证 vim /usr/local/services/nginx/html/test.php
<?php
$memcache = new Memcache;
$memcache->connect('192.168.10.35', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";
var_dump($get_result);
?>
显示结果:
Server's version: 1.4.24
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }
7、部署discuz
discuz防止路径为:/usr/local/services/bbs
vim nginx.conf
location ^~ /bbs/ {
root /usr/local/services;
fastcgi_split_path_info ^(.+\.php)(.*)$;
if ( $fastcgi_script_name ~ \..*\/.*php ) {
return 403;
}
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
if ( $fastcgi_script_name ~ .*\.php($|/) ) {
fastcgi_pass 127.0.0.1:9000;
add_header Cache-Control "no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0";
add_header Pragma no-cache;
}
}
访问http://ip/bbs/install
根据提示就行设置
至此论坛就部署OK啦