l=>linux

n=>nginx

m=>mysql (主从)

r=>redis(临时主从,永久主从)

p=>php

 

1、准备

 

1.1、安装vagrant、VirtualBox

 

附件地址 https://pan.baidu.com/s/1jKgUSpK 

 

1.2、在D盘创建cuzn目录,把Vagrantfile、docker和box拷贝到D:/cuzn/下,再创建目录D:/cuzn/data/etc和D:/cuzn/data/www

 

 

 

2、用vagrant启动linux:

 

2.1、打开主机命令行窗口(cmd.exe),并进入到当前目录下

D:

cd cuzn

 

2.2、初始化vagrant并启动linux:

#vagrant box add inviqa/centos-7-minimal

vagrant up

 

2.3、登入linux

vagrant ssh

 

2.4、在linux中运行,并退出:

sudo yum -y update && yum -y install kernel-headers kernel-devel

exit

 

2.5、在主机安装vagrant插件,并重启

vagrant plugin install vagrant-vbguest

vagrant reload

 

2.6、使用SecureCRT登入linux

主机:127.0.0.1

端口:2218 (从Vagrantfile中查看)

用户名:root

密码:vagrant

 

 

 

3、linux 设置

 

3.1、中文支持

yum -y update

yum -y install kde-l10n-Chinese && yum -y reinstall glibc-common

localedef -c -f UTF-8 -i zh_CN zh_CN.utf8

 

vi /etc/locale.conf 

修改为:

LANG="zh_CN.UTF-8"

LANGUAGE="zh_CN:zh"

保存

 

3.2、修改时区:

查看(看时间和时区对不对,时区要为+0800):

date -R; date +%z

 

修改时区:

rm -f /etc/localtime 

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

 

如果时间不对,可以修改系统日期时间(假设15:48:00 2017-12-16是当前时间)

date -s '15:48:00 2017-12-16'

hwclock --set --date '15:48:00 2017-12-16'

hwclock --hctosys 

clock -w 

 

重启vagrant:

vagrant reload

 

3.3、linux基础工具

yum install -y net-tools lrzsz 

 

3.4、安全加强

yum install -y glibc glibc-common glibc-devel glibc-headers nscd \

bind-libs bind-libs-lite bind-license bind-utils \

gnutls tomcat-servlet-3.0-api wget \

kernel kernel-devel kernel-headers kernel-tools kernel-tools-libs python-perf \

python-perf \

libnl3 libnl3-cli NetworkManager NetworkManager-glib NetworkManager-tui \

libxml2 libxml2-python \

vim-common vim-enhanced vim-filesystem vim-minimal \

libtiff \

openssh openssh-clients openssh-server openssl-devel openssl-libs openssl-perl openssl-static \

libgcrypt libgcrypt-devel \

sqlite \

cups-filters cups-filters-libs \

ntp ntpdate \

libuser \

sssd-client \

subversion subversion-libs \

ModemManager-glib \

libpng \

openssl openssl-libs \

poppler poppler-utils \

abrt abrt-addon-ccpp abrt-addon-kerneloops abrt-addon-pstoreoops abrt-addon-python abrt-addon-vmcore abrt-addon-xorg abrt-cli abrt-console-notification abrt-libs abrt-python abrt-tui \

libreport libreport-cli libreport-filesystem libreport-plugin-mailx libreport-plugin-rhtsupport libreport-plugin-ureport libreport-python libreport-rhel libreport-web \

chrony \

openldap \

expat \

libXfont \

curl libcurl \

openssl098e \

nss nss-sysinit nss-tools nss-util \

git perl-Git \

pcre pcre-devel \

libxml2 libxml2-devel libxml2-python

 

rm -f /etc/cron.deny 

rm -f /etc/at.deny 

touch /etc/cron.allow 

touch /etc/at.allow 

chmod 0600 /etc/cron.allow 

chmod 0600 /etc/at.allow

 

 

 

4、安装docker

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum install -y docker-ce-17.09.1.ce

systemctl start docker

systemctl enable docker

 

4.1、使用阿里云加速Docker

首先注册一个阿里云的帐号

进入:https://cr.console.aliyun.com/#/accelerator

根据提示,创建:/etc/docker/daemon.json

sudo systemctl daemon-reload

sudo systemctl restart docker

 

 

5、安装mysql

 

5.1、创建docker image

cd /docker/mysql/cuzn-mysql

./build.sh

 

5.1、安装主库

cd /docker/mysql

./run_master.sh 

注:123456是数据库root密码

 

5.2、安装从库

cd /docker/mysql

./run_slave.sh 3322

 

5.3重新弄mysql 从库

1.docker ps 找到从库的名称 mysql-slave-3322 

2.docker stop  mysql-slave-3322

3.docker rm  mysql-slave-3322

4.cd /data1/mysql

5.rm -rf rm -rf mysql-slave-3322/

6.cd /docker/mysql

7../run_slave.sh 3322

 

6、安装redis

 

6.1、安装缓存用的redis

cd /docker/redis/cuzn-redis

./build.sh

 

6.1.1、安装主库

cd /docker/redis/redis-cache-master-6480

./run.sh

 

6.1.2、安装从库

cd /docker/redis/cuzn-redis

./build.sh

cd /docker/redis/redis-slave

./run.sh redis-cache-master-6480 6481

 

6.2、安装永欠存储用的redis

 

6.2.1、安装主库

cd /docker/redis/redis-permanent-master-6490

./run.sh

 

6.2.2、安装从库

cd /docker/redis/redis-slave

./run.sh redis-permanent-master-6490 6491

 

6.3、管理工具:RedisDesktopManager

 

6.3.1、windows: 

https://redisdesktop.com/download

 

6.3.2、mac:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null

brew cask install rdm

 

 

 

7、安装git

yum -y install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel

yum -y install git

 

7.1、设置简写

git config --system alias.st status

git config --system alias.ci "commit -m"

git config --system alias.co checkout

git config --system alias.br  branch

git config --system alias.mg  "merge --no-ff"

 

7.2、设置用户

 

git config --global user.name "你的姓名"

git config --global user.email "你的@邮箱.com"

 

7.3、设置 ssh key

cd 

rm -fr .ssh

ssh-keygen -t rsa -C "你的@邮箱.com"

一路回车

cat /root/.ssh/id_rsa.pub

复制内容备用

 

7.4、注册gitlab,并设置 ssh key

http://127.0.0.1:10011/

用“你的@邮箱.com”注册后进入:

http://127.0.0.1:10011/profile/keys

设置 ssh key,把8.3生成的id_rsa.pub内容填入

 

7.5、git工具:sourcetree,小乌龟(tortoisegit)

 

8、安装php和nginx

 

8.1、创建linux基础docker image

cd /docker/centos-systemd

./build.sh

 

8.2、创建php-nginx的docker image

cd /docker/php-nginx

./build.sh

 

8.3、创建数据

 

8.3.1、把nginx配置文件放到 D:/cuzn/data/etc 下

 

8.3.2 拉取网站数据

cd /data/www/

git clone ssh://git@127.0.0.1:12122/cuzn/cuzn.git

cd cuzn

git checkout develop

git pull develop

 

8.3.3 创建配置文件

cd conf

ln -s debug local

 

8.3.4 创建cache目录

cd ..

mkdir cache

chmod 777 cache

 

8.4、启动php-nginx

cd /docker/php-nginx

./run dev

 

 

 

9、设置host

如果是非线上环境,要设置host

 

9.1、下载host切换软件:switch host

 

9.2、查看服务器环境ip

ifconfig

 

9.3、设置host并切换到指定环境

 

 

 

9、安装supervisord

mkdir -p /data/etc/supervisord

mkdir -p /data2/logs/supervisord

chmod -R 777 /data2/logs/supervisord

yum install -y iproute python-setuptools hostname inotify-tools yum-utils which jq

yum clean all

rm -rf /var/cache/yum

easy_install supervisor

echo_supervisord_conf > /etc/supervisord.conf

sed -i "s|logfile=\/tmp\/supervisord\.log|logfile=\/data2\/logs\/supervisord\/supervisord\.log|g" /etc/supervisord.conf

sed -i "s|;\[include\]|\[include\]|g" /etc/supervisord.conf

sed -i "s|;files = relative\/directory\/\*\.ini|files = \/data\/etc\/supervisord\/\*\.ini|g" /etc/supervisord.conf

 

(cat <<EOF

[Unit]

Description=Supervisor daemon

 

[Service]

Type=forking

ExecStart=/usr/bin/supervisord

ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown

ExecReload=/usr/bin/supervisorctl $OPTIONS reload

KillMode=process

Restart=on-failure

RestartSec=42s

 

[Install]

WantedBy=multi-user.target

EOF

) >/usr/lib/systemd/system/supervisord.service

 

systemctl enable supervisord.service

systemctl start supervisord.service

 

 

 

 

 

 

 

 

 

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权