LNMP

来源:互联网 发布:做淘宝直播怎么找商家 编辑:程序博客网 时间:2024/06/07 16:05

LNMP

安装Nginx

[root@server6 ~]# lsnginx-1.12.0.tar.gz[root@server6 ~]# rpm -qa | grep mysqlmysql-libs-5.1.71-1.el6.x86_64[root@server6 ~]# rpm -qa | grep php[root@server6 ~]# tar zxf nginx-1.12.0.tar.gz [root@server6 ~]# cd nginx-1.12.0[root@server6 nginx-1.12.0]# cd src/core/[root@server6 core]# pwd/root/nginx-1.12.0/src/core[root@server6 core]# vim nginx.h    #不显示版本号... 14 #define NGINX_VER          "nginx"  ...[root@server6 cc]# pwd/root/nginx-1.12.0/auto/cc[root@server6 cc]# vim gcc ...172 #CFLAGS="$CFLAGS -g"...[root@server6 nginx-1.12.0]# yum install gcc openssl-devel pcre-devel -y[root@server6 nginx-1.12.0]# ./configure --prefix=/usr/local/lnmp/nginx  --with-http_ssl_module --with-http_stub_status_module      #生成Makefile文件[root@server6 nginx-1.12.0]# make && make install[root@server6 ~]# vim .bash_profile    #添加环境变量... 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/nginx/sbin...[root@server6 ~]# source ~/.bash_profile [root@server6 ~]# which nginx/usr/local/lnmp/nginx/sbin/nginx[root@server6 ~]# nginx [root@server6 ~]# netstat -antp        #工作在:80端口上&&netstat命令的使用:    https://linux.cn/article-2434-1.html[root@server6 conf]# pwd/usr/local/lnmp/nginx/conf&&定义访问页面vim nginx.conf...***需自定义server{    listen 80;    server_name www.westos.org;    location / {        root /web1;        index index.html;    }}.....mkdir /web1vim /web1/index.html测试:访问:www.westos.org    要在物理机做本地解析&&实现https访问,开启443端口vim nginx.conf...    server {        listen       443 ssl;        server_name  www.westos.org;        ssl_certificate      cert.pem;        ssl_certificate_key  cert.pem;        ssl_session_cache    shared:SSL:1m;        ssl_session_timeout  5m;        ssl_ciphers  HIGH:!aNULL:!MD5;        ssl_prefer_server_ciphers  on;        location / {            root   html;            index  index.html index.htm;        }    }...[root@server6 conf]# cd /etc/pki/tls/certs/[root@server6 certs]# lsca-bundle.crt        make-dummy-cert  renew-dummy-certca-bundle.trust.crt  Makefile[root@server6 certs]# make cert.pem[root@server6 certs]# mv cert.pem /usr/local/lnmp/nginx/conf/测试:浏览器中访问:https://linux.cn/article-2434-1.html&&添加状态页面vim nginx.conf.....        location / {            root   html;            index  index.html index.htm;        }    location /status {        stub_status on;        access_log off;    }测试:浏览器访问:http://172.25.66.1/status&&实现反反向代理负载均衡vim nginx.conf.....events {    worker_connections  65535;}http {    upstream westos {    server 172.25.30.7:80;    server 172.25.30.8:80;    }    include       mime.types;    default_type  application/octet-stream;....server{    listen 80;    server_name www.westos.org;    location / {    #   root /web1;    #   index index.html;        proxy_pass http://westos;    }}测试:[root@foundation66 Desktop]# for i in range {1..100};do curl www.westos.org;done实现负载均衡&&定义算法,发布错误页面    默认支持后端健康检查***了解cookie和session及其应用场景cache参考文档:http://www.cnblogs.com/shiyangxt/archive/2008/10/07/1305506.html具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案cookie 和session 的区别:    1、cookie数据存放在客户的浏览器上,session数据放在服务器上。    2、cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗,考虑到安全应当使用session。    3、session会在一定时间内保存在服务器上。当访问增多,会比较占用你服务器的性能,考虑到减轻服务器性能方面,应当使用COOKIE。    4、单个cookie保存的数据不能超过4K,很多浏览器都限制一个站点最多保存20个cookie。

Cmake安装mysql

[root@server6 ~]# lsanaconda-ks.cfg                  install.log.syslog         nginx-1.12.0.tar.gzcmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.11.tar.gzinstall.log                      nginx-1.12.0[root@server6 ~]# tar zxf mysql-boost-5.7.11.tar.gz [root@server6 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y   #根据报错安装依赖包[root@server6 mysql-5.7.11]# yum install ncurses-decel gcc-c++ ncurses-devel -y[root@server6 mysql-5.7.11]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_READLINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all  -DWITH_BOOST=boost/boost_1_59_0/[root@server6 mysql-5.7.11]# rm -fr CMakeCache.txt  #如果cmake编译出错,则需要执行此步骤之后继续cmake[root@server6 mysql-5.7.11]# make [root@server6 mysql-5.7.11]# make install***初始化密码[root@server6 ~]# cd /usr/local/lnmp/mysql/support-files/[root@server6 support-files]# cp my-default.cnf /etc/my.cnf[root@server6 support-files]# vim /etc/my.cnf... 18 basedir = /usr/local/lnmp/mysql 19 datadir = /usr/local/lnmp/mysql/data 20 port = 3306 21 # server_id = ..... 22 socket = /usr/local/lnmp/mysql/data/mysql.sock...[root@server6 support-files]# file mysql.server mysql.server: POSIX shell script text executable[root@server6 support-files]# cp mysql.server /etc/init.d/mysqld[root@server6 mysql]# pwd/usr/local/lnmp/mysql[root@server6 mysql]# ll[root@server6 mysql]# groupadd -g 27 mysqld[root@server6 mysql]# groupmod -n mysql mysqld[root@server6 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/docs/ -s /sbin/nologin mysql[root@server6 mysql]# id mysqluid=27(mysql) gid=27(mysql) groups=27(mysql)[root@server6 mysql]# chown mysql.mysql . -R[root@server6 mysql]# ll    *此时所有目录用户和组都是mysql|此时还没有data目录[root@server6 mysql]# vim ~/.bash_profile ..... 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/nginx/sbin:/usr/local/lnmp/mysql/bin[root@server6 mysql]# source ~/.bash_profile [root@server6 mysql]# mysqld --initialize-insecure  #简单初始化|生成了data目录[root@server6 mysql]# cd mysql-test/[root@server6 mysql-test]# ls[root@server6 mysql-test]# cd ..[root@server6 mysql]# cd data/[root@server6 mysql]# ll[root@server6 mysql]# chown root.root . -R[root@server6 mysql]# chown mysql.mysql data/ -R[root@server6 mysql]# /etc/init.d/mysqld startStarting MySQL. SUCCESS! [root@server6 mysql]# mysql #此时不需要密码就直接可以登陆.....mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)mysql> quitBye[root@server6 mysql]# mysql_secure_installation     **此时需要设置数据库密码:大小写+数字+特殊字符[root@server6 mysql]# mysql -p  #登陆:此时需要输入密码:Xiamin0099........mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)mysql> quitBye[root@server6 mysql]# &&&mysqld --initialize--->第一次生成随机密码,用随机密码登陆后进去可直接修改密码

安装php

[root@server6 ~]# lsanaconda-ks.cfg                         mysql-boost-5.7.11.tar.gzcmake-2.8.12.2-4.el6.x86_64.rpm         nginx-1.12.0gd-devel-2.0.35-11.el6.x86_64.rpm       nginx-1.12.0.tar.gzlibmcrypt-2.5.8-9.el6.x86_64.rpm       libmcrypt-devel-2.5.8-9.el6.x86_64.rpm  php-5.6.20.tar.bz2mysql-5.7.11                            re2c-0.13.5-1.el6.x86_64.rpm[root@server6 ~]# tar jxf php-5.6.20.tar.bz2[root@server6 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm [root@server6 php-5.6.20]# yum install net-snmp-devel gmp-devel gd-devel-2.0.35-11.el6.x86_64.rpm  libmcrypt-* libxml2-devel curl-devel -y[root@server6 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext --with-gmp --with-pear --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-mcrypt --with-mhash .....config.status: creating sapi/fpm/php-fpm.confconfig.status: creating sapi/fpm/init.d.php-fpmconfig.status: creating sapi/fpm/php-fpm.serviceconfig.status: creating sapi/fpm/php-fpm.8config.status: creating sapi/fpm/status.htmlconfig.status: creating sapi/cgi/php-cgi.1config.status: creating ext/phar/phar.1config.status: creating ext/phar/phar.phar.1config.status: creating main/php_config.hconfig.status: executing default commands.....[root@server6 php-5.6.20]# make && make install[root@server6 php-5.6.20]# cd /usr/local/lnmp/php/[root@server6 php]# cd etc/[root@server6 etc]# mv php.ini-production php.ini[root@server6 etc]# vim php.ini .....925 date.timezone =Asia/Shanghai[root@server6 etc]# cp php-fpm.conf.default php-fpm.conf[root@server6 etc]# pwd/usr/local/lnmp/php/etc[root@server6 etc]# vim php-fpm.conf..... 25 pid = run/php-fpm.pid149 user = nginx150 group = nginx.....[root@server6 ~]# cd php-5.6.20/sapi/fpm/[root@server6 fpm]# file init.d.php-fpminit.d.php-fpm: POSIX shell script text executable[root@server6 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm[root@server6 fpm]# chmod +x /etc/init.d/php-fpm [root@server6 fpm]# /etc/init.d/php-fpm startStarting php-fpm  done[root@server6 fpm]# netstat -antlp  #9000端口[root@server6 nginx]# pwd/usr/local/lnmp/nginx[root@server6 nginx]# vim conf/nginx.conf..... 52             index  index.php index.html index.htm;  #定义默认访问页面顺序 76         location ~ \.php$ { 77             root           html; 78             fastcgi_pass   127.0.0.1:9000; 79             fastcgi_index  index.php; 80         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_nam    e;   81             include        fastcgi.conf;    #fastcgi_params;--->fastcgi.conf 82         }[root@server6 nginx]# vim html/index.php [root@server6 nginx]# cat html/index.php        #php测试页面<?phpphpinfo()?>[root@server6 nginx]# nginx -s reload#测试:浏览器访问:172.25.30.6    可看到php页面及相关参数

整合论坛

[root@server6 ~]# yum install unzip -y[root@server6 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/yum install unzip -yunzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/cd /usr/local/lnmp/nginx/html/[root@server6 ~]# cd /usr/local/lnmp/nginx/html/[root@server6 html]# ls50x.html  index.html  index.php  readme  upload  utility[root@server6 html]# cd upload/[root@server6 upload]# cd ..[root@server6 html]# mv upload/ bbs[root@server6 html]# pwd/usr/local/lnmp/nginx/html#测试:浏览器访问:http://172.25.30.6/bbs/install/**修改权限可在浏览器中看到文件权限开放[root@server6 html]# cd bbs/[root@server6 bbs]# chmod 777 config/ data/ uc_client/ uc_server/ -R&&Permission deny**修改mysql的data权限,之后可看到在安装mysql包[root@server6 bbs]# cd /usr/local/lnmp/mysql/[root@server6 mysql]# lltotal 60drwxr-xr-x  2 root  root   4096 Oct  3 13:02 bin-rw-r--r--  1 root  root  17987 Feb  2  2016 COPYINGdrwxr-x---  5 mysql mysql  4096 Oct  3 14:07 datadrwxr-xr-x  2 root  root   4096 Oct  3 13:01 docsdrwxr-xr-x  3 root  root   4096 Oct  3 13:01 includedrwxr-xr-x  4 root  root   4096 Oct  3 13:02 libdrwxr-xr-x  4 root  root   4096 Oct  3 13:01 mandrwxr-xr-x 10 root  root   4096 Oct  3 13:02 mysql-test-rw-r--r--  1 root  root   2478 Feb  2  2016 READMEdrwxr-xr-x 28 root  root   4096 Oct  3 13:02 sharedrwxr-xr-x  2 root  root   4096 Oct  3 13:56 support-files[root@server6 mysql]# chmod 755 data/[root@server6 mysql]# ll -d data/drwxr-xr-x 5 mysql mysql 4096 Oct  3 14:07 data/[root@server6 mysql]# ***安装完成,进入论坛
原创粉丝点击