centos7 安裝Nginx-1.9.14、php-5.6.20、Mysql-5.7.11以及Mongodb、memcached、redis

 

×導讀:centos7的版本是1511; nginx的版本:1.9.14 ;php的版本:5.6.20 ;mysql的版本:5.7.11; mongodb的版本:3.2.4 ;redis的版本:3.0.7;  memcached的版本:1.4.25.

關於版本:

centos7的版本是1511

nginx的版本:1.9.14

php的版本:5.6.20

mysql的版本:5.7.11

mongodb的版本:3.2.4

redis的版本:3.0.7

memcached的版本:1.4.25

 

服務部署目錄:

/servers

/servers/nginx

/servers/libmctypt

/servers/libmemcached

/servers/php

/servers/boost

/servers/mysql

/servers/redis

/servers/libevent

/servers/memcached

/servers/mongodb

 

運行代碼目錄:

/documentRoot

 

***********************************準備 start****************************************

[root@pangyiguang ~]# yum install vim

 

安裝一些依賴包:

[root@pangyiguang ~]# yum install gcc gcc-c++ cmake autoconf

[root@pangyiguang ~]# yum install openssl-devel libcurl-devel wget tar m4 git-core boost-static  npm ncurses-devel which ncurses-static zlib-devel zlib-static

[root@pangyiguang ~]# yum install libxml2 libxml2-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel

 

設置防火牆:

添加以下可信埠到防火牆的public區域,並使其生效:

 

[root@pangyiguang ~]# firewall-cmd –zone=public –add-port=80/tcp –permanent

[root@pangyiguang ~]# firewall-cmd –zone=public –add-port=3306/tcp –permanent

[root@pangyiguang ~]# firewall-cmd –zone=public –add-port=11211/tcp –permanent

[root@pangyiguang ~]# firewall-cmd –zone=public –add-port=6379/tcp –permanent

[root@pangyiguang ~]# firewall-cmd –zone=public –add-port=27017/tcp –permanent

[root@pangyiguang ~]# firewall-cmd –reload

 

***********************************準備 end****************************************

 

***********************************下載與解壓 start****************************************

進入主目錄:

[root@pangyiguang ~]# cd ~

 

下載所需要的安裝包:

php的memcached擴展需要的安裝包:

[root@pangyiguang ~]# wget https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz

[root@pangyiguang ~]# wget http://pecl.php.net/get/memcached-2.2.0.tgz

 

安裝php時需要的安裝包:

[root@pangyiguang ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

[root@pangyiguang ~]# wget http://cn2.php.net/distributions/php-5.6.20.tar.gz

[root@pangyiguang ~]# wget http://download.savannah.gnu.org/releases/freetype/freetype-2.7.tar.gz
[root@pangyiguang ~]# wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz

nginx安裝包:

[root@pangyiguang ~]# wget http://nginx.org/download/nginx-1.9.14.tar.gz

 

mysql最新的安裝包:

[root@pangyiguang ~]# wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.11.tar.gz

 

mongodb的最新的安裝包:

[root@pangyiguang ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.2.4.tgz

 

redis的安裝包:

[root@pangyiguang ~]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz

 

memcached服務的安裝包:

[root@pangyiguang ~]# wget http://www.memcached.org/files/memcached-1.4.25.tar.gz

[root@pangyiguang ~]# wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz

解壓相應的安裝包:

 

[root@pangyiguang ~]# tar zxf libmemcached-1.0.18.tar.gz

[root@pangyiguang ~]# tar zxf memcached-2.2.0.tgz

[root@pangyiguang ~]# tar zxf libmcrypt-2.5.7.tar.gz

[root@pangyiguang ~]# tar zxf php-5.6.20.tar.gz

[root@pangyiguang ~]# tar zxf jpegsrc.v9b.tar.gz
[root@pangyiguang ~]# tar zxf freetype-2.7.tar.gz

[root@pangyiguang ~]# tar zxf nginx-1.9.14.tar.gz

[root@pangyiguang ~]# tar zxf memcached-1.4.25.tar.gz

[root@pangyiguang ~]# tar zxf mongodb-linux-x86_64-amazon-3.2.4.tgz

[root@pangyiguang ~]# tar zxf mysql-5.7.11.tar.gz

[root@pangyiguang ~]# tar zxf redis-3.0.7.tar.gz

[root@pangyiguang ~]# tar zxf libevent-2.0.22-stable.tar.gz

 

***********************************下載與解壓 end****************************************

 

 

***********************************nginx安裝 start****************************************

 

[root@pangyiguang ~]# cd ~/nginx-1.9.14/

[root@pangyiguang ~]# ./configure –prefix=/servers/nginx –with-http_ssl_module –with-pcre

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

***********************************nginx安裝 end****************************************

 

 

***********************************mysql與配置 start****************************************

添加mysql用戶組與用戶:

[root@pangyiguang ~]# groupadd mysql

[root@pangyiguang ~]# useradd -r -g mysql mysql

 

[root@pangyiguang ~]# cd ~/mysql-5.7.11/

 

編譯安裝:

 

[root@pangyiguang ~]# cmake -DCMAKE_INSTALL_PREFIX=/servers/mysql -DMYSQL_UNIX_ADDR=/servers/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/servers/mysql/data -DMYSQL_USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/servers/boost

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

創建數據存放的目錄:

[root@pangyiguang ~]# cd /servers/mysql/

[root@pangyiguang ~]# mkdir data

[root@pangyiguang ~]# chown -R mysql:mysql data

 

[root@pangyiguang ~]# cp /servers/mysql/support-files/my-default.cnf /etc/my.cnf

 

配置mysql的配置文件:

[root@pangyiguang ~]# vim /etc/my.cnf

 

#########################my.cnf###########################

 

# For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It’s a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

 

[mysqld]

 

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

 

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

 

# These are commonly set, remove the # and set as required.

basedir = /servers/mysql

datadir = /servers/mysql/data

port = 3306

# server_id = …..

socket = /servers/mysql/mysql.sock

user = mysql

 

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

#########################my.cnf###########################

 

初始化mysql的數據服務:

[root@pangyiguang ~]# /servers/mysql/bin/mysqld –initialize-insecure  –explicit_defaults_for_timestamp –sql-mode=NO_AUTO_CREATE_USER

 

[root@pangyiguang ~]# /servers/mysql/bin/mysqld_safe &

[root@pangyiguang ~]# /servers/mysql/bin/mysqladmin -u root -p shutdown

[root@pangyiguang ~]# cp /servers/mysql/support-files/mysql.server /etc/init.d/mysql

 

[root@pangyiguang ~]# service mysql start

 

鏈接mysql並修改密碼為:123456

[root@pangyiguang ~]# /servers/mysql/bin/mysql -u root mysql

 

##################################################

mysql> use mysql;

mysql> desc user;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@”%” IDENTIFIED BY “root”;

mysql> update user set authentication_string = password(‘123456′) where User=’root’;

mysql> select Host,User,authentication_string from user where User=’root’;

mysql> flush privileges;

mysql> exit

##################################################

 

***********************************mysql安裝與配置 end****************************************

 

 

***********************************php start****************************************

先安裝mcrypt依賴:

[root@pangyiguang ~]# cd ~/libmcrypt-2.5.7/

[root@pangyiguang ~]# ./configure –prefix=/servers/libmctypt

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

再安裝gd庫需要的依賴:

[root@pangyiguang ~]# cd ~/jpeg-9b/

[root@pangyiguang ~]# ./configure –prefix=/servers/jpeg

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

[root@pangyiguang ~]# cd ~/freetype-2.7/

[root@pangyiguang ~]# ./configure –prefix=/servers/freetype

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

其中jpeg是gd庫對jpeg的支持,freetype是gd庫對字體文件的支持,默認都是不支持的。

 

編譯安裝:

[root@pangyiguang ~]# cd ~/php-5.6.20/

[root@pangyiguang ~]# ./configure –prefix=/servers/php  –with-config-file-path=/servers/php/etc/php.ini \

–enable-fpm –with-mcrypt=/servers/libmctypt –with-openssl \

–enable-mbstring –with-curl –with-pdo-mysql –with-pdo-sqlite  –enable-soap –enable-shmop \

–enable-inline-optimization –with-bz2  –with-zlib –enable-sockets \

–enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex \

–with-mhash –enable-zip –with-pcre-regex –with-mysqli –with-sqlite3 –enable-opcache \

–enable-exif –with-gd –with-jpeg-dir=/servers/jpeg/ –with-freetype-dir=/servers/freetype/

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make test

[root@pangyiguang ~]# make clean

web運行的www用戶:

[root@pangyiguang ~]# groupadd www

[root@pangyiguang ~]# useradd -g www www

 

[root@pangyiguang ~]# cp /servers/php/etc/php-fpm.conf.default /servers/php/etc/php-fpm.conf

 

編輯配置文件:

[root@pangyiguang ~]# vim /servers/php/etc/php-fpm.conf

 

###########php-fpm.conf###############

把 25,32,,89 行的注釋去掉

pid = run/php-fpm.pid

error_log = log/php-fpm.log

daemonize = yes

 

把 149,150 行改為www

user = www

group = www

 

把 164 行 的

listen = 127.0.0.1:9000

改為

listen = run/php-fpm.sock

 

把 175,176,177 行改為www

listen.owner = www

listen.group = www

listen.mode = 0660

 

###########php-fpm.conf###############

 

[root@pangyiguang ~]# mkdir /servers/php/run

[root@pangyiguang ~]# chown -R www:www /servers/php/run

 

 

把php二進位執行文件目錄放到環境變數,順便也把mysql的也放了,最好把其他安裝的服務也放一下。

[root@pangyiguang ~]# vim ~/.bash_profile

 

######################~/.bash_profile############################

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

 

# User specific environment and startup programs

 

PATH=$PATH:$HOME/bin:/servers/mysql/bin:/servers/php/bin

 

export PATH

 

#####################~/.bash_profile#############################

 

使剛配置的環境變數生效:

[root@pangyiguang ~]# source ~/.bash_profile

安裝memcache、redis、mongodb的php擴張:

[root@pangyiguang ~]# pecl install memcache redis mongodb

 

編譯安裝php擴展memcached的依賴包:

[root@pangyiguang ~]# cd ~/libmemcached-1.0.18/

[root@pangyiguang ~]# ./configure –prefix=/servers/libmemcached

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

編譯安裝php擴展memcached:

[root@pangyiguang ~]# cd ~/memcached-2.2.0/

[root@pangyiguang ~]# phpize

[root@pangyiguang ~]# ./configure –with-php-config=/servers/php/bin/php-config –with-libmemcached-dir=/servers/libmemcached –disable-memcached-sasl

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

[root@pangyiguang ~]# ls /servers/php/lib/php/extensions/no-debug-non-zts-20131226/

 

###################

memcached.so  memcache.so  mongodb.so  opcache.a  opcache.so  redis.so

###################

把剛剛安裝的擴展寫入php.ini配置文件:

[root@pangyiguang ~]# vim /servers/php/etc/php.ini

 

#####################/servers/php/etc/php.ini#############################

extension=memcache.so

extension=memcached.so

extension=redis.so

extension=mongodb.so

 

date.timezone = Asia/Shanghai

#####################/servers/php/etc/php.ini#############################

 

啟動php-fpm服務進程:

[root@pangyiguang ~]# /servers/php/sbin/php-fpm -c /servers/php/etc/php.ini -y /servers/php/etc/php-fpm.conf

 

 

***********************************php end****************************************

 

 

 

***********************************nginx&&php start****************************************

創建一個網站代碼的目錄:

[root@pangyiguang ~]# mkdir /documentRoot

[root@pangyiguang ~]# cp /servers/nginx/html/* /documentRoot/

 

編輯nginx配置文件,使其訪問的php指到php解析:

[root@pangyiguang ~]# vim /servers/nginx/conf/nginx.conf

 

#####################/servers/nginx/conf/nginx.conf#############################

user  www;

worker_processes  2;

 

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

 

events {

worker_connections  1024;

}

 

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”‘;

 

access_log  logs/access.log  main;

 

sendfile        on;

keepalive_timeout  65;

gzip  on;

 

server {

listen       80;

server_name  localhost;

 

location / {

root   /documentRoot;

index  index.html index.htm index.php;

}

 

error_page  404              /404.html;

 

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

 

location ~ \.php$ {

root           /documentRoot;

fastcgi_pass   unix:/servers/php/run/php-fpm.sock;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

 

location ~ /\.ht {

deny  all;

}

}

}

#####################/servers/nginx/conf/nginx.conf#############################

 

啟動nginx服務:

[root@pangyiguang ~]# /servers/nginx/sbin/nginx

 

 

通過瀏覽器http訪問:

memcache、memcached的擴展:

 

mongodb的擴展:

 

redis的擴展:

 

gd:

***********************************nginx&&php end****************************************

 

 

 

***********************************memcached start****************************************

編譯安裝memcached服務的依賴libevent:

[root@pangyiguang ~]# cd ~/libevent-2.0.22-stable/

[root@pangyiguang ~]# ./configure –prefix=/servers/libevent

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

編譯安裝memcached:

[root@pangyiguang ~]# cd ~/memcached-1.4.25/

[root@pangyiguang ~]# ./configure –prefix=/servers/memcached –with-libevent=/servers/libevent/

[root@pangyiguang ~]# make && make install

[root@pangyiguang ~]# make clean

 

啟動memcached:

[root@pangyiguang ~]# /servers/memcached/bin/memcached -d start -m 512 -u memcached -c 1024 -p 11211 -P /tmp/memcached.pid

 

-d start|restart|stop 啟動|重啟|停止memcached服務

-m 指定最大使用內存大小

-c 最大同時連接數

-p 指定埠號

-P 指定進程文件

 

***********************************memcached end****************************************

 

***********************************redis start****************************************

[root@pangyiguang ~]# mkdir /servers/redis

 

編譯安裝:

[root@pangyiguang ~]# cd ~/redis-3.0.7/

[root@pangyiguang ~]# make PREFIX=/servers/redis/ install

[root@pangyiguang ~]# make distclean

 

[root@pangyiguang ~]# mkdir /servers/redis/etc

[root@pangyiguang ~]# cp ~/redis-3.0.7/redis.conf /servers/redis/etc/redis.conf

 

編輯redis的配置文件:

[root@pangyiguang ~]# vim /servers/redis/etc/redis.conf

把 42 行 改為 後台運行

daemonize yes

 

啟動redis服務:

[root@pangyiguang ~]# /servers/redis/bin/redis-server /servers/redis/etc/redis.conf

 

連接客戶端:

[root@pangyiguang ~]# redis-cli

 

***********************************redis end****************************************

 

***********************************mongodb start****************************************

創建一些待會所需要部署目錄:

[root@pangyiguang ~]# mkdir /servers/mongodb

[root@pangyiguang ~]# mkdir /servers/mongodb/etc

[root@pangyiguang ~]# mkdir /servers/mongodb/data

[root@pangyiguang ~]# mkdir /servers/mongodb/logs

 

[root@pangyiguang ~]# cp ~/mongodb-linux-x86_64-amazon-3.2.4/* /servers/mongodb/

 

編輯mongodb的配置文件:

[root@pangyiguang ~]# vim /servers/mongodb/etc/mongo.conf

 

#####################/servers/mongodb/etc/mongo.conf#############################

port = 27017

bind_ip = 127.0.0.1

fork = true

auth = false

 

pidfilepath = /servers/mongodb/mongo.pid

dbpath = /servers/mongodb/data

logpath = /servers/mongodb/logs/mongo.log

logappend = true

#####################/servers/mongodb/etc/mongo.conf#############################

 

啟動mongodb:

[root@pangyiguang ~]# /servers/mongodb/bin/mongod –config /servers/mongodb/etc/mongo.conf

 

***********************************mongodb end****************************************

 

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營