码迷,mamicode.com
首页 > 其他好文 > 详细

自动化安装脚本

时间:2017-08-09 13:11:43      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:1.0   bst   mkfs   fas   exp   lib   ade   ntp   -o   

Nginx自动化安装脚本:

技术分享
#!/bin/bash
#install nginx-1.10.2

#installation directory

INSTALL_DIR=/usr/local
SRC_DIR=/usr/local/src


[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}
[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1
fi

#install Depend on the package
for Package in wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
do
    yum -y install $Package
done

Install_Nginx()
{
#version information
NGINX="nginx-1.10.2"


#define compile parameter
NGINXFEATURES="--prefix=${INSTALL_DIR}/nginx \
--user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --pid-path=/var/run/nginx.pid "

cd ${SRC_DIR}
#Download the installation package
echo Downloading NGINX
if [ ! -f ${NGINX}.tar.gz ]
then
  wget -c http://nginx.org/download/${NGINX}.tar.gz
else
  echo Skipping: NGINX already downloaded
fi


echo ----------Unpacking downloaded archives. This process may take serveral minutes---------

echo "Extracting ${NGINX}......"
tar xzf ${NGINX}.tar.gz
echo Done.

#add nginx user
groupadd -r nginx
useradd -r -g nginx nginx

#make install 
echo ###################
echo Compile NGINX
echo ###################
cd ${SRC_DIR}/${NGINX}
./configure ${NGINXFEATURES}
make
make install
cd ../

echo #####################################
[ $? = "0" ] && echo "Nginx Install sucess"
echo #####################################

}

#configure file setting
config_Nginx()
{
echo user nginx;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;


events {
    use epoll;
    worker_connections 65535;
}

http {
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    server_tokens off;
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    client_max_body_size 30m;  
   
    fastcgi_connect_timeout 300;  
    fastcgi_send_timeout 300;  
    fastcgi_read_timeout 300;  
    fastcgi_buffer_size 64k;  
    fastcgi_buffers 4 64k;  
    fastcgi_busy_buffers_size 128k;  
    fastcgi_temp_file_write_size 128k;  
   
    gzip on;  
    gzip_min_length  1k;  
    gzip_buffers     4 16k;  
    gzip_http_version 1.0;  
    gzip_comp_level 2;  
    gzip_types       text/plain application/x-javascript text/css application/xml;  
    gzip_vary on;  

    include /usr/local/nginx/conf/conf.d/*.conf;

upstream tomcat7{
        server 127.0.0.1:8080;

        }

}

‘ | sudo tee /tmp/nginx.conf

#vhost.conf setting
cat > /tmp/vhost.conf << EOF 
server {
    listen       80;
    server_name  localhost;


    location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|)$ {
            root  /usr/local/tomcat7/webapps/;
        }

    location / {
    proxy_pass http://tomcat7;
    proxy_redirect off;
    proxy_set_header HOST \$host;
    proxy_set_header X-Real-IP \$remote_addr;
    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
    client_max_body_size 50m;
    client_body_buffer_size 512k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffer_size 10k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
     }

   location /nginx_status {
          stub_status on;
           access_log off;
          allow 127.0.0.1;
          deny all;
 }
   error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}
log_format access ‘\$remote_addr - \$remote_user [\$time_local] "\$request" ‘
                ‘\$status \$body_bytes_sent "\$http_referer" ‘
                ‘"\$http_user_agent" "\$http_x_forwarded_for" \$request_time‘;

    access_log  /usr/local/nginx/logs/access.log  access;
     
EOF

}

Nginx_start()
{
/bin/cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
/bin/cp /tmp/nginx.conf /usr/local/nginx/conf/
/bin/cp /tmp/vhost.conf /usr/local/nginx/conf/conf.d

/usr/local/nginx/sbin/nginx -t
[ $? = "0" ] && echo "Nginx config sucess ..."

}

Install_Nginx
config_Nginx
Nginx_start
Nginx自动化脚本
技术分享
#!/bin/bash
#install nginx-1.10.2



#安装目录
INSTALL_DIR=/usr/local
SRC_DIR=/usr/local/src


[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}
[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1
fi

#安装依赖包
for Package in wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
do
    yum -y install $Package
done

Install_Nginx()
{
#更新版本信息
NGINX="nginx-1.10.2"
PCRE="pcre-8.35"
ZLIB="zlib-1.2.8"
OPENSSL="openssl-1.0.1i"

NGINXFEATURES="--prefix=${INSTALL_DIR}nginx \
--user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --pid-path=/var/run/nginx.pid --with-pcre=${SRC_DIR}/${PCRE} --with-zlib=${SRC_DIR}/${ZLIB} --with-openssl=${SRC_DIR}/${OPENSSL}
"

cd ${SRC_DIR}
#下载所需安装包
echo Downloading NGINX
if [ ! -f ${NGINX}.tar.gz ]
then
  wget -c http://nginx.org/download/${NGINX}.tar.gz
else
  echo Skipping: NGINX already downloaded
fi

echo Downloading PCRE
if [ ! -f ${PCRE}.tar.gz ]
then
  wget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/${PCRE}.tar.gz
else
  echo Skipping: PCRE already downloaded
fi

echo Downloading ZLIB
if [ ! -f ${ZLIB}.tar.gz ]
then
  wget -c http://zlib.net/${ZLIB}.tar.gz
else
  echo Skipping: ZLIB already downloaded
fi

echo Downloading OPENSSL
if [ ! -f ${OPENSSL}.tar.gz ]
then
  wget -c http://www.openssl.org/source/${OPENSSL}.tar.gz
else
  echo Skipping: OPENSSL already downloaded
fi

echo ----------Unpacking downloaded archives. This process may take serveral minutes---------

echo "Extracting ${NGINX}......"
tar xzf ${NGINX}.tar.gz
echo Done.

echo "Extracting ${PCRE}..."
tar xzf ${PCRE}.tar.gz
echo Done.

echo "Extracting ${ZLIB}..."
tar xzf ${ZLIB}.tar.gz
echo Done.

echo "Extracting ${OPENSSL}..."
tar xzf ${OPENSSL}.tar.gz
echo Done.

#添加用户
groupadd -r nginx
useradd -r -g nginx nginx

#编译
echo ###################
echo Compile NGINX
echo ###################
cd ${SRC_DIR}/${NGINX}
./configure ${NGINXFEATURES}
make
make install
cd ../

mkdir -p ${INSTALL_DIR}/nginx/conf/vhosts

}

Install_Nginx



链接地址:http://blog.csdn.net/loyachen/article/details/50904593
参考Nginx脚本

Nginx+PHP安装:

技术分享
#!/bin/bash
#install nginx-1.10.2

#installation directory

INSTALL_DIR=/usr/local
SRC_DIR=/usr/local/src


[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}
[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}
[ ! -d /data/log ] && mkdir -p /data/log/nginx


# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1
fi

#install Depend on the package
for Package in wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
do
    yum -y install $Package
done

Install_Nginx()
{
#version information
NGINX="nginx-1.10.2"


#define compile parameter
NGINXFEATURES="--prefix=${INSTALL_DIR}/nginx \
--user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --pid-path=/var/run/nginx.pid "

cd ${SRC_DIR}
#Download the installation package
echo Downloading NGINX
if [ ! -f ${NGINX}.tar.gz ]
then
  wget -c http://nginx.org/download/${NGINX}.tar.gz
else
  echo Skipping: NGINX already downloaded
fi


echo ----------Unpacking downloaded archives. This process may take serveral minutes---------

echo "Extracting ${NGINX}......"
tar xzf ${NGINX}.tar.gz
echo Done.

#add nginx user
groupadd -r nginx
useradd -r -g nginx nginx

#make install 
echo ###################
echo Compile NGINX
echo ###################
cd ${SRC_DIR}/${NGINX}
./configure ${NGINXFEATURES}
make
make install
cd ../

mkdir -p ${INSTALL_DIR}/nginx/conf/conf.d
echo #####################################
[ $? = "0" ] && echo "Nginx Install sucess"
echo #####################################

}

#configure file setting
config_Nginx()
{
echo user nginx;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;


events {
    use epoll;
    worker_connections 65535;
}

http {
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    server_tokens off;
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    client_max_body_size 30m;  
   
    fastcgi_connect_timeout 300;  
    fastcgi_send_timeout 300;  
    fastcgi_read_timeout 300;  
    fastcgi_buffer_size 64k;  
    fastcgi_buffers 4 64k;  
    fastcgi_busy_buffers_size 128k;  
    fastcgi_temp_file_write_size 128k;  
   
    gzip on;  
    gzip_min_length  1k;  
    gzip_buffers     4 16k;  
    gzip_http_version 1.0;  
    gzip_comp_level 2;  
    gzip_types       text/plain application/x-javascript text/css application/xml;  
    gzip_vary on;  

    include /usr/local/nginx/conf/conf.d/*.conf;

}

‘ | sudo tee /tmp/nginx.conf

#vhost.conf setting
cat > /tmp/vhost.conf << EOF 
server {
listen 80;
server_name localhost;
root html;

location / {


        root html;
        index index.html index.htm index.php;

        }

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;

include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
    }
}

log_format access ‘\$remote_addr - \$remote_user [\$time_local] "\$request" ‘
                ‘\$status \$body_bytes_sent "\$http_referer" ‘
                ‘"\$http_user_agent" "\$http_x_forwarded_for" \$request_time‘;

    access_log  /usr/local/nginx/logs/access.log  access;

EOF

}

Nginx_start()
{
/bin/cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
/bin/cp /tmp/nginx.conf /usr/local/nginx/conf/
/bin/cp /tmp/vhost.conf /usr/local/nginx/conf/conf.d

/usr/local/nginx/sbin/nginx -t
[ $? = "0" ] && echo "Nginx config sucess ..."

}
#PHP yum 方法安装
#phpinstall()
#{
#rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
#echo "install php..."

#yum install php70w  php70w-bcmath php70w-cli php70w-common  php70w-devel php70w-fpm    php70w-gd php70w-imap  php70w-ldap php70w-mbstring php70w-mcrypt php70w-mysql   php70w-odbc   php70w-pdo   php70w-pear  php70w-pecl-igbinary  php70w-xml php70w-xmlrpc php70w-opcache php70w-intl php70w-pecl-memcache --skip-broken -y
#}

#PHP编译安装
phpinstall()
{
#version information
PHP="php-7.0.14"

#define compile parameter
PHPFEATURES="--prefix=${INSTALL_DIR}/php7 --enable-fpm --enable-fastCGI  --enable-zip --with-mysql --with-gd "
cd ${SRC_DIR}
#Download the installation package

echo ‘Downloading PHP‘
if [ ! -f ${PHP}.tar.gz ]
then
  wget -c http://ftp.ntu.edu.tw/php/distributions/${PHP}.tar.gz
else
  echo ‘Skipping: PHP already downloaded‘
fi

#install Depend on the package
for Package in libxml2 libxml2-devel libpng libpng-devel
do
    yum -y install $Package
done

echo ‘----------Unpacking downloaded archives. This process may take serveral minutes---------‘
echo "Extracting ${PHP}......"
tar xzf ${PHP}.tar.gz
echo ‘Done.‘

#make install 
echo ‘###################‘
echo ‘Compile PHP‘
echo ‘###################‘
cd ${SRC_DIR}/${PHP}
./configure ${PHPFEATURES}
make
make install

#file replace
/bin/cp php.ini-production /usr/local/php7/etc/php.ini
cd /usr/local/php7/etc/ && /bin/cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php7/etc/php-fpm.d/ && /bin/cp www.conf.default www.conf
/usr/local/php7/sbin/php-fpm -t


echo ‘#####################################‘
[ $? = "0" ] && echo "PHP Install sucess"
echo ‘#####################################‘

}

Install_Nginx
config_Nginx
Nginx_start
phpinstall
Nginx-PHP安装脚本

Java tomcat7自动化安装脚本:

技术分享
#!/bin/bash
#install tomcat7

#安装目录
INSTALL_DIR=/usr/local
SRC_DIR=/usr/local/src

[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}
[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}

#Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1
fi

#安装JDK
JDK_Install(){
JDK_VERSION="jdk-8u77-linux-x64"
cd ${SRC_DIR}
if [ -f ${JDK_VERSION}.rpm ];then
  echo "Skipping: JDK already downloaded"
else
  echo "wget -c .............."
fi
echo "Install ${JDK_VERSION} start..."
rpm -ivh ${JDK_VERSION}.rpm
echo Done.
[ $? = "0" ] && echo "JDK install sucess"

}
#安装tomcat
TOMCAT_INSTALL()
{
TOMCAT="apache-tomcat-7.0.72"
cd ${SRC_DIR}
if [ -f ${TOMCAT}.tar.gz ];then
  echo "Skipping: ${TOMCAT} already downloaded"
else
  echo "wget -c .............."
fi

tar -zxf ${TOMCAT}.tar.gz -C ${INSTALL_DIR}

if [ $? != "0" ];then
  echo "tomcat install error."
else
  echo "tomcat install sucess...."
fi

cd ${INSTALL_DIR} && /bin/mv ${TOMCAT} tomcat7 && echo "mv sucess."
}

JDK_Install
TOMCAT_INSTALL
Java tomcat脚本

系统初始化脚本:

技术分享
#!/bin/bash
/etc/init.d/ntpd stop
chkconfig ntpd off
echo */59 * * * * /usr/sbin/ntpdate cn.pool.ntp.org>/dev/null 2>&1>>/var/spool/cron/root
/bin/cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +%F-%T`
sed -i s/#Port 22/Port 6168/g /etc/ssh/sshd_config 
sed -i s/#UseDNS yes/UseDNS no/g /etc/ssh/sshd_config 
sed -i s/#PermitEmptyPasswords no/PermitEmptyPasswords no/g /etc/ssh/sshd_config 
sed -i s@PermitRootLogin yes@PermitRootLogin no@g /etc/ssh/sshd_config
/etc/init.d/sshd restart
echo "export HISTTIMEFORMAT=‘%F-%T ‘">>/etc/profile
echo ulimit -HSn 65535 >> /etc/profile
echo ulimit -HSn 65535>>/etc/rc.local
source /etc/profile
系统初始化脚本

磁盘分区及自动化挂载脚本:

技术分享
#!/bin/bash
fdisk /dev/vdb <<EOF
n
p
1


wq
EOF

/sbin/mkfs.ext4 /dev/vdb1 && echo "Formatting completed..."

/bin/mkdir -pv /data && /bin/mount /dev/vdb1 /data && echo "mount suceess..."
#ls  -lh  /dev/disk/by-uuid/ |grep vdb1 |awk {print $9}
uuid=`blkid |grep /dev/vdb1 |awk -F " {print $2}`
echo $uuid
echo "UUID=$uuid /data ext4 defaults,barrier=0 1 1" >> /etc/fstab && echo "fstab sucess."
磁盘分区及自动化挂载

Zabbix自动化安装脚本:

技术分享
#!/bin/bash

echo -n "stop SELinux..."
setenforce 0 > /dev/null 2>&1
sed -i /^SELINUX=/s/=.*/=disabled/ /etc/selinux/config && echo "OK"

echo -n "stop iptables fire ……"

/etc/init.d/iptables stop

echo -n "upgrate php version,默认为5.3.3的版本..."
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm

yum install php56w php56w-gd php56w-mysql php56w-bcmath php56w-mbstring php56w-xml php56w-ldap -y



sed -i "s@;date.timezone =@date.timezone = Asia/Shanghai@g"  /etc/php.ini 
sed -i "s@post_max_size = 8M@post_max_size = 32M@" /etc/php.ini 
sed -i "s@max_execution_time = 30@max_execution_time = 300@" /etc/php.ini 
sed -i "s@max_input_time = 60@max_input_time = 300@" /etc/php.ini 
sed -i "s@;always_populate_raw_post_data = -1@always_populate_raw_post_data = -1@" /etc/php.ini 


echo -n "升级MYSQL的版本,默认为5.1的版本"

rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

yum install -y mysql-server mysql-devel -y

echo -n "正在启动mysqld服务……"
service mysqld start > /dev/null 2>&1 && echo "OK"

echo -n "正在为mysql的root用户设置密码……"
mysqladmin -uroot password "123456" && echo "OK"


echo "正在执行mysql语句……"

mysql -uroot -p123456 -e "CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;" && echo "sucess."
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY ‘zabbix‘;" && echo "sucess."
mysql -uroot -p123456 -e "flush privileges;" 


echo "安装Zabbix"

groupadd  -g 201  zabbix
useradd  -g zabbix  -u 201 -m zabbix

yum install httpd libxml2-devel net-snmp-devel libcurl-devel -y


echo -n "正在下载zabbix源码包……"
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
echo -n "正在解压……"
tar zxvf zabbix-3.0.3.tar.gz

cd zabbix-3.0.3

/usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
/usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
/usr/bin/mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql

./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql --with-libxml2

make &&make install
zabbix自动化安装脚本

Zabbix 代理端安装脚本:

技术分享
#!/bin/bash

rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

yum -y install zabbix-agent

sed -i s#Server=127.0.0.1#Server=192.168.100.7#g /etc/zabbix/zabbix_agentd.conf
sed -i s#ServerActive=127.0.0.1#ServerActive=192.168.100.7:10050#g /etc/zabbix/zabbix_agentd.conf
sed -i s#Server=127.0.0.1#Server=60.205.204.172#g /etc/zabbix/zabbix_agentd.conf
sed -i s#ServerActive=127.0.0.1#ServerActive=60.205.204.172:10050#g /etc/zabbix/zabbix_agentd.conf

/etc/init.d/zabbix-agent restart
chkconfig zabbix-agent on
zabbix agent 代理端脚本

 

 

 

自动化安装脚本

标签:1.0   bst   mkfs   fas   exp   lib   ade   ntp   -o   

原文地址:http://www.cnblogs.com/saneri/p/7324463.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!