生产环境编译安装LNMP / LNMP一键安装脚本

  • A+
所属分类:系统运维

%ignore_pre_1%

 

生产环境:  (单击下面的服务名称即可下载)
操作系统:centos-6.6-64位最小化安装
软件版本:nginx-1.9.4(提供web服务)   mysql-5.6.26(提供数据库服务)    php-5.5.28(提供PHP运行环境)
约定:所有软件均安装在 /APP/ 下,mysql数据文件 /data/mysql_db ,web目录 /data/web/

 

1、编译安装Mysql

# yum -y install ncurses* cmake bison* openssl* gcc gcc-c++
安装编译mysql时需要的依赖包

# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26.tAR.gz
下载mysql安装包

# groupadd mysql && useradd -g mysql mysql -s /sbin/nologin
创建Mysql组和用户 设置不允许登陆系统

# mkdir -p /data/mysql_db
建立mysql数据库存放目录

# chown -R mysql:mysql /data/mysql_db
设置mysql数据库目录权限

# tAR zxvf mysql-5.6.26.tAR.gz && cd mysql-5.6.26
解压mysql包

# cmake . -DCMAKE_iNSTALL_PREFiX=/APP/mysql /
-DMYSQL_DATADiR=/data/mysql_db /
-DSYSCONFDiR=/etc /
-DWiTH_MYiSAM_STORAGE_ENGiNE=1 /
-DWiTH_iNNOBASE_STORAGE_ENGiNE=1 /
-DWiTH_MEMORY_STORAGE_ENGiNE=1 /
-DWiTH_READLiNE=1 /
-DMYSQL_UNiX_ADDR=/data/mysql_db/mysql.sock /
-DMYSQL_TCP_PORT=3306 /
-DENABLED_LOCAL_iNFiLE=1 /
-DWiTH_PARTiTiON_STORAGE_ENGiNE=1 /
-DEXTRA_CHARSETS=all /
-DDEFAULT_CHARSET=utf8 /
-DDEFAULT_COLLATiON=utf8_general_ci /
-DWiTH_FEDERATED_STORAGE_ENGiNE=1 /
-DWiTH_ARCHiVE_STORAGE_ENGiNE=1 /
-DWiTH_BLACKHOLE_STORAGE_ENGiNE=1 /
-DWiTH_SSL=yes
执行Cmake编译Mysql指定安装目录,数据存放目录,配置文件存放目录,出现如下语句说明cmake成功
生产环境编译安装LNMP / LNMP一键安装脚本
# make && make install
执行编译安装
生产环境编译安装LNMP / LNMP一键安装脚本
配置Mysql:

# vim /etc/my.cnf
新建mysql配置文件,增加下面配置项

===============================

[client]
port = 3306
socket = /data/mysql_db/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /data/mysql_db/mysql.sock
pid-file=/data/mysql_db/mysql.pid
basedir = /APP/mysql/
datadir = /data/mysql_db
open_files_limit = 51200
back_log = 600
table_open_cache = 4096
max_connections = 3000
max_connect_errors = 6000
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 128M
query_cache_limit = 4M
thread_stack = 512K
transaction_isolation = READ-COMMiTTED
tmp_table_size = 256M
max_heap_table_size = 256M
long_query_time = 10
slow_query_log = 5
slow_query_log_file = /data/log/mysql_slow-log.log
log_queries_not_using_indexes=1
log_bin=/data/mysql_db/mysql-binlog
binlog_format=mixed
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 32M
read_buffer_size = 8M
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
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M
innodb_data_file_path = ibdata1:1024M: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 = 0
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
open-files-limit = 8192
log-error=/data/mysql_db/mysql.err

===============================

# /APP/mysql/scripts/mysql_install_db /
--user=mysql /
--datadir=/data/mysql_db /
--basedir=/APP/mysql
初始化mysql系统数据库

# cp /APP/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# vim /etc/rc.d/init.d/mysqld  修改下面两项目录配置
    basedir=/APP/mysql   datadir=/data/mysql_db
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig mysqld on
把mysql加入系统服务,赋予执行权限,并设置为开机启动

# service mysqld stARt
启动mysql

生产环境编译安装LNMP / LNMP一键安装脚本

# ln -s /APP/mysql/bin/* /usr/bin
将mysql所有命令链接到系统环境变量中

命令行输入mysql ,进入mysql数据库
生产环境编译安装LNMP / LNMP一键安装脚本

Mysql配置结束

 

 

2、编译安装Nginx

# yum -y install zlib* pcre* lua-devel
安装编译Nginx时需要的依赖包

# wget http://mirrors.sohu.com/nginx/nginx-1.9.4.tAR.gz
下载Nginx安装包

# groupadd www && useradd -g www www -s /sbin/nologin
创建Nginx组和用户,设置不允许登陆系统

# tAR zxvf nginx-1.9.4.tAR.gz  && cd nginx-1.9.4
解压Nginx包

./configure --prefix=/APP/nginx /
--sbin-path=/APP/nginx/sbin/nginx /
--conf-path=/APP/nginx/conf/nginx.conf /
--user=www /
--group=www /
--with-pcre /
--with-file-aio /
--with-poll_module /
--with-http_ssl_module /
--with-http_realip_module /
--with-http_stub_status_module /
--with-http_sub_module /
--with-http_gzip_static_module /
--with-http_dav_module /
--with-http_flv_module /
--with-http_mp4_module /
--with-http_spdy_module /
--with-http_sub_module /
--with-http_dav_module /
--without-http_uwsgi_module /
--without-http_scgi_module /
--http-log-path=/data/logs/nginx/access.log /
--error-log-path=/data/logs/nginx/error.log /
--http-client-body-temp-path=/tmp/nginx/client-body-temp /
--http-proxy-temp-path=/tmp/nginx/proxy-temp /
--http-fastcgi-temp-path=/tmp/nginx/fastcgi-temp

执行./coonfigure对nginx进行配置以及检测当前环境是否满足安装需求,出现下图说明./configure通过

生产环境编译安装LNMP / LNMP一键安装脚本

# make && make install 
编译安装Nginx

# mkdir -p /tmp/nginx/client-body-temp
创建缓存目录

# /APP/nginx/sbin/nginx
启动nginx,浏览器访问web服务器ip 看是否启动成功。成功界面如下:

生产环境编译安装LNMP / LNMP一键安装脚本

# vim /etc/rc.d/init.d/nginx
为nginx提供开机启动脚本,复制以下内容到服务文件中

===============================

#!/bin/bash
# nginx StARtup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# it has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /APP/nginx/logs/nginx.pid
# config: /APP/nginx/conf/nginx.conf
nginxd=/APP/nginx/sbin/nginx
nginx_config=/APP/nginx/conf/nginx.conf
nginx_pid=/APP/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function librARy.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKiNG} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# StARt nginx daemons functions.
stARt() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"StARting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /vAR/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo#
[ $RETVAL = 0 ] && rm -f /vAR/lock/subsys/nginx /APP/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
test() {
$nginxd -t
}
# See how we were called.
case "$1" in
test)
test
;;
stARt)
stARt
;;
stop)
stop
;;
reload)
reload
;;
restARt)
stop
stARt
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {stARt|stop|restARt|reload|status|help|test}"
exit 1
esac
exit $RETVAL

===============================

# chmod 755 /etc/rc.d/init.d/nginx
# chkconfig nginx on
赋予Nginx执行权限,并设置为开机启动

生产环境编译安装LNMP / LNMP一键安装脚本

Nginx配置结束

 

3、编译安装PHP

# yum -y install gd-devel curl-devel libxml2-devel bzip2-devel /
libxpm-devel libXpm mbstring exif libicu-devel libmcrypt-devel /
php-mcrypt bzip2* libjpeg* libpng* freetype*
安装编译PHP时需要的依赖包

# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tAR.gz
下载PHP依赖的libmcrypt加密算法扩展库

# wget http://mirrors.sohu.com/php/php-5.5.28.tAR.gz
下载PHP安装包

# tAR zxvf libmcrypt-2.5.7.tAR.gz && cd libmcrypt-2.5.7
解压libmcrypt包

# ./configure && make && make install
编译安装libmcrypt

# tAR zxvf php-5.5.28.tAR.gz && cd php-5.5.28
解压PHP包

./configure /
--prefix=/APP/php5.5 /
--sysconfdir=/APP/php5.5/etc /
--with-config-file-path=/APP/php5.5/etc /
--with-config-file-scan-dir=/APP/php5.5/etc/conf.d /
--enable-maintainer-zts /
--enable-phpdbg /
--enable-fpm /
--with-fpm-user=www /
--with-fpm-group=www /
--with-zend-vm=GOTO /
--enable-inline-optimization /
--disable-debug /
--disable-short-tags /
--without-peAR /
--enable-bcmath /
--with-mysql=mysqlnd /
--with-mysqli=mysqlnd /
--with-pdo-mysql /
--without-pdo-sqlite /
--disable-ipv6 /
--with-curl /
--enable-ftp /
--enable-sockets /
--with-openssl /
--with-bz2 /
--with-zlib /
--with-zlib-dir /
--enable-zip /
--enable-json /
--with-iconv /
--with-iconv-dir /
--with-pcre-regex /
--with-pcre-dir /
--enable-mbstring /
--enable-mbregex /
--with-gettext /
--with-mcrypt /
--with-mhash /
--disable-calendAR /
--enable-gd-jis-conv /
--with-gd /
--with-freetype-dir /
--with-jpeg-dir /
--with-png-dir /
--enable-gd-native-ttf /
--enable-exif /
--enable-xml /
--with-libxml-dir /
--enable-soap /
--disable-xmlwriter /
--disable-xmlreader /
--enable-sysvsem /
--enable-sysvmsg /
--enable-shmop /
--enable-sysvshm /
--enable-pcntl /
--disable-flatfile /
--enable-fd-setsize=4096 /
--enable-intl /
--with-xpm-dir

执行./coonfigure对PHP进行配置以及检测当前环境是否满足安装需求,出现下图说明./configure通过

生产环境编译安装LNMP / LNMP一键安装脚本

# make && make install
编译安装PHP

配置PHP

# vim /APP/php5.5/etc/php.ini
创建php.ini 配置文件,并写入以下内容

===============================

[PHP]
engine = On
short_open_tag = ON
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,proc_close,
proc_get_status,proc_nice,proc_terminate,php_uname,posix_getpwuid,posix_kill,
posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_setuid,posix_uname,
syslog,pARse_ini_file,eval,apache_child_terminate,apache_setenv,
define_syslog_vARiables,escapeshellARg,escapeshellcmd,show_source
disable_classes =
zend.enable_gc = On
expose_php = OFF
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_ NOTiCE & ~E_STRiCT
display_errors = off
display_stARtup_errors = Off
log_errors = On
log_errors_max_len = 1024
error_log=/data/logs/php/php-error.log
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
vARiables_order = "GPCS"
request_order = "GP"
register_ARgc_ARgv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_APPend_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLi Server]
cli_server.color = On
[Date]
date.timezone = PRC
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[PhAR]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCi8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSiD
session.auto_stARt = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_chARacter = 5
url_rewriter.tags = "a=href,ARea=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatibility_mode = Off
mssql.secure_connection = Off
[Assertion]
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[opcache]
[curl]

===============================

# vim /APP/php5.5/etc/php-fpm.conf
新建php-fpm配置文件,并写入以下内容

===============================

[global]
pid = /APP/php5.5/bin/php-fpm.pid
log_level = notice
error_log = /data/logs/php/php-error.log

[www]
catch_workers_output = yes
user = www
group = www
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.stARt_servers = 5
pm.min_spARe_servers = 2
pm.max_spARe_servers = 8
pm.max_requests = 512
request_slowlog_timeout = 8s
slowlog = /data/logs/php/php5.5-slow.log

===============================

# mkdir -p /data/logs/php
创建php日志存放目录

# /APP/php5.5/sbin/php-fpm
启动php

PHP配置结束

 

4、配置nginx支持php

# vim /APP/nginx/conf/nginx.conf
修改nginx配置文件,将一下行写入到nginx.conf

=======================================
user www;
worker_processes auto;
worker_rlimit_nofile 51200;
error_log /data/logs/nginx/error.log crit;
pid /APP/nginx/logs/nginx.pid;
events
{
use epoll;
worker_connections 51200;
}
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 64k;
client_max_body_size 8m;
sendfile on;
server_tokens off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 512k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 4;
gzip_types text/plain APPlication/javascript APPlication/x-javascript text/css;
gzip_vARy on;
gzip_disable "MSiE [1-6]."
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwARded_for';
include host/*.host;
}
=======================================

# mkdir /APP/nginx/conf/host
创建网站server文件存放目录

# vim /APP/nginx/conf/host/local.host
创建server文件

===============================

server {
listen 80;
server_name 127.0.0.1;
index index.shtml index.html index.php;
root /data/web/;
access_log /data/logs/nginx/www.access.log;
location ~ .*/.php$ {
include fastcgi-php5.5.conf;
}
}

===============================

# vim /APP/nginx/conf/fastcgi-php5.5.conf
创建fastcgi配置文件

===============================

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
client_max_body_size 8m;
client_body_buffer_size 128k;
fastcgi_pARam GATEWAY_iNTERFACE CGi/1.1;
fastcgi_pARam SERVER_SOFTWARE nginx;
fastcgi_pARam QUERY_STRiNG $query_string;
fastcgi_pARam REQUEST_METHOD $request_method;
fastcgi_pARam CONTENT_TYPE $content_type;
fastcgi_pARam CONTENT_LENGTH $content_length;
fastcgi_pARam SCRiPT_FiLENAME $document_root$fastcgi_script_name;
fastcgi_pARam SCRiPT_NAME $fastcgi_script_name;
fastcgi_pARam REQUEST_URi $request_uri;
fastcgi_pARam DOCUMENT_URi $document_uri;
fastcgi_pARam DOCUMENT_ROOT $document_root;
fastcgi_pARam SERVER_PROTOCOL $server_protocol;
fastcgi_pARam REMOTE_ADDR $remote_addr;
fastcgi_pARam REMOTE_PORT $remote_port;
fastcgi_pARam SERVER_ADDR $server_addr;
fastcgi_pARam SERVER_PORT $server_port;
fastcgi_pARam SERVER_NAME $server_name;
fastcgi_pARam REDiRECT_STATUS 200;

===============================

# mkdir /data/web
创建网站根目录

# echo "<?phpinfo()?>" >> /data/web/index.php
创建phpinfo 测试文件
重新启动nginx,访问web服务器

至此LNMP环境安装完成

生产环境编译安装LNMP / LNMP一键安装脚本

LNMP一键安装包:http://yunpan.cn/cmcwDgujq6g5G (提取码:5418)

欢迎在下方对本文提出意见或建议,小白会第一时间回复您。

 

版权属于:
小白的运维站

原文地址:
http://www.52yunwei.cn/?p=241

转载时必须以链接形式注明原始出处及本声明。




该文章由WP-AutoPost插件自动采集发布

原文地址:http://www.52yunwei.cn/?p=241

weinxin
我的微信
这是我的微信

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: