标签:lnmp
1:基础环境准备
[root@node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@node1 ~]# uname -r 3.10.0-327.18.2.el7.x86_64 [root@node1 ~]# getenforce Disabled
2:编译安装Nginx
2.1 准备工作
[root@node1 ~]# useradd -u 7005 -s /sbin/nologin -M nginx [root@node1 ~]# yum install wget gcc gcc-c++ autoconf automake bzip2 -y [root@node1 ~]# yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel -y
2.2 下载需要的软件包
[root@node1 ~]# mkdir source [root@node1 ~]# cd source/ [root@node1 source]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2 [root@node1 source]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@node1 source]# wget http://nginx.org/download/nginx-1.10.0.tar.gz [root@node1 source]# wget https://github.com/jemalloc/jemalloc/releases/download/4.2.0/jemalloc-4.2.0.tar.bz2
2.3 安装jemalloc优化nginx,mysql
[root@node1 source]# tar -xf jemalloc-4.2.0.tar.bz2 -C /usr/local/src/ [root@node1 source]# cd !$ cd /usr/local/src/ [root@node1 src]# cd jemalloc-4.2.0/ [root@node1 jemalloc-4.2.0]# ./configure && make && make install [root@node1 jemalloc-4.2.0]# echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf [root@node1 jemalloc-4.2.0]# ldconfig
2.4 编译安装Nginx
[root@node1 source]# tar -xf zlib-1.2.8.tar.gz -C /usr/local/src/ [root@node1 source]# tar -xf pcre-8.38.tar.bz2 -C /usr/local/src/ [root@node1 source]# tar -xf nginx-1.10.0.tar.gz -C /usr/local/src/ [root@node1 source]# cd /usr/local/src/nginx-1.10.0/ [root@node1 nginx-1.10.0]# vim auto/cc/gcc 178 # debug #取消debug模式 179 #CFLAGS="$CFLAGS -g" [root@node1 nginx-1.10.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_gzip_static_module --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.38 --pid-path=/usr/local/nginx/nginx.pid --with-ld-opt="-ljemalloc" --with-http_flv_module --user=nginx --group=nginx [root@node1 nginx-1.10.0]# make -j 4 && make install [root@node1 ~]# /usr/local/nginx/sbin/nginx [root@node1 ~]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 11712 root 7u IPv4 27174 0t0 TCP *:http (LISTEN) nginx 11713 nginx 7u IPv4 27174 0t0 TCP *:http (LISTEN)
3:编译安装MySQL5.7.12
3.1 准备工作
[root@node1 ~]# useradd -u 7003 -s /sbin/nologin -M mysql [root@node1 ~]# mkdir -p /data/mysql [root@node1 ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel wget bzip2 openssl openssl-devel cmake bison
3.2 下载软件包
[root@node1 source]# wget http://120.52.73.44/nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz [root@node1 source]# wget http://fossies.org/linux/misc/mysql-5.7.12.tar.gz
3.3 安装zlib
[root@node1 source]# cd /usr/local/src/zlib-1.2.8/ [root@node1 zlib-1.2.8]# ./configure --prefix=/usr/local/zlib [root@node1 zlib-1.2.8]# make && make install
3.4 安装boost
boost使用1.6的没成功,自行尝试
[root@node1 ~]# mkdir /usr/local/boost [root@node1 ~]# cp boost_1_59_0.tar.gz /usr/local/boost/
3.5 安装mysql
[root@node1 ~]# tar -xf mysql-5.7.12.tar.gz -C /usr/local/src [root@node1 ~]# cd !$/mysql-5.7.12 cd /usr/local/src/mysql-5.7.12 [root@node1 mysql-5.7.12]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql > -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock > -DMYSQL_DATADIR=/data/mysql/ > -DSYSCONFDIR=/etc > -DMYSQL_TCP_PORT=3306 > -DWITH_INNOBASE_STORAGE_ENGINE=1 > -DWITH_PARTITION_STORAGE_ENGINE=1 > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 > -DWITH_MYISAM_STORAGE_ENGINE=1 > -DENABLED_LOCAL_INFILE=1 > -DWITH_DEBUG=0 > -DDEFAULT_CHARSET=utf8 > -DDEFAULT_COLLATION=utf8_general_ci > -DWITH_EXTRA_CHARSETS=all > -DMYSQL_MAINTAINER_MODE=0 > -DWITH_EDITLINE=bundled > -DWITH_SSL:STRING=bundled > -DWITH_ZLIB:STRING=bundled > -DZLIB_LIBRARY:FILEPATH=/usr/local/zlib/lib/ > -DZLIB_INCLUDE_DIR:PATH=/usr/local/zlib/include/ > -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" > -DENABLE_DOWNLOADS=1 > -DWITH_BOOST=/usr/local/boost [root@node1 mysql-5.7.12]# make -j 8 [root@node1 mysql-5.7.12]# make install
3.6 初始化MySQL
[root@node1 ~]# chown -R mysql.mysql /usr/local/mysql/ [root@node1 ~]# chown -R mysql.mysql /data/ [root@node1 ~]# echo ‘export PATH=$PATH:/usr/local/mysql/bin‘ >> /etc/profile [root@node1 ~]# source !$ source /etc/profile [root@node1 ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/ 2016-05-19T20:14:50.116815Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-05-19T20:14:52.295861Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-05-19T20:14:52.830312Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-05-19T20:14:52.900305Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 58bc254a-1dfe-11e6-b44e-000c29a693ba. 2016-05-19T20:14:52.901926Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2016-05-19T20:14:52.903104Z 1 [Note] A temporary password is generated for root@localhost: pgVUH?ypG6fe #随机生成的密码
3.7 配置文件和启动脚本
[root@node1 ~]# mv /etc/my.cnf /etc/my.cnf.bk [root@node1 ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf [root@node1 ~]# sed -i ‘/^\[mysqld\]/adatadir = /data/mysql‘ /etc/my.cnf [root@node1 ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf [root@node1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@node1 ~]# chmod +x /etc/init.d/mysqld [root@node1 ~]# chkconfig mysqld on
3.8 启动mysql修改root密码
[root@node1 ~]# systemctl start mysqld.service [root@node1 ~]# mysql -uroot -ppgVUH?ypG6fe mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘123456‘); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
4:编译安装PHP
4.1 编译安装
[root@node1 ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel [root@node1 source]# wget http://hk1.php.net/distributions/php-7.0.6.tar.gz [root@node1 source]# tar -xf php-7.0.6.tar.gz -C /usr/local/src/ [root@node1 source]# cd /usr/local/src/php-7.0.6/ [root@node1 php-7.0.6]# ./configure > --prefix=/usr/local/php > --with-mysql-sock=/data/mysql/mysql.sock > --with-mcrypt=/usr/include > --with-mhash > --with-openssl > --with-mysqli=shared,mysqlnd > --with-pdo-mysql=shared,mysqlnd > --with-gd > --with-iconv > --with-zlib > --enable-zip > --enable-inline-optimization > --disable-debug > --disable-rpath > --enable-shared > --enable-xml > --enable-bcmath > --enable-shmop > --enable-sysvsem > --enable-mbregex > --enable-mbstring > --enable-ftp > --enable-gd-native-ttf > --enable-pcntl > --enable-sockets > --with-xmlrpc > --enable-soap > --without-pear > --with-gettext > --enable-session > --with-curl > --with-jpeg-dir > --with-freetype-dir > --enable-opcache > --enable-fpm > --with-fpm-user=nginx > --with-fpm-group=nginx > --without-gdbm > --disable-fileinfo [root@node1 php-7.0.6]# make -j 8 && make install
4.2 简单的设置
[root@node1 ~]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/ #查看生成的模块 mysqli.a mysqli.so opcache.a opcache.so pdo_mysql.a pdo_mysql.so [root@node1 ~]# cp /usr/local/src/php-7.0.6/php.ini-production /usr/local/php/etc/php.ini [root@node1 ~]# cp /usr/local/src/php-7.0.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@node1 ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@node1 ~]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
4.3 添加php的环境变量
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/php/bin:/usr/local/php/sbin
4.4 创建php数据库文件的存放路径以及相关安全配置
[root@node1 ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /run/php-fpm && cd /run/ && chown -R nginx:nginx php-fpm [root@node1 run]# mkdir -p /var/lib/php/session [root@node1 run]# chown -R nginx:nginx /var/lib/php
4.5 设置PHP开机启动以及测试配置文件是否正确
[root@node1 run]# chmod +x /etc/init.d/php-fpm [root@node1 run]# chkconfig php-fpm on [root@node1 run]# php-fpm -t [19-May-2016 18:11:58] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful [root@node1 run]# service php-fpm start Starting php-fpm done [root@node1 run]# lsof -i :9000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME php-fpm 97375 root 7u IPv4 136018 0t0 TCP localhost:cslistener (LISTEN) php-fpm 97376 nginx 0u IPv4 136018 0t0 TCP localhost:cslistener (LISTEN) php-fpm 97377 nginx 0u IPv4 136018 0t0 TCP localhost:cslistener (LISTEN)
5:配置LNMP
5.1 配置nginx
[root@node1 ~]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx [root@node1 ~]# mkdir /website [root@node1 ~]# chown -R nginx:nginx /website/ [root@node1 ~]# vim /usr/local/nginx/conf/nginx.conf user nginx nginx; worker_processes auto; error_log logs/error.log error; pid /run/nginx.pid; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; server { listen 80; server_name oslinux.cn; charset UTF-8; location / { root /website; index index.html index.htm index.php; } location /NginxStatus { stub_status on; #启用StubStatus的工作状态统计功能*/ access_log logs/NginxStatus.log; #/*StubStatus模块的访问日志文件*/ auth_basic "NginxStatus"; #/*StubStatus的一种认证机制*/ } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /website; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /website$fastcgi_script_name; include fastcgi_params; } } } [root@node1 ~]# nginx -s reload
5.2 配置PHP
[root@node1 ~]# vim /usr/local/php/etc/php.ini 202 short_open_tag = On 359 expose_php = Off 722 extension_dir = "/usr/local/php/lib/php/extensions/no-de bug-non-zts-20151012/" 901 zend_extension=opcache.so 902 extension=mysqli.so 903 extension=pdo_mysql.so 915 date.timezone = Asia/Shanghai 1732 [opcache] 1734 opcache.enable=1
[root@node1 ~]# /etc/init.d/php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done [root@node1 ~]# nginx -s reload [root@node1 ~]# vim /website/index.php <?php phpinfo(); ?>
本文出自 “黑夜浮屠” 博客,请务必保留此出处http://lorne.blog.51cto.com/9062483/1775485
标签:lnmp
原文地址:http://lorne.blog.51cto.com/9062483/1775485