1、安装nginx。
nginx-1.4.5。下载地址:
http://nginx.org/download/nginx-1.4.5.tar.gz
(安装之前需要确认是否已经存在pcre,如果没有直接yum安装。)
groupadd www #添加www组
useradd -s /sbin/nologin -g www www #添加www至www组,并设置不能登陆
开始安装:
nginx-1.4.5/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
解决:yum -y install pcre-devel
报错:./configure: error: SSL modules require the OpenSSL library.
解决:yum -y install openssl openssl-devel
#配置完成后
make && make install
3、创建Nginx日志目录
mkdir -p /home/nginx/logs
chmod +w /home/nginx/logs
chown -R www:www /home/nginx/logs
4、创建Nginx配置文件
①、在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/nginx/conf/nginx.conf
vi /usr/local/nginx/conf/nginx.conf
输入以下内容:
引用
user www www;
worker_processes 8;
error_log /home/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
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 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
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.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler$binary_remote_addr10m;
log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /home/nginx/logs/wwwlogs.log wwwlogs;
server
{
listen 80;
server_name www;
index index.html index.htm index.php;
root /home/htdocs/www;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
}
}
2、编译安装MySQL
mkdir -p /home/mysql/3306/data/
mkdir -p /home/mysql/3306/binlog/
mkdir -p /home/mysql/3306/relaylog/
把mysql加入mysql组
/usr/sbin/usermod -G mysql mysql
报错:usermod:用户 mysql 不存在
/usr/sbin/useradd mysql -s /sbin/nologin
chown -R mysql:mysql /home/mysql/
解压mysql
tar zxvf mysql-5.5.11-linux2.6-x86_64.tar.gz
移动到/usr/local/ 并重命名为mysql
mv mysql-5.5.11-linux2.6-x86_64 /usr/local/mysql
如果报错:/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 可能是libaio.so.1相关的包没安装 yum install libaio |
vi /home/mysql/3306/my.cnf
我的配置是:
[client]
character-set-server = utf8
port = 3306
socket = /tmp/mysql3306.sock
[mysqld]
event_scheduler = 1
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
#replicate-ignore-table = yccms.YcLog
user = mysql
port = 3306
socket = /tmp/mysql3306.sock
basedir = /usr/local/mysql
datadir = /home/mysql/3306/data
log-error = /home/mysql/3306/mysql_error.log
pid-file = /home/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
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 = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
#log-bin = /home/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /home/mysql/3306/relaylog/relaylog
relay-log-info-file = /home/mysql/3306/relaylog/relaylog
relay-log = /home/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 250
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 1
[mysqldump]
quick
max_allowed_packet = 32M
vi /home/mysql/3306/mysql
我的配置是:
#!/bin/sh
mysql_port=3306
mysql_username="admin"
mysql_password="12345678"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql${mysql_port}.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /home/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi
⑤、赋予shell脚本可执行权限:
chmod +x /home/mysql/3306/mysql
⑥、启动MySQL:
/home/mysql/3306/mysql start
⑦、通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql3306.sock
⑧、输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'jindiao4'@'%' IDENTIFIED BY 'jindiao4pwd'; //创建的账号密码用于外网登陆
⑨、(可选)停止MySQL:
/home/mysql/3306/mysql stop
3、安装PHP
下载php,下载链接:
http://us1.php.net/get/php-5.3.28.tar.gz/from/this/mirror
。
安装php前要先安装好依赖包,直接yum安装比较快:
yum -y install gd
yum -y install libxml2.x86_64
yum -y install libxml2-devel.x86_64
tar zxvf php-5.3.28.tar.gz
cd php-5.3.28
#这些扩展根据需要选择安装。如果是基于nginx+php-fpm的,--enable-fpm 一定要写上
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --enable-mbstring --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --enable-zip --enable-sockets --with-mhash --enable-fpm
#配置成功后开始编译安装
make&& makeinstall
cp php.ini-production /usr/local/php/etc/php.ini
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
修改以下内容:
vim php-fpm.conf
[www]
listen 127.0.0.1:9000 #设置接受请求的地址,在nginx.conf中会用到
listen.allowed_clients 127.0.0.1 #设允许连接到php-fpm的ip,每个地址是用逗号分隔.
listen.owner www #设置监听的用户
listen.group www #设置监听的组
listen.mode 0666 #设置Unix套接字的权限,读写权限必须设置
user www #进程运行的用户
group www #进程运行的用户组
pm dynamic #进程启动方式设置。可用值: static, dynamic
pm.max_children 15 #子进程的数量,pm设置为static时表示启动的进程数。pm设置为dynamic时表示最大进程数
pm.start_servers 15 #启动时的进程数。仅在pm设置为dynamic时使用。
pm.min_spare_servers 5 #最小进程数.仅在pm设置为dynamic时使用
pm.max_spare_servers 15 #最大进程数.仅在pm设置为dynamic时使用
pm.max_requests 500 #设置每个子进程重生之前服务的请求数.设置为 '0' 则一直接受请求.
#pm dynamic时进程计算公式:min_spare_servers+(max_spare_servers-min_spare_servers)/2
按照这个原则去配置
min_spare_servers ≤ start_servers ≤ max_spare_servers ≤ max_children
php-fpm简单配置结束,启动服务:
/var/app/php/php-fpm