docker容器里面各测试环境部署部署脚本(nginx,php,redis,mysql,nodejs)

释放双眼,带上耳机,听听看~!

    公司用到的语言,当然还是php为主,不过后台现在都用到nodejs和golang,所以nodesjs和golang都要安装,发觉使用docker还是很好的,只要把环境部署好了,然后打构建成镜像,下次直接就可以生成环境了,不用重新部署。以下为相关服务的部署脚本:

nginx:

###上传并解压安装文件:
tar zxvf nginx-1.8.0.tar.gz

 

###进到安装目录:
cd nginx-1.8.0

 

###编译参数安装:

./configure –user=nginx –group=nginx –prefix=/app/nginx1.8.0 –with-http_stub_status_module –with-http_ssl_module 
make
make install

 

###建立软连接:
ln -s /app/nginx1.8.0/ /app/nginx
ll /app/nginx

 

###检查语法并启动:
/app/nginx/sbin/nginx -t #检查语法
/app/nginx/sbin/nginx

mysql:

###安装依赖包####
yum -y install wget gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake bison bison-devel ncurses-devel perl

###新建用户组###
groupadd mysql
useradd mysql -g mysql

###上传并解压安装包###

cd /home/hejp/tools
tar -zxv -f mysql-5.6.17.tar.gz
cd mysql-5.6.17


 

###cmake编译参数安装###
cmake \
-DCMAKE_INSTALL_PREFIX=/app/mysql-5.6.17 \
-DMYSQL_UNIX_ADDR=/app/mysql-5.6.17/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/app/mysql-5.6.17/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306

make && make install

# 复制配置文件
cp /app/mysql/support-files/my-default.cnf /etc/my.cnf

#添加系统变量
echo 'export PATH=/app/mysql/bin:$PATH' >>/etc/profile
echo "export PATH" >> /etc/profile
source /etc/profile
echo $PATH

# 进入安装路径并授权mysql用户:
cd /app/mysql
mkdir -p /app/mysql/data
chown -R mysql.mysql /app/mysql/

##调整/tmp授权,否则初始化会错误:
chmod -R 1777 /tmp 

# 执行初始化:
cd /app/mysql/scripts/
./mysql_install_db –basedir=/app/mysql/ –datadir=/app/mysql/data/ –user=mysql

 

# 把服务启动脚本添加到/etc/init.d目录下:
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

# 启动MySQL服务,设置密码,设置开机启动。

/etc/init.d/mysqld start
netstat -lntup|grep mysql
/app/mysql/bin/mysqladmin -u root password 'qyd123' 
chkconfig mysqld on
echo "ok!"

php:

###上传并解压安装包:

cd /home/hejp/tools/
tar zxvf php-7.0.4.tar.gz

 

###进到目录并安装依赖包:
cd php-7.0.4
yum install libxslt* -y

 

###然后编译参数安装:
./configure \
–prefix=/app/php7.0.4 \
–with-config-file-path=/app/php7.0.4/etc \
–with-config-file-scan-dir=/app/php7.0.4/etc/php.d \
–with-mysql-sock=/app/mysql-5.6.17/tmp/mysql.sock \
–with-mcrypt=/usr/local \
–enable-mysqlnd \
–with-mysqli=mysqlnd \
–with-pdo-mysql=/app/mysql-5.6.17 \
–enable-fpm \
–with-fpm-user=nginx \
–with-fpm-group=nginx \
–with-gd \
–with-iconv \
–with-zlib \
–enable-xml \
–enable-shmop \
–enable-sysvsem \
–enable-inline-optimization \
–enable-mbregex \
–enable-mbstring \
–enable-ftp \
–enable-gd-native-ttf \
–with-openssl \
–enable-pcntl \
–enable-sockets \
–with-xmlrpc \
–enable-zip \
–enable-soap \
–without-pear \
–with-gettext \
–enable-session \
–with-curl \
–with-jpeg-dir \
–with-freetype-dir \
–enable-opcache

make
make install

ln -s /app/php7.0.5/ /app/php

 

###从安装目录拷贝配置文件:
cp php.ini-production /app/php/etc/php.ini

 

###进到目录修改配置文件参数:
cd /app/php/etc/
cp php-fpm.conf.default php-fpm.conf

[ -f php-fpm.conf ] &&\
sed -i "s%;pid = run/php-fpm.pid%pid = /app/logs/php-fpm.pid%g" php-fpm.conf
sed -i "s%;error_log = log/php-fpm.log%error_log = /app/logs/php-fpm.log%g" php-fpm.conf
sed -i "s%;log_level = notice%log_level = error%g" php-fpm.conf
sed -i "s%;rlimit_files = 1024%rlimit_files = 32768%g" php-fpm.conf
sed -i "s%; events.mechanism = epoll%events.mechanism = epoll%g" php-fpm.conf
sed -i "s%;rlimit_files = 1024%rlimit_files = 32768%g" php-fpm.conf

cd /app/php/etc/php-fpm.d/
cp www.conf.default www.conf

[ -f www.conf ] &&\ sed -i "s/;listen.owner = nginx/listen.owner = nginx/g" www.confsed -i "s/;listen.group = nginx/listen.group = nginx/g" www.confsed -i "s/;listen.mode = 0660/listen.mode = 0660/g" www.confsed -i "s/pm.max_children = 5/pm.max_children = 1024/g" www.confsed -i "s/pm.start_servers = 2/pm.start_servers = 16/g" www.confsed -i "s/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g" www.confsed -i "s/pm.max_spare_servers = 3/pm.max_spare_servers = 20/g" www.confsed -i "s/;pm.process_idle_timeout = 10s;/pm.process_idle_timeout = 15s;/g" www.confsed -i "s/;pm.max_requests = 500/pm.max_requests = 2048/g" www.conf

 

#创建php的error_log和pid文件路径:
mkdir /app/logs -p

 

#检查语法并启动
/app/php/sbin/php-fpm -t
/app/php/sbin/php-fpm 
netstat -lntup|grep php-fpm
ps -ef|grep php-fpm

echo "ok!"


redis:

###解压源码包:

tar -zxvf redis-3.0.6.tar.gz

 

###进入目录编译安装:
cd redis-3.0.6 
make
make PREFIX=/app/redis-3.0.6 install

ln -s /app/redis-3.0.6 /app/redis

 

###创建配置文件redis.conf:
mkdir /app/redis/etc/
cp redis.conf /app/redis/etc/

 

###把命令拷贝到 /usr/bin/:
cd /app/redis/bin/
cp redis-benchmark redis-cli redis-server /usr/bin/

#调整内存参数
#1表示内核允许超量使用内存直到内存用完为止:
echo  "vm.overcommit_memory=1">>/etc/sysctl.conf
sysctl -p

 

###修改一下配置文件redis.conf

vim /app/redis/etc/redis.conf

 

# redis以守护进程的方式运行
daemonize yes

 

# 客户端闲置多长时间后断开连接,默认为0关闭此功能 
timeout 300

 

# 设置redis日志级别,默认级别:notice 
loglevel verbose

# 并且日志输出设置为stdout,那么日志信息就输出到/dev/null里面去了 
logfile stdout

 

###redis环境变量配置:

vim /etc/profile
export PATH="$PATH:/app/php/bin:/app/mysql/bin:/app/redis/redis/bin"

source /etc/profile

 

####启动服务:

/app/redis/bin/redis-server /app/redis/etc/redis.conf

ps -ef|grep redis

lsof -i:6379

echo "ok"


nodesjs:

centos7下编译安装nodejs:

tar xvf node-v4.4.3.tar.gz

cd node-v4.4.3
./configure 
make 
make install

 

编译完后配置环境:

cp /usr/local/bin/node /usr/sbin/

 

检查命令:

 whereis node

出现这个:node: /usr/local/bin/node  表示node安装完成。

 

再安装以下模块,命令为:

 node还要安装以下模块  
npm install -g ejs
npm install -g jade
npm install -g express
npm install -g forever 

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

**   以上为相关的服务安装脚本,当然安装完服务后还需要相关的交互测试,以保证服务安装成功,例如redis和php的交互还需要安装phpredis,php与mysql的交互需要用到pdo来插入数据进行测试。**

给TA打赏
共{{data.count}}人
人已打赏
安全运维

MySQL和MongoDB数据相互迁移

2021-12-11 11:36:11

安全运维

Ubuntu上NFS的安装配置

2021-12-19 17:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索