Centos7+Nginx1.11.7+MysqL5.7.16+PHP7.1.0+openssl-1.1.0c
一、linux 系统限制配置
1、关闭系统防火墙
systemctlstopfirewalld.service关闭防火墙 systemctldisablefirewalld.service禁用防火墙
2、关闭SElinux
sed-i's/SELINUX=.*/SELINUX=disabled/g'/etc/selinux/config setenforce0selinux立即生效
二、系统安装约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
三、下载软件包
1、下载Nginx最新稳定版本
wget-P/usr/local/srchttp://Nginx.org/download/Nginx-1.11.7.tar.gz
2、下载MysqL-boost-5.7.16 带boost 如果不带源码安装如果网络环境不会可能会出现错误
wget-P/usr/local/srchttp://cdn.MysqL.com/Downloads/MysqL-5.7/MysqL-boost-5.7.16.tar.gz
3、下载PHP-7.1.0版本
wget-P/usr/local/srchttp://cn2.PHP.net/distributions/PHP-7.1.0.tar.gz
4、下载libmemcached-1.0.18
wget-P/usr/local/srchttps://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz
5、下载PHP-memcached
yum-yinstallgit cd/usr/local/src gitclone-bPHP7https://github.com/PHP-memcached-dev/PHP-memcached.git
6、下载openssl-1.1.0c
wget-P/usr/local/srchttps://www.openssl.org/source/openssl-1.1.0c.tar.gz
四、安装编译器及依赖
yum-yinsyallepel-release yum-yinstallpatchgccgcc-c++readline-develzlib-devellibffi-devel\ opensslopenssl-develmakeautoconfautomakelibtoolbisonlibxml2\ libxml2-devellibxslt-devellibyaml-develpythonpython-docutils\ cmakeimakeexpat-devellibaiolibaio-develbzrncurses-develwget\ libjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devel\ pcre-develcurl-devellibmcryptlibmcrypt-devel
五、编译安装MysqL-boost-5.7.16 方便再次安装创建MysqL_install.sh脚本
#!/bin/bash #yumupdate-y #yuminstall-ycmakegcc-c++ncurses-develgccmakeopenssl* #MysqL安装脚本 DBDIR='/data/MysqL'#MysqL数据存储目录 MysqLDIR='/usr/local/MysqL'#MysqL安装目录 PASSWD='123456'#MysqLroot密码安装完成可远程ip登陆 [-d$DBDIR]||mkdir$DBDIR-p idMysqL&>/dev/null if[$?-ne0];then useraddMysqL-s/sbin/nologin-M fi chown-RMysqL:MysqL$DBDIR cd/usr/local/src tar-xvfMysqL-boost-5.7.16.tar.gz cdMysqL-5.7.16 cmake.-DCMAKE_INSTALL_PREFIX=$MysqLDIR\ -DMysqL_DATADIR=$DBDIR\ -DSYSCONFDIR=/etc\ -DWITH_INNOBASE_STORAGE_ENGINE=1\ -DWITH_ARCHIVE_STORAGE_ENGINE=1\ -DWITH_BLACKHOLE_STORAGE_ENGINE=1\ -DWITH_READLINE=1\ -DWITH_LIBWRAP=0\ -DMysqL_UNIX_ADDR=/tmp/MysqL.sock\ -DWITH_SSL=system\ -DWITH_ZLIB=system\ -DWITH_BOOST=/usr/local/src/MysqL-5.7.16/boost/boost_1_59_0\ -DDEFAULT_CHARSET=utf8\ -DDEFAULT_COLLATION=utf8_general_ci if[$?!=0];then echo"cmakeerror!" exit1 fi make&&makeinstall if[$?-ne0];then echo"installMysqLisFailed!"&&/bin/false fi sleep2 chown-RMysqL:MysqL$MysqLDIR chown-Rroot:root$MysqLDIR cp$MysqLDIR/support-files/my-default.cnf/etc/my.cnf echoexportPATH=$PATH:$MysqLDIR/bin:$MysqLDIR/lib>>/etc/profile source/etc/profile cat>>/etc/my.cnf<<EOF character_set_server=utf8 basedir=$MysqLDIR datadir=$DBDIR port=3306 server_id=1 socket=/tmp/MysqL.sock explicit_defaults_for_timestamp=true EOF sed-i's/sql_mode=.*/sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER/g'/etc/my.cnf source/etc/profile sleep5 cd$MysqLDIR cpsupport-files/MysqL.server/etc/init.d/MysqLd chmod700/etc/init.d/MysqLd MysqL_ssl_rsa_setup rm-rf$DBDIR MysqLd--initialize--user=MysqL if[$?-ne0];then echo"installMysqLisFailed!"&&/bin/false fi #/etc/init.d/MysqLdstop MysqLd_safe--user=MysqL--skip-grant-tables--skip-networking& sleep5 echo"updateusersetauthentication_string=Password('$PASSWD')whereuser='root';flushprivileges;"|MysqLMysqL echo"setpassword=Password('$PASSWD');flushprivileges;"|MysqL-uroot-p$PASSWD--connect-expired-password sleep5 echo"GRANTALLPRIVILEGESON*.*TOroot@'%'IDENTIFIEDBY'$PASSWD';FLUSHPRIVILEGES;"|MysqL-uroot-p$PASSWD /etc/init.d/MysqLdrestart if[$?-ne0];then echo"installMysqLisFailed!"&&/bin/false fi IDSO=`cat/etc/ld.so.conf|grep$MysqLDIR/lib|wc-l` if[$IDSO-eq0];then echo"$MysqLDIR/lib">>/etc/ld.so.conf ldconfig fi chkconfigMysqLdon
2、给MysqL_install.sh 可执行权限
chmod+xMysqL_install.sh
3、运行MysqL_install.sh
./MysqL_install.sh
六、编译安装PHP7 创建PHP安装脚本PHP7_install.sh
1、vimPHP7_install.sh
#!/bin/bash if[$(find/-nameMysqL|wc-l)-gt1];then echo"MysqLisinstall" else yuminstall-yMysqL fi cd/usr/local/src tar-xzvfPHP-7.1.0.tar.gz cd./PHP-7.1.0 ./configure\ --prefix=/usr/local/PHP7\ --exec-prefix=/usr/local/PHP7\ --with-config-file-path=/usr/local/PHP7/etc\ --with-curl\ --with-freetype-dir\ --with-gd\ --with-gettext\ --with-iconv-dir\ --with-kerberos\ --with-libdir=lib64\ --with-libxml-dir\ --with-MysqLi\ --with-openssl\ --with-pcre-regex\ --with-pdo-MysqL\ --with-pdo-sqlite\ --with-pear\ --with-png-dir\ --with-xmlrpc\ --with-xsl\ --with-zlib\ --with-zlib-dir\ --with-mhash\ --with-mcrypt\ --with-openssl-dir\ --with-jpeg-dir\ --enable-fpm\ --enable-bcmath\ --enable-libxml\ --enable-inline-optimization\ --enable-gd-native-ttf\ --enable-mbregex\ --enable-mbstring\ --enable-opcache\ --enable-pcntl\ --enable-shmop\ --enable-soap\ --enable-sockets\ --enable-sysvsem\ --enable-xml\ --enable-zip make&&makeinstall #中文PHP画图取消这个参数,不然会出现乱码 #--enable-gd-jis-conv\
2、给PHP7_install.sh 可执行权限
chmod+xPHP7_install.sh
3、执行PHP7_install.sh
./PHP7_install.sh
4、编译安装libmemcached-1.0.18
vimlibmemcached_install.sh
#/!bin/bash cd/usr/local/src tar-zxvflibmemcached-1.0.18.tar.gz cd./libmemcached-1.0.18 ./configure--prefix=/usr/local/libmemcached make&&makeinstall
chmod+xlibmemcached_install.sh ./libmemcached_install.sh
5、编译安装PHP-memcached
vim memcached_install.sh
#!/bin/bash cd/usr/local/src/PHP-memcached /usr/local/PHP7/bin/PHPize ./configure--with-libmemcached-dir=/usr/local/libmemcached\ --with-PHP-config=/usr/local/PHP7/bin/PHP-config\ --disable-memcached-sasl make&&makeinstall
chmod+xmemcached_install.sh ./memcached_install.sh 留意编完成生成文件路径 Installingsharedextensions:/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/
七、编译安装openssl-1.1.0c
vimopenssl_install.sh
#!/bin/bash #opensslinstall cd/usr/local/src tar-xvfopenssl-1.1.0c.tar.gz cd/usr/local/src/openssl-1.1.0c ./config--openssldir=/usr/local/ssl make&&makeinstall ./configshared--openssldir=/usr/local/ssl makeclean make&&makeinstall IDSO=`cat/etc/ld.so.conf|grep/usr/local/lib64|wc-l` if[$IDSO-eq0];then echo"/usr/local/lib64">>/etc/ld.so.conf fi ldconfig
chmod+xopenssl_install.sh ./openssl_install.sh
八、编译安装Nginx-1.11.7
vimNginx_install.sh
#!/bin/bash #Nginxinstall idNginx&>/dev/null if[$?-ne0];then groupadd-rNginx useradd-gNginx-rNginx fi cd/usr/local/src tar-xvfNginx-1.11.7.tar.gz cd/usr/local/src/Nginx-1.11.7 ./configure--prefix=/usr/local/Nginx\ --sbin-path=/usr/sbin/Nginx\ --conf-path=/etc/Nginx/Nginx.conf\ --error-log-path=/var/log/Nginx/error.log\ --http-log-path=/var/log/Nginx/access.log\ --pid-path=/var/run/Nginx.pid\ --lock-path=/var/run/Nginx.lock\ --http-client-body-temp-path=/var/cache/Nginx/client_temp\ --http-proxy-temp-path=/var/cache/Nginx/proxy_temp\ --http-fastcgi-temp-path=/var/cache/Nginx/fastcgi_temp\ --http-uwsgi-temp-path=/var/cache/Nginx/uwsgi_temp\ --http-scgi-temp-path=/var/cache/Nginx/scgi_temp\ --user=Nginx\ --group=Nginx\ --with-http_ssl_module\ --with-http_realip_module\ --with-http_addition_module\ --with-http_sub_module\ --with-http_dav_module\ --with-http_flv_module\ --with-http_mp4_module\ --with-http_gunzip_module\ --with-http_gzip_static_module\ --with-http_random_index_module\ --with-http_secure_link_module\ --with-http_stub_status_module\ --with-http_auth_request_module\ --with-threads\ --with-stream\ --with-openssl=/usr/local/src/openssl-1.1.0c\#openssl源码解压路径 --with-stream_ssl_module\ --with-http_slice_module\ --with-mail\ --with-mail_ssl_module\ --with-file-aio\ --with-http_v2_module\ --with-ipv6 mkdir-pv/var/cache/Nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp} make&&makeinstall
2、给Nginx_install.sh可执行权限
chmod+xNginx_install.sh ./Nginx_install.sh
九、配置PHP7
/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/memcached.so 这个路径是随机可变的所以要注意 留意变完成生成文件路径 Installingsharedextensions:/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/
cd/usr/local/src/PHP-7.1.0 cpPHP.ini-production/usr/local/PHP7/etc/PHP.ini cp/usr/local/PHP7/etc/PHP-fpm.conf.default/usr/local/PHP7/etc/PHP-fpm.conf cp/usr/local/PHP7/etc/PHP-fpm.d/www.conf.default/usr/local/PHP7/etc/PHP-fpm.d/www.conf sed-i"s/user=.*/user=Nginx/g"/usr/local/PHP7/etc/PHP-fpm.d/www.conf sed-i"s/group=.*/group=Nginx/g"/usr/local/PHP7/etc/PHP-fpm.d/www.conf cp./sapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm chmod+x/etc/init.d/PHP-fpm chkconfigPHP-fpmon cat>>/usr/local/PHP7/etc/PHP.ini<<EOF soap.wsdl_cache_enabled=1 max_input_time=600 max_execution_time=300 date.timezone=Asia/Shanghai post_max_size=32M memory_limit=128M mbstring.func_overload=1 extension=/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/memcached.so EOF cat>/usr/local/Nginx/html/index.PHP<<EOF <?PHP PHPinfo(); ?> EOF servicePHP-fpmstart
十、配置Nginx
mv/etc/Nginx/Nginx.conf/etc/Nginx/Nginx.conf.back
cat>/etc/Nginx/Nginx.conf<<EOF userNginx; worker_processes1; error_log/var/log/Nginx/error.logwarn; pid/var/run/Nginx.pid; events{ worker_connections1024; } http{ include/etc/Nginx/mime.types; default_typeapplication/octet-stream; log_formatmain'\$remote_addr-\$remote_user[\$time_local]"\$request"' '\$status\$body_bytes_sent"\$http_referer"' '"\$http_user_agent""\$http_x_forwarded_for"'; access_log/var/log/Nginx/access.logmain; sendfileon; #tcp_nopushon; keepalive_timeout65; #gzipon; include/etc/Nginx/conf.d/*.conf; } EOF
3、创建/etc/Nginx/conf.d
mkdir-p/etc/Nginx/conf.d
cat>/etc/Nginx/conf.d/default.conf<<EOF server{ listen80; server_namelocalhost; #charsetkoi8-r; #access_loglogs/host.access.logmain; location/{ root/usr/local/Nginx/html; indexindex.PHPindex.htmlindex.htm; } #error_page404/404.html; #redirectservererrorpagestothestaticpage/50x.html # error_page500502503504/50x.html; location=/50x.html{ roothtml; } #proxythePHPscriptstoApachelisteningon127.0.0.1:80 # #location~\.PHP${ #proxy_passhttp://127.0.0.1; #} #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # location~\.PHP${ root/usr/local/Nginx/html; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.PHP; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } location~*^.+\.(jpg|jpeg|gif|png|bmp)${ access_logoff; rootopencart; expires30d; break; } } EOF
5、创建Nginx启动脚本
vim/etc/init.d/Nginx
#chkconfig:23451090 #description:StartandStopNginx PATH=/usr/local/bin:/sbin:/usr/bin:/bin EXEC=/usr/sbin/Nginx PIDFILE=/var/run/Nginx.pid CONF="/etc/Nginx/Nginx.conf" AUTH="1234" case"$1"in start) if[-f$PIDFILE] then echo"$PIDFILEexists,processisalreadyrunningorcrashed." else echo"StartingNginxserver..." $EXEC-c$CONF& fi if["$?"="0"] then echo"Nginxisrunning..." fi ;; stop) if[!-f$PIDFILE] then echo"$PIDFILEexists,processisnotrunning." else PID=$(cat$PIDFILE) echo"Stopping..." kill-9$PID PID=$(pidofNginx) kill-9$PID rm-rf/var/run/Nginx.pid sleep2 while[-x$PIDFILE] do echo"WaitingforNginxtoshutdown..." sleep1 done echo"Nginxstopped" fi ;; reload) $EXEC-sreload ;; restart|force-reload) ${0}stop ${0}start ;; *) echo"Usage:/etc/init.d/Nginx{start|stop|restart|force-reload|reload}">&2 exit1 esac
6、给/etc/init.d/Nginx 可执行权限
chmod+x/etc/init.d/Nginx
7、设置开机启动
chkconfigNginxon
8、启动Nginx
serviceNginxstart
十一、测试
[root@QKA169src]#opensslversion OpenSSL1.1.0c10Nov2016 MysqL-uroot-p123456 MysqL>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |MysqL| |performance_schema| |sys| +--------------------+ 4rowsinset(0.00sec) 看看是否登陆成功。远程带IP是否登陆成功 MysqL-uroot-h192.168.1.69-p123456 MysqL>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |MysqL| |performance_schema| |sys| +--------------------+ 4rowsinset(0.00sec) MysqL:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure. WelcometotheMysqLmonitor.Commandsendwith;or\g. YourMysqLconnectionidis6 Serverversion:5.7.16Sourcedistribution Copyright(c)2000,2016,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MysqL>
测试Nginx 是否能打开
[root@QKA169html]#ps-ef|grepPHP-fpm root3374331018:03?00:00:00PHP-fpm:masterprocess(/usr/local/PHP7/etc/PHP-fpm.conf) nobody337434337433018:03?00:00:00PHP-fpm:poolwww nobody337435337433018:03?00:00:00PHP-fpm:poolwww root33745437888018:12pts/000:00:00grep--color=autoPHP-fpm [root@QKA169html]#ps-ef|grepNginx root3374001018:01?00:00:00Nginx:masterprocess/usr/sbin/Nginx-c/etc/Nginx/Nginx.conf Nginx337401337400018:01?00:00:00Nginx:workerprocess root33745637888018:13pts/000:00:00grep--color=autoNginx [root@QKA169html]#netstat-nalp|grep80 tcp000.0.0.0:800.0.0.0:*LISTEN337400/Nginx:maste tcp00192.168.1.69:80192.168.6.6:54714TIME_WAIT- tcp00192.168.1.69:80192.168.6.6:54709TIME_WAIT- 远程打开 http://192.168.1.69/
到此lnmp源码安装完成
原文链接:https://www.f2er.com/centos/379431.html