×导读: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…