假如我们会去部署一个又一个的软件,如何是好呢,里面有wget,有rsync,有yum安装,有账号修改。我们可以采用jenkins里面绑定了agent了之后进行部署,怎么装都好,但是这样我们需要安装jenkins,需要部署java,还需要做各种配置。还有一个方案是fab。
cd /usr/local/src/
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
tar xzvf Python-2.7.12.tgz
cd Python-2.7.12
./configure —prefix=/usr/local/python-2.7.12
make -j 4
make install
virtualenv -p /usr/local/python-2.7.12/bin/python2.7 /usr/local/fabenv
source /usr/local/fabenv/bin/activate
pip install Fabric
(fabenv) [root@ss b-localhost]# ls
deploy.sh fabfile.py fabfile.pyc README src
(fabenv) [root@ss b-localhost]# cat fabfile.py
#!/usr/bin/env python
#coding=utf-8
def hello(name="Hello"):
print("Hello %s!"%name)
from fabric.api import *
#env.hosts=['[email protected]:22']
#env.password='123123'
env.hosts=['[email protected]:22']
env.password='123123'
def test():
run('ifconfig')
def basic():
put('./src/basic.sh','/tmp/basic.sh')
run('ls -l /tmp')
run('/bin/bash /tmp/basic.sh')
def i_haproxy():
put('./src/haproxy.sh','/tmp/haproxy.sh')
run('/bin/bash /tmp/haproxy.sh')
def i_nginx():
put('./src/nginx.sh','/tmp/nginx.sh')
run('/bin/bash /tmp/nginx.sh')
def i_fastdfs():
put('./src/fastdfs.sh','/tmp/fastdfs.sh')
run('/bin/bash /tmp/fastdfs.sh')
def i_nginx_fastdfs():
put('./src/nginx_fastdfs.sh','/tmp/nginx_fastdfs.sh')
run('/bin/bash /tmp/nginx_fastdfs.sh')
def i_mariadb():
put('./src/mariadb.sh','/tmp/mariadb.sh')
run('/bin/bash /tmp/mariadb.sh')
def i_zookeeper():
put('./src/zookeeper.sh','/tmp/zookeeper.sh')
run('/bin/bash /tmp/zookeeper.sh')
# 新建账户
id guoyingjiang || useradd -m guoyingjiang
# 部署目录和权限
[ -d "/home/guoyingjiang/opt" ] && echo "/home/guoyingjiang/opt目录已经存在" || mkdir -p /home/guoyingjiang/opt
[ -d "/home/guoyingjiang/logs" ] && echo "/home/guoyingjiang/logs目录已经存在" || mkdir -p /home/guoyingjiang/logs
chown guoyingjiang:guoyingjiang /home/guoyingjiang/opt
chown guoyingjiang:guoyingjiang /home/guoyingjiang/logs
# sudoer权限
sed -i '/guoyingjiang.*/d' /etc/sudoers
echo 'guoyingjiang ALL=(ALL) NOPASS: ALL' >> /etc/sudoers
sed -i 's/guoyingjiang.*/guoyingjiang ALL=(ALL) NOPASSWD: ALL/' /etc/sudoers
sed -i 's:^Defaults requiretty:#Defaults requiretty:g' /etc/sudoers
# SSH服务优化设置
sed -i 's:^GSSAPIAuthentication.*:GSSAPIAuthentication no:g' /etc/ssh/sshd_config
sed -i 's:^GSSAPICleanupCredentials.*:GSSAPICleanupCredentials no:g' /etc/ssh/sshd_config
sed -i 's:^UseDNS.*:UseDNS no:g' /etc/ssh/sshd_config
service sshd reload
# 部署公钥到目标主机
[ -d "/home/guoyingjiang/.ssh/" ] || mkdir -p /home/guoyingjiang/.ssh
[ -e "/home/guoyingjiang/.ssh/authorized_keys" ] && (echo "authorized_keys文件存在") || (echo "authorized_keys文件不存在";touch /home/guoyingjiang/.ssh/authorized_keys;)
sed -i '/jacky@jacky-HP-ProBook-430-G2/d' /home/guoyingjiang/.ssh/authorized_kyes || echo "authorized_keys里面没有我们的公钥"
#echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1SfbvDyqegzKuwLkt6lQHV/dYGnVPZFnW36jl2PBGNYbnpxY5jqqnBfYEbnrY9/3QIBLeqGjnNnPilhFtGtJzN7PxFDe6jhtTlb0N9dmkiVrOBG2N+tExCxVG4KNBQZ0bBJPxgCss2+3Q8SZX0n5Ifx8NjnWM13B/MA01Uet99PZ7qIXFsu48BRpudmj9Zq9qcSXBHHESQRKa2JiXSpd3dcmFH8kCwUXTO/LJFSfPvI4YQpj+3XVA4A+t7N2yZ2819MNmgkcYG5Bvo4xRtv12JyWUo/UU/pU6br0EwCS2FQu+qXOhyp2/ApC/LQwVbd5OvHNNO0KWVkhSmpunxygF jacky@jacky-HP-ProBook-430-G2' >> /home/guoyingjiang/.ssh/authorized_keys
# 设置Jenkins退出后,后台进程继续运行
#sed -i '/BUILD_ID/d' /home/guoyingjiang/.bashrc
#echo 'export BUILD_ID=dontKillMe' >> /home/guoyingjiang/.bashrc
#部署JAVA
#cd /home/guoyingjiang/opt/
#wget http://soft.ops.ac.cn/java/jdk-7u79-linux-x64.tar.gz -O jdk-7u79-linux-x64.tar.gz
#tar xzvf jdk-7u79-linux-x64.tar.gz
#[ -L "java" ] && rm -f java || echo "软连接不存在"
#ln -s jdk1.7.0_79 java
#cd /home/guoyingjiang/
#rsync -avzP .bashrc .bashrc.bak.`date +%y%d%h%m`
#sed -i '/JAVA/d' .bashrc
#echo '
#export JAVA_HOME=/home/guoyingjiang/opt/java
#export PATH=$JAVA_HOME/bin:$PATH
#' >> /home/guoyingjiang/.bashrc
#source /home/guoyingjiang/.bashrc
#java -version
# Ulimit 设置
sudo echo '
* soft nofile 1048576
* soft nproc 1048576
* hard nofile 1048576
* hard nproc 1048576
* hard memlock unlimited
' > /etc/security/limits.d/90-nproc.conf
sudo ulimit -a
# close SELinux
sudo setenforce 0
sudo sed -i 's:SELINUX=.*:SELINUX=disabled:g' /etc/selinux/config
# TCP 优化
sudo echo '
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_conntrack_max = 10240
net.ipv4.nf_conntrack_max = 10240
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
' > /etc/sysctl.conf
sudo sysctl -p
# 改变用户和组
cd /home/guoyingjiang && chown -R guoyingjiang:guoyingjiang .
(fabenv) [root@ss src]# cat haproxy.sh
# 下载并解压
cd /home/guoyingjiang/opt
rm -rf haproxy*
wget -O haproxy-1.6.3.tar.gz http://soft.ops.ac.cn/haproxy/haproxy-1.6.3.tar.gz
tar xzvf haproxy-1.6.3.tar.gz
[ -L "haproxy" ] && rm -f haproxy || echo "软连接不存在"
# 编译
cd /home/guoyingjiang/opt/haproxy-1.6.3
make TARGET=linux26 -j 4
# 将上面编译生成的haproxy拷贝到 /home/guoyingjiang/opt/haproxy/下面
[ -d "/home/guoyingjiang/opt/haproxy" ] || mkdir -p /home/guoyingjiang/opt/haproxy/
cp /home/guoyingjiang/opt/haproxy-1.6.3/haproxy /home/guoyingjiang/opt/haproxy/
# 下载配置文件
cd /home/guoyingjiang/opt/haproxy
wget -O haproxy.conf http://soft.ops.ac.cn/haproxy/haproxy.conf
# 下载启动文件
cd /home/guoyingjiang/opt/haproxy/
wget -O haproxy.init http://soft.ops.ac.cn/haproxy/haproxy.init.txt && chmod a+x haproxy.init
sed -i 's:/home/guoyingjiang/opt:/home/guoyingjiang/opt:g' haproxy.init
# 改变用户和组
cd /home/guoyingjiang/haproxy
chown -R guoyingjiang:guoyingjiang .
# 压缩上传
#cd /home/guoyingjiang/opt && tar czvf haproxy.tar.gz haproxy
#cd /home/guoyingjiang/opt && rsync -avzP haproxy.tar.gz rsync.ops.ac.cn::ops1970/deploy/tars/
# 启动
# /home/guoyingjiang/opt/haproxy/haproxy.init restart
# cd /home/guoyingjiang/opt/haproxy && ./haproxy -f haproxy.conf -d
(fabenv) [root@ss src]# cat fastdfs.sh
# 多打几个路径,下面用得到
export PATH=/sbin:/usr/sbin:$PATH
# 下载必要的文件
cd /home/guoyingjiang/opt
wget http://soft.ops.ac.cn/fastdfs/libfastcommon-master.zip -O libfastcommon-master.zip
wget http://soft.ops.ac.cn/fastdfs/fastdfs-nginx-module_v1.16.tar.gz -O fastdfs-nginx-module_v1.16.tar.gz
wget http://soft.ops.ac.cn/fastdfs/FastDFS_v5.05.tar.gz -O FastDFS_v5.05.tar.gz
wget http://soft.ops.ac.cn/fastdfs/nginx-1.8.0.tar.gz -O nginx-1.8.0.tar.gz
# 创建必要的目录,稍后FastDFS会用的到,而且在好几个配置文件中会提到
mkdir -p /home/guoyingjiang/opt/data/fastdfs_tracker
mkdir -p /home/guoyingjiang/opt/data/fastdfs_storage
mkdir -p /home/guoyingjiang/opt/data/fastdfs
# 部署libfastcommon
cd /home/guoyingjiang/opt
[ -d "libfastcommon-master" ] && rm -rf libfastcommon-master
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
mkdir -p /home/guoyingjiang/opt/addons/libfastcommon/include/
mkdir -p /home/guoyingjiang/opt/addons/libfastcommon/lib/
rsync -avzP src/* /home/guoyingjiang/opt/addons/libfastcommon/include/
rsync -avzP src/* /home/guoyingjiang/opt/addons/libfastcommon/lib/
# fastDFS 部署
cd /home/guoyingjiang/opt/
tar -xf FastDFS_v5.05.tar.gz
cd /home/guoyingjiang/opt/FastDFS
source ~/.bashrc
export DESTDIR=/home/guoyingjiang/opt/fastdfs/
# 编译变量
export C_INCLUDE_PATH=/home/guoyingjiang/opt/addons/libfastcommon/include
export LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib
./make.sh
./make.sh install
# 将环境变量放到.bashrc
sed -i ':LD_LIBRARY_PATH=/opt/guoyingjiang/addons/libfastcommon/lib:d' ~/.bashrc
sed -i '/^$/d' ~/.bashrc
echo '
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib:$LD_LIBRARY_PATH
' >> ~/.bashrc
. ~/.bashrc
# 将环境变量放到.bashrc
sed -i ':/LD_LIBRARY_PATH=/opt/guoyingjiang/fastdfs/usr/lib64/:d' ~/.bashrc
sed -i '/^$/d' ~/.bashrc
echo '
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/fastdfs/usr/lib64/:$LD_LIBRARY_PATH
' >> ~/.bashrc
. ~/.bashrc
# 上面设置完成后,把环境变量放到bashrc里面去
sed -i ':/opt/guoyingjiang/fastdfs/usr/bin:d' ~/.bashrc
echo '
export PATH=/home/guoyingjiang/opt/fastdfs/usr/bin:$PATH
' >> ~/.bashrc
. ~/.bashrc
# fastDFS 配置
cd /home/guoyingjiang/opt/fastdfs/etc/fdfs/
# 配置 For Client
cp client.conf.sample client.conf
sed -i 's:base_path=.*:base_path=/home/guoyingjiang/opt/fastdfs/:' client.conf
sed -i 's/tracker_server=.*/tracker_server=10.0.1.103:22122/' client.conf
# 配置 For Storage
cp -f storage.conf.sample storage.conf
sed -i 's:base_path=.*:base_path=/home/guoyingjiang/opt/data/fastdfs_storage:' storage.conf
sed -i 's:store_path0=.*:base_path=/home/guoyingjiang/opt/data/fastdfs_storage:' storage.conf
sed -i 's:max_connections=.*:max_connections=100000:' storage.conf
sed -i '/tracker_server=/d' storage.conf
sed -i 's:/usr/local/:/home/guoyingjiang/opt/fastdfs/usr/:g' /home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_storaged
sed -i 's:/etc/fdfs/:/home/guoyingjiang/opt/fastdfs/etc/fdfs/:g' /home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_storaged
IP=`/sbin/ifconfig | grep '10\.\|192\.168\.' | head -n 1 | awk -F\: '{print $2}' | awk '{print $1}'`
echo "
tracker_server=$IP:22122
" >> storage.conf
# 配置 For Tracker
cd /home/guoyingjiang/opt/fastdfs/etc/fdfs/
cp -f tracker.conf.sample tracker.conf
sed -i 's:base_path=.*:base_path=/home/guoyingjiang/opt/data/fastdfs_tracker/:' tracker.conf
sed -i 's:max_connections=.*:max_connections=100000:' tracker.conf
sed -i 's:log_level=.*:log_level=debug:g' tracker.conf
sed -i 's:run_by_user=.*:run_by_user=guoyingjiang:g' tracker.conf
sed -i 's:run_by_group=.*:run_by_group=guoyingjiang:g' tracker.conf
# 启动脚本修改
#PRG=/usr/local/bin/fdfs_trackerd
#CONF=/etc/fdfs/tracker.conf
sed -i 's:/usr/local/:/home/guoyingjiang/opt/fastdfs/usr/:g' /home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_trackerd
sed -i 's:/etc/fdfs/:/home/guoyingjiang/opt/fastdfs/etc/fdfs/:g' /home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_trackerd
# tracker 重启
/home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_trackerd restart
# storage 重启
/home/guoyingjiang/opt/fastdfs/etc/init.d/fdfs_storaged restart
# 下载文件
cd /home/guoyingjiang/opt
wget http://soft.ops.ac.cn/fastdfs/nginx-1.8.0.tar.gz -O nginx-1.8.0.tar.gz
wget http://soft.ops.ac.cn/fastdfs/fastdfs-nginx-module_v1.16.tar.gz -O fastdfs-nginx-module_v1.16.tar.gz
tar xzvf nginx-1.8.0.tar.gz
tar xzvf fastdfs-nginx-module_v1.16.tar.gz
# 修改fastdfs-nginx-module的配置文件地址
sed -i 's:/etc/fdfs/mod_fastdfs.conf:/home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf:g' /home/guoyingjiang/opt/fastdfs-nginx-module/src/config
# 编译 pcre
cd /home/guoyingjiang/opt
wget -O pcre-7.8.tar.gz http://soft.ops.ac.cn/pcre/pcre-7.8.tar.gz
tar xzvf pcre-7.8.tar.gz
cd /home/guoyingjiang/opt/pcre-7.8 && ./configure --prefix=/home/guoyingjiang/opt/addons/pcre && make -j 4 && make install
# 编译 zlib
cd /home/guoyingjiang/opt
wget -O zlib-1.2.3.tar.gz http://soft.ops.ac.cn/zlib/zlib-1.2.3.tar.gz
tar xzvf zlib-1.2.3.tar.gz
cd /home/guoyingjiang/opt/zlib-1.2.3 && ./configure --prefix=/home/guoyingjiang/opt/addons/zlib && make -j 4 && make install
# 编译使用 - zlib
export C_INCLUDE_PATH=/home/guoyingjiang/opt/addons/zlib/include:$C_INCLUDE_PATH
export LIBRARY_PATH=/home/guoyingjiang/opt/addons/zlib/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib:$LD_LIBRARY_PATH
# 编译使用 - pcre
export C_INCLUDE_PATH=/home/guoyingjiang/opt/addons/pcre/include:$C_INCLUDE_PATH
export LIBRARY_PATH=/home/guoyingjiang/opt/addons/pcre/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib:$LD_LIBRARY_PATH
# 编译使用 - fdfs-client
export LIBRARY_PATH=/home/guoyingjiang/opt/FastDFS/client/:$LIBRARY_PATH
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/FastDFS/client/:$LD_LIBRARY_PATH
# 编译使用 - fastdfs trunk_shared.h
export C_INCLUDE_PATH=/home/guoyingjiang/opt/fastdfs/usr/include/fastdfs/:$C_INCLUDE_PATH
# 编译使用 - libfastcommon
export C_INCLUDE_PATH=/home/guoyingjiang/opt/addons/libfastcommon/include/:$C_INCLUDE_PATH
export LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib/:$LIBRARY_PATH
export LD_LIBRARY_PATH=/home/guoyingjiang/opt/addons/libfastcommon/lib/:$LD_LIBRARY_PATH
# 调整编译内容
# /home/guoyingjiang/opt/fastdfs-nginx-module/src/config
cd /home/guoyingjiang/opt/nginx-1.8.0
./configure --prefix=/home/guoyingjiang/opt/nginx --add-module=/home/guoyingjiang/opt/fastdfs-nginx-module/src/
make -j 4
make install
# 最后将环境变量放到 ~/.bashrc里面
sed -i ':/opt/guoyinjgiang/nginx/sbin:d' ~/.bashrc
echo '
export PATH=/home/guoyingjiang/opt/nginx/sbin:$PATH
' >> ~/.bashrc
source ~/.bashrc 1>/dev/null 2>&1
# Nginx调整配置 - 将默认的80端口改掉
cd /home/guoyingjiang/opt/nginx/conf
sed -i 's:listen.*80;:listen 8089;:g' nginx.conf
# Nginx 调整运行账户
## xxianqudi奥下面
# sed -i 's:#user nobody;:user guoyingjiang;:g' /home/guoyingjiang/opt/nginx/conf/nginx.conf
# 下载并编辑nginx启动文件
cd /home/guoyingjiang/opt/nginx/
[ -d "bin" ] || mkdir bin
cd bin
wget -O nginx http://soft.ops.ac.cn/nginx/nginx.init.txt
chmod a+x nginx
sed -i 's:nginx="/usr/local/nginx/sbin/nginx":nginx="/home/guoyingjiang/opt/nginx/sbin/nginx":g' nginx
sed -i 's:NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf":NGINX_CONF_FILE="/home/guoyingjiang/opt/nginx/conf/nginx.conf":g' nginx
sed -i 's:lockfile=/home/guoyingjiang/opt/var/lock/subsys/nginx'
sed -i 's:^lockfile=.*:./nginx.lock'
mkdir -p /home/guoyingjiang/opt/var/lock/subsys
sed -i 's:lockfile=/var/lock/subsys/nginx:lockfile=/home/guoyingjiang/opt/var/lock/subsys/nginx:g' nginx
# 测试启动
nginx -t
/home/guoyingjiang/opt/nginx/bin/nginx restart
(fabenv) [root@ss src]# cat nginx_fastdfs.sh
# 基础变量获得
source ~/.bashrc 1>/dev/null 2>&1
IP=`/sbin/ifconfig | grep '10\.\|192\.168\.' | head -n 1 | awk -F\: '{print $2}' | awk '{print $1}'`
# -----------------------------------------FAST DFS
# fastdfs 配置, mime.types 和 http.conf
cp -f /home/guoyingjiang/opt/FastDFS/conf/mime.types /home/guoyingjiang/opt/fastdfs/etc/fdfs/
cp -f /home/guoyingjiang/opt/FastDFS/conf/http.conf /home/guoyingjiang/opt/fastdfs/etc/fdfs/
# fastdfs配置 , mod_fastdfs.conf
cp -f /home/guoyingjiang/opt/fastdfs-nginx-module/src/mod_fastdfs.conf /home/guoyingjiang/opt/fastdfs/etc/fdfs/
sed -i 's:base_path=.*:base_path=/home/guoyingjiang/opt/data/fastdfs_storage:g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i 's:url_have_group_name =.*:url_have_group_name = true:g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i '/tracker_server=.*/d' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
echo "tracker_server=$IP:22122" >> /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i 's/storage_server_port=.*/storage_server_port=$IP:23000/g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i 's:group_name=.*:group_name=group1:g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i 's:storage_path_count=.*:store_path_count=1:g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
sed -i 's:store_path0=.*:store_path0=/home/guoyingjiang/opt/data/fastdfs_storage:g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf
log_filename=/home/ops/fastdfs/logs/mod_fastdfs.log
cat /home/guoyingjiang/opt/fastdfs/etc/fdfs/mod_fastdfs.conf | grep -v "^#" | grep -v "^$"
# DFS创建软链
[ -L /home/guoyingjiang/opt/data/fastdfs_storage/data/M00 ]
[ $? -eq 0 ] || ln -s /home/guoyingjiang/opt/data/fastdfs_storage/data /home/guoyingjiang/opt/data/fastdfs_storage/data/M00
# DFS创建日志路径
mkdir -p /home/guoyingjiang/opt/fastdfs/logs/
# -----------------------------------------NGInx
# Nginx调整配置 - nginx.conf
cd /home/guoyingjiang/opt/nginx/conf
sed -i '/include servers/d' nginx.conf
sed -i '$ d' nginx.conf
echo ' include servers/*.conf;' >> nginx.conf
echo '}' >> nginx.conf
cat nginx.conf | grep include
# Nginx配置调整 - fdfs.conf
[ -d 'servers' ] && echo "目录已经存在" || mkdir servers
echo '
server {
listen 8090;
server_name uploadserver,_;
access_log /home/guoyingjiang/opt/nginx/logs/a.log;
error_log /home/guoyingjiang/opt/nginx/logs/e.log;
location /group1/M00 {
root /home/guoyingjiang/opt/data/fastdfs_storage/data;
ngx_fastdfs_module;
}
location / {
root /var/www/html/html;
index index.html index.htm;
}
}
' > servers/fdfs.conf;
# Nginx 日志配置
mkdir -p /home/guoyingjiang/opt/nginx/logs;
# Nginx 配置文件检测
nginx -t
# Nginx 启动
nginx -s stop || echo "Nginx貌似没有进程"
nginx
# fdfs Client 配置
sed -i 's/tracker_server=.*/tracker_server=10.0.1.20:22122/g' /home/guoyingjiang/opt/fastdfs/etc/fdfs/client.conf
# 联合测试
/home/guoyingjiang/opt/fastdfs/usr/bin/fdfs_upload_file /home/guoyingjiang/opt/fastdfs/etc/fdfs/client.conf /home/guoyingjiang/opt/FastDFS_v5.05.tar.gz | xargs -i wget http://127.0.0.1:8090/{}
# 判断mysql端口是否存在,否则就强杀
# ps aux | grep mysql | grep -v grep | awk '{print $2}' | xargs -i kill -9 {}
# 定义变量
MYDIR=/home/guoyingjiang/opt
NOW=`date +%Y%m%d%H%M`
# 备份过去的文件,下载文件
cd /home/guoyingjiang/opt
mkdir -p $MYDIR/bak/$NOW
touch mariadb.$NOW
## [ -e "$MYDIR/mariadb*" ]
mv mariadb* $MYDIR/bak/$NOW/
# 开始下载文件
cd /home/guoyingjiang/opt
## wget -O mariadb-10.1.16-linux-x86_64.tar.gz http://soft.ops.ac.cn/mariadb/mariadb-10.1.16-linux-x86_64.tar.gz
## tar xzf mariadb-10.1.16-linux-x86_64.tar.gz
rsync -avzP soft.ops.ac.cn::ops1970/mariadb/mariadb-10.1.16-linux-x86_64 .
ln -s mariadb-10.1.16-linux-x86_64 mariadb
# 部署配置文件
cat < $MYDIR/mariadb/my.cnf
[server]
[mysqld_safe]
log-error=/home/guoyingjiang/opt/data/mariadb/log/error.log
[mysqld]
log-bin=mysql-bin
server-id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=1
binlog_format=mixed
character_set_server=utf8
slow_query_log=on
long_query_time=2
log-error=/home/guoyingjiang/opt/data/mariadb/log/error.log
key_buffer_size=256
max_allowed_packet=4M
thread_stack=256K
table_cache=128K
sort_buffer_size=6M
read_buffer_size=4M
wait_timeout=86400
thread_concurrency=8
max_connections=100000
lower_case_table_names=1
user=guoyingjiang
basedir=/home/guoyingjiang/opt/mariadb/
datadir=/home/guoyingjiang/opt/data/mariadb/data/
log-error=/home/guoyingjiang/opt/data/mariadb/log/error.log
socket=/home/guoyingjiang/opt/data/mariadb/run/mysql.sock
pid_file=/home/guoyingjiang/opt/data/mariadb/run/mysql.pid
lc-messages-dir=/home/guoyingjiang/opt/mariadb/share/english/
relay_log=relay-bin
[galera]
[embedded]
[mariadb]
[mariadb-10.1]
EOF
# DB初始化
cd /home/guoyingjiang/opt/mariadb && ./scripts/mysql_install_db --defaults-file=/home/guoyingjiang/opt/mariadb/my.cnf
# DB第一次启动,修改mysql.server
cd /home/guoyingjiang/opt/mariadb/ && sed -i 's:^basedir=$:basedir=/home/guoyingjiang/opt/mariadb/:g' ./support-files/mysql.server
cd /home/guoyingjiang/opt/mariadb/ && sed -i '1,$ s:if $bindir/mysqladmin ping >/dev/null 2>&1; then:if test -e $mysqld_pid_file_path;then:' /home/guoyingjiang/opt/mariadb/support-files/mysql.server
# DB第一次启动,创建目录
mkdir -p /home/guoyingjiang/opt/data/mariadb/log
# 将环境变量放到 ~/.bashrc
sed -i ':mariadb:d' /home/guoyingjiang/.bashrc
echo '
export PATH=/home/guoyingjiang/opt/mariadb/bin:$PATH
' >> /home/guoyingjiang/.bashrc
# 启动DB
/home/guoyingjiang/opt/mariadb/support-files/mysql.server restart
(fabenv) [root@ss src]# cat zookeeper.sh
cd /home/guoyingjiang/opt
wget -O zookeeper-3.4.7.tar.gz http://soft.ops.ac.cn/zookeeper/zookeeper-3.4.7.tar.gz
tar xzvf zookeeper-3.4.7.tar.gz
[ -L "zookeeper" ] && rm -f zookeeper || echo "软连接不存在"
ln -s zookeeper-3.4.7 zookeeper
cd /home/guoyingjiang/opt/zookeeper/conf/
wget -O zoo.cfg http://soft.ops.ac.cn/zookeeper/zoo.cfg
# 配置修改。定制修改 线上部署,需要调整~/zookeeper/conf/zoo.cfg里面的配置
sed -i 's:dataDir=.*:dataDir=/home/guoyingjiang/opt/data/zookeeper:g' zoo.cfg
sed -i 's:maxClientCnxns=.*:maxClientCnxns=100000:g' zoo.cfg
sed -i 's/server.1=.*/server.1=10.0.1.1:2888:3888/g' zoo.cfg
sed -i 's/server.2=.*/server.1=10.0.1.2:2888:3888/g' zoo.cfg
sed -i 's/server.3=.*/server.1=10.0.1.3:2888:3888/g' zoo.cfg
# 部署ID
cd /home/guoyingjiang/opt/zookeeper/
mkdir -p /home/guoyingjiang/opt/data/zookeeper
echo '2' > /home/guoyingjiang/opt/data/zookeeper/myid
# 环境变量
sed -i ':zkServer.sh:d' /home/guoyingjiang/.bashrc
echo '
export PATH=/home/guoyingjiang/opt/zookeeper/bin/:$PATH
' >> /home/guoyingjiang/.bashrc
# 启动
/home/guoyingjiang/opt/zookeeper/bin/zkServer.sh restart