下载mysql源码包 mysql-boost-5.7.11.tar.gz
下载编译工具cmake cmake-2.8.12.2-4.el6.x86_64.rpm
[root@server1 ~]# tar zxf mysql-boost-5.7.11.tar.gz
[root@server1 mysql-5.7.11]# yum install -y gcc gcc-c++ ncurses-devel bison
[root@server1 mysql-5.7.11]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
[root@server1 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 \ #Unix socket文件路径
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安装innodb存储引擎
> -DWITH_MYISAM_STORAGE_ENGINE=1 \ #安装myisam存储引擎
> -DDEFAULT_CHARSET=utf8 \ #使用utf8字符
> -DDEFAULT_COLLATION=utf8_general_ci \ #校验字符
> -DEXTRA_CHARSETS=all \ #安装所有扩展字符集
> -DMYSQL_TCP_PORT=3306 \ #mysql监听端口
> -DWITH_BOOST=/root/mysql-5.7.11/boost/boost_1_59_0/
make
make install
##如果需要重新编译的话,需要清除旧的对象文件和缓存信息
make clean
rm -f CmakeCache.txt
[root@server1 mysql-5.7.11]# groupadd -g 27 mysql
[root@server1 mysql-5.7.11]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/ mysql
[root@server1 mysql-5.7.11]# id mysql #创建mysql用户
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@server1 ~]# vim .bash_profile #添加路径
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@server1 ~]# source .bash_profile #重读该文件
[root@server1 mysql]# cp /etc/my.cnf /etc/my.cnf.bak #备份配置文件
[root@server1 mysql]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/lnmp/mysql/data ##修改为编译安装时设置的路径
socket=/usr/local/lnmp/mysql/data/mysql.sock
[root@server1 mysql]# pwd
/usr/local/lnmp/mysql
[root@server1 mysql]# chown -R mysql.mysql . #将所有目录以及子文件全部改为mysql拥有
[root@server1 mysql]# mysqld --initialize --user=mysql ##初始化
##初始化时会出现默认设置的mysql中root用户的密码,注意记录,用来修改密码
[root@server1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld ##创建启动脚本
[root@server1 mysql]# /etc/init.d/mysqld start
[root@server1 mysql]# chkconfig mysqld on ##开机自启动
[root@server1 mysql]# mysql_secure_installation ##设置mysql密码等
[root@server1 mysql]# ln -s /usr/local/lnmp/mysql/lib /usr/local/lnmp/mysql/lib64 #防止php编译的时候找不到 mysql 的库文件
[root@server1 ~]# tar jxf php-5.6.19.tar.bz2
[root@server1 ~]# cd php-5.6.19
#先解决软件包依赖性
[root@server1 php-5.6.19]# yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel -y
tar zxf libiconv-1.13.1.tar.gz
#加强系统对支持字符编码转换的功能
cd libiconv-1.13.1/
./configure --libdir=/usr/local/lib64
make && make install
tar jxf libmcrypt-2.5.8.tar.bz2
# mcrypt mhash 是 php 加密算法扩展库
cd libmcrypt-2.5.8
./configure --libdir=/usr/local/lib64
make && make install
cd libltdl
./configure --libdir=/usr/local/lib64 --enable-ltdl-install
make && make install
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure --libdir=/usr/local/lib64
make && make install
[root@server1 php-5.6.19]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=/usr/local/lnmp/mysql/ --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 --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-libdir=lib64 --with-ldap --with-ldap-sasl --with-mcrypt --with-mhash
[root@server1 php-5.6.19]# make && make install
##make时可能会报错:make: *** [sapi/cli/php] Error 1
解决方法:
[root@server1 php-5.6.19]# make ZEND_EXTRA_LIBS='-liconv'
解决后:重新make&& make install
[root@server1 php-5.6.19]# make && make install
[root@server1 php-5.6.19]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# vim php-fpm.conf #修改配置文件
21 [global]
22 ; Pid file
23 ; Note: the default prefix is /usr/local/lnmp/php/var
24 ; Default Value: none
25 pid = run/php-fpm.pid ##将25行注释去掉
[root@server1 etc]# cp /root/php-5.6.19/php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 etc]# vim php.ini
925 date.timezone = Asia/Shanghai
[root@server1 php]# cp /root/php-5.6.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server1 php]# chmod +x /etc/init.d/php-fpm
[root@server1 php]# useradd -u 800 -M -d /usr/local/lnmp/nginx nginx
[root@server1 php]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[root@server1 php]# source ~/.bash_profile
[root@server1 php]# /etc/init.d/php-fpm start
[root@server1 php]# chkconfig php-fpm on
[root@server1 ~]# tar zxf nginx-1.10.1.tar.gz
[root@server1 ~]# cd nginx-1.10.1
[root@server1 nginx-1.10.1]# vim src/core/nginx.h
14 #define NGINX_VER "nginx/" #去掉后面的 “ NGINX_VERSION”,为了安全,这样编译后外界无法获取程序的版本号
[root@server1 nginx-1.10.1]# vim auto/cc/gcc
178 # debug
179 #CFLAGS="$CFLAGS -g" #去掉 debug 模式编译,编译以后程序只有几百k
[root@server1 nginx-1.10.1]# yum install pcre-devel -y #解决软件包依赖性
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --user=nginx --group=nginx
[root@server1 nginx-1.10.1]# make && make install
[root@server1 nginx-1.10.1]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/nginx
[root@server1 ~]# nginx
[root@server1 ~]# vim /usr/local/lnmp/nginx/html/index.php
[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
2 user nginx nginx;
3 worker_processes 8;
27 sendfile on;
28 tcp_nopush on;
29 tcp_nodelay on;
33 gzip on;
43 location / {
44 root html;
45 index index.php index.htm;
46 }
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
71 }
[root@server1 ~]# nginx -s reload
[root@server1 ~]# vim /usr/local/lnmp/php/etc/php.ini
1001 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock
1150 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1209 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
116 server {
117 listen 80;
118 server_name bbs.lcl.com;
119 location / {
120 root /bbs;
121 index index.php;
122 }
123 location ~ \.php$ {
124 root /bbs;
125 fastcgi_pass 127.0.0.1:9000;
126 fastcgi_index index.php;
127 include fastcgi.conf;
128 }
129 }
[root@server1 ~]# mkdir /bbs
[root@server1 ~]# vim /bbs/index.php
bbs.index.php
[root@server1 ~]# nginx -s reload
##注意:测试时一定要在测试主机上做好地址解析:bbs.lcl.com
[root@server1 ~]# unzip Discuz_X3.2_SC_UTF8.zip
[root@server1 ~]# mv upload/ /bbs
[root@server1 ~]# cd /bbs/upload
[root@server1 upload]# chmod 777 -R config/ data/ uc_client/ uc_server/
[root@server1 upload]# chmod 755 /usr/local/lnmp/mysql/data/
关于redis其他的主要作用,会重新写一篇来介绍,这篇只做了lnmp和redis的使用。而且这里只做简单的redis测试,所以只用到了redis主库。
LNMP+Redis工作机制:用户通过浏览器访问LNMP网站,并以用户名和密码登录到网站,默认Redis缓存中没有该用户名和密码对应列表,PHP程序会读取MySQL数据库中的用户名和密码,然后将用户名和密码缓存至Redis中,下次用户通过浏览器再次使用同样的用户名和密码登录网站,PHP无须从数据库中读取该用户名和密码信息,而是直接优先从Redis缓存中读取并返回,从而减轻Redis数据库的压力。
Redis除了可以缓存用户名和密码,还可以缓存PHP论坛各种数据。
要实现将LNMP PHP网站相关数据存入Redis,需要一台Redis服务器、PHP-Redis连接驱动、PHP代码配置等。
[root@redismas ~]# tar zxf redis-4.0.8.tar.gz
[root@redismas ~]# cd redis-4.0.8
##安装之前注意gcc等这些的安装
[root@redismas redis-4.0.8]# make PREFIX=/usr/local/redis install
[root@redismas redis-4.0.8]# cp redis.conf /usr/local/redis/
##将/usr/local/redis/bin/目录加入到环境变量配置文件/etc/profile末尾,并在终端使环境变量生效
[root@redismas redis-4.0.8]# export PATH=/usr/local/redis/bin:$PATH
[root@redismas redis-4.0.8]# source /etc/profile
##启动服务:
[root@redismas redis-4.0.8]# cd utils/
[root@redismas utils]# ./install_server.sh ##设置中一直默认回车就可以
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@redismas utils]# netstat -antlp |grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5560/redis-server 1
要确保PHP能够连接Reids缓存服务器,需要添加PHP-Redis扩展程序,也就是给PHP安装扩展模块,所以是在lnmp服务器上操作
[root@server1 ~]# unzip phpredis-master.zip
[root@server1 ~]# cd phpredis-master
[root@server1 phpredis-master]# phpize
[root@server1 phpredis-master]# ./configure --with-php-config=/usr/local/lnmp/php/bin/php-config --enable-redis
[root@server1 phpredis-master]# make && make install
Installing shared extensions: /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
##修改php.ini配置文件,添加redis.so模块,代码如下
[root@server1 phpredis-master]# vim /usr/local/lnmp/php/etc/php.ini
extension=redis.so
extension_dir = "/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226"
[root@server1 upload]# vim /bbs/upload/config/config_global.php
17 // -------------------------- CONFIG MEMORY --------------------------- //
18 $_config['memory']['prefix'] = 'JyBhBV_';
19 $_config['memory']['redis']['server'] = '172.25.70.2';
20 $_config['memory']['redis']['port'] = 6379;
21 $_config['memory']['redis']['pconnect'] = 1;
22 $_config['memory']['redis']['timeout'] = '0';
23 $_config['memory']['redis']['requirepass'] = '';
此时可以通过浏览器访问论坛网站,同时登录Redis服务器,执行命令redis-cli进入redis命令行,运行命令KEYS *
,存在以JyBhBV开头的key,则证明redis成功缓存。