nginx+php+redis+mysql编译安装

前言

最近在安装nginx+php+redis+mysql的环境,踩了很多坑,以下是从坑里趟出来的nginx+php+redis+mysql的编译安装过程

1.安装nginx (版本1.16.0)

1.1 添加www用户
useradd www -s /sbin/nologin
1.2 安装依赖环境
yum install gcc gcc-c++ automake autoconf libtool make
1.3 解压安装包
tar -xzf nginx-1.16.0.tar.gz
tar -xzf openssl-1.1.1c.tar.gz
tar -jxf pcre-8.39.tar.bz2
tar -xzf zlib-1.2.11.tar.gz

如果提示

tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

原因为缺少bzip2

yum install bzip2

拓展,如果需要nginx的fair功能,需要下载安装

官方github下载地址:https://github.com/gnosek/nginx-upstream-fair
如果从github下载最新版本,在安装到nginx 1.14.0版本时,会报出编译错误。需要对源码做一些修改,修改参照(如果你看到这篇文章时,github主已经修改了该bug,或者你用的是nginx 1.14.0以下版本,请忽视...):https://github.com/gnosek/nginx-upstream-fair/pull/27/commits/ff979a48a0ccb9217437021b5eb9378448c2bd9e

543    -    if (us->port == 0 && us->default_port == 0) {
543    +    if (us->port == 0) {
                ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
                      "no port in upstream \"%V\" in %s:%ui",
                      &us->host, us->file_name, us->line);

    u.host = us->host;
553     -    u.port = (in_port_t) (us->port ? us->port : us->default_port);
553     +    u.port = us->port;

简单翻译一下,fair采用的不是内建负载均衡使用的轮换的均衡算法,而是可以根据页面大小、加载时间长短智能的进行负载均衡。

下载地址:nginx-upstream-fair

解压:

unzip  nginx-upstream-fair-master.zip
模块安装
未安装Nginx
切换到Nginx目录执行一下操作
配置:

./configure --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --add-module=/home/nginx-upstream-fair-master
编译安装

make && make intstall
安装过Nginx
切换到Nginx目录执行一下操作

配置

./configure --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --add-module=/home/nginx-upstream-fair-master
编译

make
复制Nginx

 cp objs/nginx /usr/local/nginx/nginx
配置实现
upstream backserver { 
fair; 
server 192.168.0.14; 
server 192.168.0.15; 
} 
注意事项
已安装Nginx,配置第三方模块时,只需要--add-module=/第三方模块目录,然后make编译一下就可以,不要 make install 安装。编译后复制objs下面的Nginx到指定目录下。

配置中path自行定义即可

1.4 编译安装nginx
cd /apps/nginx-1.16.0

./configure --prefix=/apps/nginx  --user=www --group=www --with-http_stub_status_module --with-http_auth_request_module --with-http_realip_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl-opt='enable-weak-ssl-ciphers' --with-http_stub_status_module --with-ld-opt=-ljemalloc --with-openssl=/apps/openssl-1.1.1c --with-pcre=/apps/pcre-8.39 --with-zlib=/apps/zlib-1.2.11

make && make install

此时/apps下会产生nginx目录
1.5 添加/etc/init.d/nginx启动脚本
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   licess
# website:  https://lnmp.org

NGINX_BIN='/apps/nginx/sbin/nginx'
CONFIG='/apps/nginx/conf/nginx.conf'

case "$1" in
    start)
        echo -n "Starting nginx... "

        PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
        if [ "$PID" != "" ]; then
            echo "nginx (pid $PID) already running."
            exit 1
        fi

        $NGINX_BIN -c $CONFIG

        if [ "$?" != 0 ]; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    stop)
        echo -n "Stoping nginx... "

        PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
        if [ "$PID" = "" ]; then
            echo "nginx is not running."
            exit 1
        fi

        $NGINX_BIN -s stop

        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            $0 force-quit
        else
            echo " done"
        fi
        ;;

    status)
        PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
        if [ "$PID" != "" ]; then
            echo "nginx (pid $PID) is running..."
        else
            echo "nginx is stopped."
            exit 0
        fi
        ;;

    force-quit|kill)
        echo -n "Terminating nginx... "

        PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
        if [ "$PID" = "" ]; then
            echo "nginx is is stopped."
            exit 1
        fi

        kill $PID

        if [ "$?" != 0 ]; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    reload)
        echo -n "Reload nginx... "

        PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
        if [ "$PID" != "" ]; then
            $NGINX_BIN -s reload
            echo " done"
        else
            echo "nginx is not running, can't reload."
            exit 1
        fi
        ;;

    configtest)
        echo -n "Test nginx configure files... "

        $NGINX_BIN -t
        ;;

    *)
        echo "Usage: $0 {start|stop|restart|reload|status|configtest|force-quit|kill}"
        exit 1
        ;;

esac

至此nginx编译安装完毕

2.安装php

2.1 安装依赖环境
yum -y install automake autoconf libtool make gcc gcc-c++ glibc libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libcurl libcurl-devel jemalloc jemalloc-devel libicu-devel libzip-devel
2.2 安装freetype(php需要freetype,而freetype是安装在gd中的)
cd /apps
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.bz2
tar -jxf freetype-2.4.0.tar.bz2
cd freetype-2.4.0
# 安装到/usr/local/freetype
./configure --prefix=/usr/local/freetype
make && make install
2.2 php编译:
tar -xzf php-7.2.21.tar.gz
cd /apps/php-7.2.21 

./configure  --prefix=/apps/php --with-config-file-path=/apps/php/etc --with-config-file-scan-dir=/apps/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl

make all install
编译过程中报错

报错1: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution 解决办法:

yum remove -y libzip
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

报错2:configure: error: off_t undefined; check your library configuration 解决办法:

#添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

#然后 更新配置
ldconfig -v

报错3:configure: error: libxml2 not found. Please check your libxml2 installation.

yum install -y libxml2-devel

报错4:configure: error: Please reinstall the BZip2 distribution

yum install -y bzip2-devel

报错5:configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

yum install -y curl-devel

报错6:configure: error: jpeglib.h not found.

yum install -y libjpeg-devel

报错7configure: error: png.h not found.

yum install -y libpng-devel

报错8:configure: error: freetype-config not found.

yum install -y freetype-devel

报错9:configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install -y libxslt-devel

报错10:configure: error: Please reinstall the libzip distribution

yum install -y libzip-devel

报错11:checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11

#先删除旧版本
yum remove -y libzip

#下载编译安装
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

报错12:off_t undefined 报错

checking libzip... yes
checking for the location of zlib... /usr
checking for pkg-config... (cached) /usr/bin/pkg-config
checking for libzip... in default path: found in /usr/local
checking for zip_open in -lzip... yes
checking for zip_file_set_encryption in -lzip... yes
checking for zip_libzip_version in -lzip... no
checking stdbool.h usability... yes
checking stdbool.h presence... yes
checking for stdbool.h... yes
checking fts.h usability... yes
checking fts.h presence... yes
checking for fts.h... yes
checking for int8_t... (cached) yes
checking for int16_t... (cached) yes
checking for int32_t... (cached) yes
checking for int64_t... (cached) yes
checking for uint8_t... (cached) yes
checking for uint16_t... (cached) yes
checking for uint32_t... (cached) yes
checking for uint64_t... (cached) yes
checking for ssize_t... yes
checking size of short... (cached) 2
checking size of int... (cached) 4
checking size of long... (cached) 8
checking size of long long... (cached) 8
checking size of off_t... 0
configure: error: off_t undefined; check your library configuration
off_t 类型是在 头文件 unistd.h中定义的,
在32位系统 编程成 long int ,64位系统则编译成 long long int ,
在进行编译的时候 是默认查找64位的动态链接库,
但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,
这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。
#添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

#然后 更新配置
ldconfig -v

报错13:usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
2.3 复制配置文件
2.3.1 /apps/php/etc/php-fpm.conf
[global]
pid = /apps/php/var/run/php-fpm.pid
error_log = /apps/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 40
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 40
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
2.3.2 /apps/php/etc/php.ini
[PHP]
engine = On
short_open_tag = On
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 300
max_input_time = 60
memory_limit = 512M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 50M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
cgi.fix_pathinfo=0
file_uploads = On
upload_max_filesize = 50M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = PRC
[filter]
[iconv]
[imap]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = -1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[dba]
[opcache]
[curl]
[openssl]
2.3.4 启动脚本 /etc/init.d/php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/apps/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"

wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting php-fpm "

        $php_fpm_BIN --daemonize $php_opts

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -QUIT `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    status)
        if [ ! -r $php_fpm_PID ] ; then
            echo "php-fpm is stopped"
            exit 0
        fi

        PID=`cat $php_fpm_PID`
        if ps -p $PID | grep -q $PID; then
            echo "php-fpm (pid $PID) is running..."
        else
            echo "php-fpm dead but pid file exists"
        fi
    ;;

    force-quit)
        echo -n "Terminating php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -TERM `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reload service php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -USR2 `cat $php_fpm_PID`

        echo " done"
    ;;

    configtest)
        $php_fpm_BIN -t
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
    ;;

esac
至此php安装完毕,但是之后的步骤会添加redis拓展,还需要修改配置文件

3. 安装redis

3.1 下载源码并解压
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -xzf redis-5.0.5.tar.gz
cd redis-5.0.5
3.2 编译
yum -y install gcc gcc-c++ kernel-devel
make
等待编译完成
3.3 安装
make PREFIX=/apps/redis install
mkdir /apps/redis/etc/    #创建redis配置文件目录
mkdir -p /data/data/redis /data/logs/redis   #创建reids数据目录、日志目录
cp redis.conf /apps/redis/etc/
3.4 更改配置
vim /apps/redis/etc/redis.conf

bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /apps/redis/redis.pid
loglevel notice
logfile "/data/logs/redis/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/data/redis/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
3.5 配置环境变量
vim /etc/profile
export PATH="$PATH:/apps/redis/bin"
# 保存退出

# 让环境变量立即生效
source /etc/profile
3.6 配置启动脚本
vim /etc/init.d/redis

#!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/apps/redis/bin/redis-server
REDIS_CLI=/apps/redis/bin/redis-cli

PIDFILE=/apps/redis/redis.pid
CONF="/apps/redis/etc/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ] 
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(/usr/bin/cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac

chmod 755 /etc/init.d/redis
3.7 开启自启动设置
# 复制脚本文件到init.d目录下
cp redis /etc/init.d/

# 给脚本增加运行权限
chmod +x /etc/init.d/redis

# 查看服务列表
chkconfig --list

# 添加服务
chkconfig --add redis

# 配置启动级别
chkconfig --level 2345 redis on
8.启动测试
systemctl start redis   #或者 /etc/init.d/redis start  
systemctl stop redis   #或者 /etc/init.d/redis stop

# 查看redis进程
ps -el|grep redis

# 端口查看
netstat -an|grep 6379
至此redis安装完毕

4. 安装php拓展phpredis

4.1 下载&&编译&&安装:
wget https://codeload.github.com/phpredis/phpredis/zip/develop
改名:
mv develop ./phpredis-develop.zip
unzip phpredis-develop.zip
cd phpredis-develop
重新编译phpize
phpize
执行编译:
./configure --with-php-config=/apps/php/bin/php-config
make && make install
4.2 修改php.ini配置文件加上 extension=redis.so
vim /apps/php/conf.d/007-redis.ini
extension = "redis.so"
4.3 重启php-fpm
/etc/init.d/php-fpm restart
至此php的redis拓展安装完毕

5. 安装mysql

5.1 前言

最后一步了,干巴得!

5.2 安装
5.2.1 注:安装版本为Mysql5.7.20(下载链接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz)

为什么要强调版本呢,因为不同的版本,碰到的情况不一样,从5.7.18开始,mysql 虽然也会生成 my.cnf 配置文件,但是和以前的 default.cnf 不一样,不仅位置还有内容。 本来准备将资源上传到 CSDN 的,但是文件太大,限制了。所以自行安装包自行解决吧。我使用的是 .tar.gz 式安装包。

5.2.1.1 卸载自带的 Mysql 。一般没有,但是检查下最好
rpm -qa | grep mysql

如果搜到了,假设搜到的叫做 mysql-xxx-xx,然后卸载它(替换自己的名字)。如果没有搜到,不用管了。

rpm -e --nodeps mysql-xxx-xx
5.2.1.2 解压
cd /apps
tar -xvf mysql-5.7.20-linux-glibc2.5-i686.tar.gz
5.2.1.3 修改mysql文件夹名字、创建数据库的数据目录、日志目录
mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
mkdir -p /data/data/mysql /data/logs/mysql
5.2.1.4 创建用户组mysql,创建用户mysql并将其添加到用户组mysql中,并赋予读写权限
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql.mysql mysql/
5.2.1.5 配置文件 my.cnf ,这是重点。可以去 etc 下找找是否存在 my.cnf 如果不存在自己新建一个,如果存在里面应该会有一些内容,将以前的内容注释,然后添加我们自己的
vim /etc/my.cnf

[client]
port = 3306
[mysqld]
default-storage-engine=INNODB
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

basedir=/apps/mysql
datadir=/data/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

slow_query_log =1
slow_query_log_file=/data/logs/mysql/mysql_slow.log
max_connections=1000
default-time_zone = '+8:00'

log-error=/data/logs/mysql/mysql.log
pid-file=/data/logs/mysql/mysql.pid

!includedir /etc/my.cnf.d
5.2.1.6 初始化数据库 这一步坑比较多
yum install libaio

/apps/mysql/bin/mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/data/mysql --lc_messages_dir=/apps/mysql/share --lc_messages=en_US

这一步可能会报错如下

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

这是因为前面yum安装的libnuma.so.1,但安装时默认安装的是32的,但db2需要的是64位的所以我们需要先卸载libnuma.so.1 再安装

yum remove libnuma.so.1
yum -y install numactl.x86_64

这里安装完成后,在运行如上语句

/apps/mysql/bin/mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/data/mysql --lc_messages_dir=/apps/mysql/share --lc_messages=en_US
5.2.1.7 查看密码 运行服务端 mysql service 登录mysql
启动服务端
/apps/mysql/support-files/mysql.server start

查看密码
cat /data/logs/mysql/mysqld.log

登录
/apps/mysql/bin/mysql -uroot -p
输入密码
5.2.1.8 修改初始密码,并授权root用户可以远程访问
set password=password('新密码');
grant all privileges on *.* to 'root'@'%' identified by 'yourpasswd' with grant option;   #授权root可以远程登录(此操作须谨慎,如果确认开启一定要设置好防火墙,限制访问ip)
flush privileges;

特别注意上述命令是进入 mysql 后才能执行

5.2.1.9 将 mysql 服务添加到开机自启
cd /apps/mysql/support-files

cp mysql.server /etc/init.d/mysqld

chkconfig --add mysqld
5.2.2.0 使用service mysqld命令启动/停止服务
service mysqld start/stop/restart
5.2.2.1 为了避免每次都输入mysql的全路径/apps/mysql/bin/mysql,可将其加入环境变量中,在/etc/profile最后加入两行命令
echo 'export PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

source /etc/profile

这样就可以在shell中直接输入mysql命令来启动客户端程序了

mysql -uroot -p
ok,done.

你可能感兴趣的:(nginx+php+redis+mysql编译安装)