mac+virtualbox+centos7+docker搭建lnmp环境

1.安装virtualbox
下载地址 https://www.virtualbox.org/wiki/Downloads

2.通过virtualbox安装centos7
下载地址 http://mirrors.aliyun.com/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-DVD-1503-01.iso

mac+virtualbox+centos7+docker搭建lnmp环境_第1张图片
mac+virtualbox+centos7+docker搭建lnmp环境_第2张图片
mac+virtualbox+centos7+docker搭建lnmp环境_第3张图片
mac+virtualbox+centos7+docker搭建lnmp环境_第4张图片
mac+virtualbox+centos7+docker搭建lnmp环境_第5张图片
mac+virtualbox+centos7+docker搭建lnmp环境_第6张图片

选择你下载的centos的镜像文件,然后开始安装
mac+virtualbox+centos7+docker搭建lnmp环境_第7张图片

点击确定后,然后点击启动(上面绿色箭头那个)

mac+virtualbox+centos7+docker搭建lnmp环境_第8张图片

mac+virtualbox+centos7+docker搭建lnmp环境_第9张图片

mac+virtualbox+centos7+docker搭建lnmp环境_第10张图片

mac+virtualbox+centos7+docker搭建lnmp环境_第11张图片

安装完以后进入虚拟机(鼠标点下虚拟机就进入了,想出来就按commad键),然后用root账号和密码进去

我习惯性的执行ifconfig,发现说找不到这个命令,这个时候你要执行

yum upgrade
yum install net-tools

执行完之后你就可以看到使用ifconfig了

3.宿主机与虚拟机之间网络互通
mac+virtualbox+centos7+docker搭建lnmp环境_第12张图片

看看虚拟机的ip是多少?
mac+virtualbox+centos7+docker搭建lnmp环境_第13张图片

然后在mac的终端上通过ssh就能登录到虚拟机上了,

ssh 192.168.1.108

4.安装docker
因为我们安装的是centos7,所以可以直接这么安装

yum install docker

启动docker服务

systemctl start docker

设置成开机启动

systemctl enable docker

5.下载docker镜像

docker  pull centos:centos7

6.进入容器

docker  run -i -t centos:centos7 /bin/bash

ls一下看到的就是容器内的文件了
如果要进入已经启动的容器,需要先安装nsenter,这个是在你的虚拟机里面操作的,帅哥美女们,请时刻记住你们操作的环境
由于虚拟机什么都没装,所以先安装一些必要的库

yum install gcc gcc-c++
mkdir -p /data/pkg
cd /data/pkg/
curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz | tar -zxf-; cd util-linux-2.24;
./configure --without-ncurses && make nsenter
cp nsenter /usr/local/bin/

装好之后,然后看看当前有哪些容器正在运行,docker ps
然后运行docker-enter 9e4bbed53a6d(这个字符串是docker ps出来之后,对应的CONTAINER ID)
要退出容器用exit就可以了。
7.安装nginx
先安装一些依赖库(这些是安装nginx\mysql\php需要的所有依赖)

yum upgrade
yum -y install net-tools wget tar pcre pcre-devel gcc gcc-c++ autoconf 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 openldap openldap-devel nss_ldap openldap-clients openldap-servers cmake make gd gd2 gd-devel gd2-devel bison perl-Module-Install.noarch vim
groupadd nginx
useradd -M -s /sbin/nologin  -g nginx nginx
mkdir -p /data/pkg/
cd /data/pkg/
wget http://nginx.org/download/nginx-1.6.3.tar.gz
tar -zxf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre  --with-http_realip_module --with-http_image_filter_module
make && make install

8.安装mysql

groupadd mysql
useradd -M -s /sbin/nologin -g mysql mysql
cd /data/pkg/
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz
tar -zxf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=system -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1  -DENABLED_LOCAL_INFILE=1
make && make install
mkdir -p /data/mysql/dbdata_3306
mkdir -p /data/mysql/dbdata_3307
cd /usr/local/mysql/
./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/dbdata_3306 --user=mysql
./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/dbdata_3307 --user=mysql
vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = admin
password = password
[mysqld3306]
socket = /data/mysql/dbdata_3306/mysql.sock
port = 3306
pid-file = /data/mysql/dbdata_3306/3306.pid
datadir = /data/mysql/dbdata_3306
user = mysql
skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
back_log = 50
max_connections = 300
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 2M
max_heap_table_size = 64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 1
server-id = 1
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 200M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120
[mysqld3307]
socket = /data/mysql/dbdata_3307/mysql.sock
port = 3307
pid-file = /data/mysql/dbdata_3307/3307.pid
datadir = /data/mysql/dbdata_3307
user = mysql
skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
back_log = 50
max_connections = 300
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 2M
max_heap_table_size = 64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time = 1
server-id = 1
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 200M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
prompt=\\u@\\d \\R:\\m>
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
vim /etc/profile
#增加一行
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
bin/mysqld_multi start 3306
bin/mysqld_multi start 3307
/usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/mysql/dbdata_3306/mysql.sock
/usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/mysql/dbdata_3306/mysql.sock
vim /etc/rc.local
/usr/local/mysql/bin/mysqld_multi start 3306,3307

9.安装php
先安装依赖库

cd /data/pkg/
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
tar -zxf  jpegsrc.v9.tar.gz
cd jpeg-9/
./configure --prefix=/usr/local/ --enable-shared --enable-static
make && make install
cd ../
wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
tar -zxf libpng-1.6.2.tar.gz
cd libpng-1.6.2
./configure --prefix=/usr/local/
make && make install
cd ../
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
tar -zxf freetype-2.4.12.tar.gz
cd freetype-2.4.12
./configure --prefix=/usr/local/
make && make install
cd ../
wget --content-disposition "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"
wget --content-disposition "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
wget --content-disposition "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"
tar -zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/
make && make install
cd libltdl/
./configure --prefix=/usr/local/ --enable-ltdl-install
make && make install
cd ../../
tar -zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure --prefix=/usr/local/
make && make install
tar -zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
export LDFLAGS="-L/usr/local/lib -L/usr/lib"
export CFLAGS="-I/usr/local/include -I/usr/include"
vim /etc/ld.so.conf
/usr/local/lib
ldconfig
make && make install
./configure --prefix=/usr/local/ --with-libmcrypt-prefix=/usr/local
make && make install

安装php

cd ../
wget  --content-disposition "http://cn2.php.net/get/php-5.6.7.tar.gz/from/this/mirror"
tar -zxf php-5.6.7.tar.gz
cd php-5.6.7
export LIBS="-lm -ltermcap -lresolv"
export LD_LIBRARY_PATH="/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/usr/local/ --with-jpeg-dir=/usr/local/ --with-png-dir=/usr/local/ --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/ --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap  --with-pdo-mysql --disable-opcache
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/

你可能感兴趣的:(mac-os-x)