一、安装CentOs容器
1.进入docker下载CentOs,这里我使用的CentOs6.8
docker pull centos:6.8
2.创建容器
sudo docker run --privileged --cap-add SYS_ADMIN -e container=docker -it --name lnmp -p 80:80 -p 3306:3306 -d -v /Users/qiao/www:/home/www --restart=always centos:6.8
--privileged 指定容器是否是特权容器。这里开启特权模式。
--cap-add SYS_ADMIN 添加系统的权限。
-e container=docker 设置容器的类型。
-it 启动互动模式。
-p 端口映射,为了方便本地连接。
-v 映射目录,使本地的目录和容器的目录共享
--name 容器名称
3.进入容器
docker exec -ti lnmp /bin/bash
二、安装lnmp环境
环境我这里选择的是,nginx:latest(最新版本)mysql(5.7.21)php(7.0.23)
1.首先安装依赖包
yum -y install 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 make cmake libtool* git tree
2.安装libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar zxvf libiconv-1.14.tar.gz cd libiconv-1.14/ ./configure --prefix=/usr/local make && make install
3.安装libmcrypt
tar -zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure make make install cd libltdl/ ./configure --enable-ltdl-install make make install
4.安装mhash
tar -zxvf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9 ./configure make make install
5.安装mcrypt
tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./configure make make install
6.软链
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
7.安装mysql 5.7
1.解压 tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 2.移动到/usr/local下 mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql 3.添加用户组和用户(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限) groupadd mysql useradd -r -g mysql -s /bin/false mysql 4.进入安装目录 cd /usr/local/mysql 5.修改当前目录拥有者为新建的mysql用户 chown -R mysql:mysql ./ 6.安装mysql的一些依赖包(不安装会报错) yum -y install numactl libaio 7.安装mysql ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize 8.开启mysql服务 ./support-files/mysql.server start 9.将mysql进程放入系统进程中 cp support-files/mysql.server /etc/init.d/mysqld 10.重新启动mysql服务 service mysqld restart 11.为mysql设置环境变量 vi /etc/profile 添加 export PATH=$PATH:/usr/local/mysql/bin 刷新环境变量 source /etc/profile 12.重设mysql密码(这里使用简单粗暴的方法) (1)关闭mysql服务 service mysqld stop (2)进入mysql下bin目录 cd /usr/local/bin (3)运行 mysqld_safe --skip-grant-tables & (4)登陆mysql并修改密码 mysql -u root -p use mysql update user set authentication_string=PASSWORD('root') where User='root'; quit; service mysqld restart;
再次进入mysql后,会提示你修改密码,输入
alter user user() identified by '123456';
8.安装pcre
tar -zxvf pcre-8.41.tar.gz cd pcre-8.31 ./configure make && make install
9.安装zlib
tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make && make install
10.openssl安装
tar -zxvf openssl-1.0.1c.tar.gz cd openssl-1.0.1c ./config make && make install
启动mongodb
./mongod --config mongodb.conf
启动memcached
memcached -d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 1024 –P /var/memcached/memcached.pid