Ansible + shell 实现部署fastdfs+nginx 实现图片服务器并提供动态缩放功能;
#!/usr/bin/env bashset -x
set -e
IFS=$'\n'
dest=/usr/local/
fastdfsgz="V5.05.tar.gz"
fastdfsmod="fastdfs-nginx-module_v1.16.tar.gz"
nginxgz="nginx-1.12.0.tar.gz"
IP=$(ip a s eth0 | grep"inet " | awk '{print $2}' | sed -r "s/\/24//g")
for gz in ${dest}${fastdfsgz} ${dest}${fastdfsmod} ${dest}${nginxgz}
do
tar xf $gz -C ${dest}
done
########安装libfast
cd ${dest}
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon
./make.sh && ./make.sh install
############更改fastdfs-nginx-module/src/config
sed -ri "4s/local\///g" ${dest}fastdfs-nginx-module/src/config
##################安装fastdfs
cd ${dest}fastdfs-5.05/
./make.sh && ./make.sh install &
wait
cp conf/http.conf /etc/fdfs/
cp conf/mime.types /etc/fdfs/
cd /etc/fdfs/
for filename in client.conf.sample storage.conf.sample tracker.conf.sample
do
cp ${filename} ${filename/.sample/}
sed -ri "s/base_path=/#base_path=/g" ${filename/.sample}
done
mkdir -p /home/fast/client /home/fast/tracker /home/fast/storage/data
cp ${dest}fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
sed -ri "/^connect_timeout/cconnect_timeout = 10" /etc/fdfs/mod_fastdfs.conf
sed -ri "/^tracker_server/ctracker_server=${IP}:22122" /etc/fdfs/mod_fastdfs.conf
sed -ri "/^url_have_group_name/curl_have_group_name=true" /etc/fdfs/mod_fastdfs.conf
sed -ri "/^store_path0=/cstore_path0=\/home\/fast\/storage\/data" /etc/fdfs/mod_fastdfs.conf
###tracker.conf
sed -ri "/#base_path=/abase_path=\/home\/fast\/tracker" tracker.conf
####client.conf
sed -ri "/#base_path=/abase_path=\/home\/fast\/client" client.conf
sed -ri "s/tracker_server=/#tracker_server=/g" client.conf
sed -ri "/#tracker_server=/atracker_server=${IP}:22122" client.conf
####storage.conf
sed -ri "/#base_path=/abase_path=\/home\/fast\/storage" storage.conf
sed -ri "s/tracker_server=/#tracker_server=/g" storage.conf
sed -ri "/#tracker_server=/atracker_server=${IP}:22122" storage.conf
sed -ri "/store_path0=/cstore_path0=\/home\/fast\/storage\/data" storage.conf
############编译nginx
cd ${dest}nginx-1.12.0
./configure \
--user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_sub_module --with-http_ssl_module \
--with-pcre --add-module=/usr/local/fastdfs-nginx-module/src/ \
--with-http_image_filter_module&
#--add-module=/usr/local/nginx-rtmp-module &
wait
make && make install &
wait
if [ -d ${dest}/nginx/conf.d ];then
mv ${dest}fastdfs_nginx.conf ${dest}/nginx/conf.d/
else
mkdir ${dest}/nginx/conf.d
mv ${dest}fastdfs_nginx.conf ${dest}/nginx/conf.d/
fi
cd /usr/local/nginx/conf.d/
for rows in $(tac ./fastdfs_nginx.conf)
do
sed -ri "40a$rows" /usr/local/nginx/conf/nginx.conf
done
############
/usr/local/nginx/sbin/nginx-t
页:
[1]