标签:centos7 lnmp
系统环境
最小化安装64位Centos7.1(已安装开发工具包)
部分安装包下载地址
wget http://ncu.dl.sourceforge.net/project/re2c/re2c/0.14.2/re2c-0.14.2.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz/from/http://cdn.mysql.com/
源码包存放目录
/usr/local/src
安装NGIX及PHP相关依赖包
yum install cmake
yum install zlib-devel pcre-devel openssl-devel ncurses-devel flex-devel bison-devel libxml2-devel libpng-devel freetype-devel libcurl-devel gd-devel
yum install glibc-devel glib2-devel bzip2-devel gdbm-devel dbus-devel gmp-devel readline-devel libxslt-devel xmlrpc-c xmlrpc-c-devel libvpx-devel libtool-libs libtool-ltdl-devel
添加NGINX及MYSQL用户
groupadd vmail -g 1001
useradd vmail -u 1001 -g 1001 -M -s /bin/false
groupadd mysql -g 1100
useradd mysql -u 1100 -g 1001 -M -s /sbin/nologin
安装内存管理优化工具
tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1
./configure
make
make install
tar zxvf gperftools-2.1.tar.gz
cd gperftools-2.1
./configure --enable-frame-pointers
make
make install
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig -v
安装NGINX
mkdir /var/tmp/nginx
chown vmail:vmail /var/tmp/nginx/
tar zxvf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure --prefix=/usr/local/nginx \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--lock-path=/var/lock/subsys/nginx.lock \
--user=vmail --group=vmail \
--with-http_ssl_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-debug \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-google_perftools_module
make &&make install
配置NGINX支持内存管理优化
mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc/
vi /usr/local/nginx/conf/nginx.conf
google_perftools_profiles /tmp/tcmalloc;
user vmail;
创建NGINX启动脚本
vi /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-
reload|configtest}"
exit 2
esac
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
chown vmail:vmail -R /usr/local/nginx/logs/
service nginx start
防火墙开启80端口
vi /etc/firewalld/zones/public.xml
在<zone>下添加如下行:
<service name="http"/>
firewall-cmd --reload
安装MYSQL
安装前先设置好主机名
vi /etc/hostname
主机名
mkdir -p /data/mysql
chown mysql:mysql -R /data/
chmod 750 -R /data/
tar zxvf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=gbk \
-DDEFAULT_COLLATION=gbk_chinese_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_TCP_PORT=3306
make && make install
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
rm -f /etc/my.cnf
chkconfig --add mysqld
chkconfig mysqld on
cd /data/mysql
openssl genrsa -out mykey.pem 1024
openssl rsa -in mykey.pem -pubout -out mykey.pub
chmod 400 mykey.pem
chmod 444 mykey.pub
chown mysql:mysql mykey.*
vi /use/local/mysql/my.cnf
[mysqld]
federated //解决MySQL Plugin ‘FEDERATED‘ is disabled 错误
innodb_buffer_pool_size = 128M
log_bin = /data/mysql/log/bin.log
expire_logs_days = 30
sync_binlog = 1
log-error=/data/mysql/log/error.log
general_log=1
general_log_file=/data/mysql/log/mysql.log
slow_query_log=1
slow_query_log_file=/data/mysql/log/slowquery.log
log-output=FILE
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
explicit_defaults_for_timestamp=true //解决TIMESTAMP with implicit DEFAULT value is deprecated.错误
sha256_password_private_key_path=mykey.pem //解决RSA private key file not found: /data/mysql//private_key.pem. Some authentication plugins will not work.
sha256_password_public_key_path=mykey.pub
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
service mysqld start
/usr/local/mysql/bin/mysqladmin -u root password 123456
/usr/local/mysql/bin/mysql -u root -p
mysql> grant all privileges on *.* to root@‘%‘ identified by ‘123456‘ with grant option;
echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
echo "/usr/local/mysql/lib/plugin" >>/etc/ld.so.conf
ldconfig -v
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
如果报[Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists.错误按以下方法解决
登录数据库,进入mysql库,执行如下SQL删除5张表,记住,一定要是drop table if exists
/usr/local/mysql/bin/mysql -u root -p
mysql>use mysql;
mysql>drop table if exists innodb_index_stats;
mysql>drop table if exists innodb_table_stats;
mysql>drop table if exists slave_master_info;
mysql>drop table if exists slave_relay_log_info;
mysql>drop table if exists slave_worker_info;
执行前用show tables查看一下表的数据,执行完后看是否已经比删除之前减少了,如果减少了,说明成功了
退出并停止数据库,进入到数据库数据文件所在目录,删除5个表所对应的idb文件
rm -f /data/mysql/mysql/innodb_index_stats.ibd innodb_table_stats.ibd slave_master_info.ibd slave_relay_log_info.ibd slave_worker_info.ibd
启动数据库,进入到mysql库,重建上面被删除的表结构
/usr/local/mysql/bin/mysql -u root -p
mysql>use mysql;
source /usr/local/mysql/share/mysql_system_tables.sql
查看表,如果5个表已成功创建,说明成功了
安装PHP
tar zxvf re2c-0.14.2.tar.gz
cd re2c-0.14.2
./configure
make && make install
tar -zxvf php-5.6.7.tar.gz
cd php-5.6.7
./configure --prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-fpm --with-mhash \
--enable-soap --with-libxml-dir \
--with-openssl --with-vpx-dir \
--with-pcre-regex --with-sqlite3 \
--with-zlib --enable-bcmath \
--with-iconv --with-bz2 \
--enable-calendar --with-curl \
--with-cdb --enable-dom \
--enable-exif --enable-fileinfo \
--enable-filter --with-pcre-dir \
--enable-ftp --with-gd \
--with-openssl-dir --with-jpeg-dir \
--with-png-dir --with-zlib-dir \
--with-freetype-dir --enable-gd-native-ttf \
--enable-gd-jis-conv --with-gettext \
--with-gmp --with-mhash --enable-json \
--enable-mbstring --disable-mbregex \
--disable-mbregex-backtrack --with-libmbfl \
--with-onig --enable-pdo --with-pdo-mysql \
--with-zlib-dir --with-pdo-sqlite \
--with-readline --enable-session \
--enable-shmop --enable-simplexml \
--enable-sockets --with-xpm-dir \
--enable-sysvmsg --enable-sysvsem \
--enable-sysvshm --enable-wddx \
--with-libxml-dir --with-xsl --enable-zip \
--enable-mysqlnd-compression-support \
--enable-maintainer-zts
make && make install
cp /usr/local/src/php-5.6.7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
vi /etc/init.d/php-fpm
user vmail
group vmail
内存小于4G服务器(值可逐级递减):
修改如下参数:
--------------
pm = dynamic
pm.max_children=40
pm.start_servers=10
pm.min_spare_servers=10
pm.max_spare_servers=40
--------------
内存大于4G服务器(值可逐级递增):
修改如下参数:
--------------
pm = static
pm.max_children=100
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
cp /usr/local/src/php-5.6.7/php.ini-development /usr/local/php/lib/php.ini
vi php.ini
expose_php = Off
display_errors = Off
date.timezone =PRC
log_errors = On
error_log = /usr/local/nginx/logs/php_error.log
disable_functions =
passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用
vi /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
service nginx restart
在配置完成Nginx+FastCGI之后,为了保证Nginx下PHP环境的高速稳定运行,需要添加一些FastCGI优化缓存指令
vi /usr/local/nginx/conf/nginx.conf
添加到http层级:
--------------------------
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;
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;
fastcgi_cache TEST;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
本文出自 “学习笔记” 博客,请务必保留此出处http://303188936.blog.51cto.com/2722929/1636756
标签:centos7 lnmp
原文地址:http://303188936.blog.51cto.com/2722929/1636756