This commit is contained in:
condor
2026-07-24 18:54:53 +08:00
parent 43c2a411b9
commit 679e0b4184
128 changed files with 13855 additions and 1 deletions
+78
View File
@@ -0,0 +1,78 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
Install_fail2ban() {
pushd ${oneinstack_dir}/src > /dev/null
src_url=http://mirrors.linuxeye.com/oneinstack/src/fail2ban-${fail2ban_ver}.tar.gz && Download_src
tar xzf fail2ban-${fail2ban_ver}.tar.gz
pushd fail2ban-${fail2ban_ver} > /dev/null
sed -i 's@for i in xrange(50)@for i in range(50)@' fail2ban/__init__.py
${python_install_dir}/bin/python setup.py install
if [ -e /bin/systemctl ]; then
/bin/cp build/fail2ban.service /lib/systemd/system/
systemctl enable fail2ban
else
if [ "${PM}" == 'yum' ]; then
/bin/cp files/redhat-initd /etc/services/fail2ban
sed -i "s@^FAIL2BAN=.*@FAIL2BAN=${python_install_dir}/bin/fail2ban-client@" /etc/services/fail2ban
sed -i 's@Starting fail2ban.*@&\n [ ! -e "/var/run/fail2ban" ] \&\& mkdir /var/run/fail2ban@' /etc/services/fail2ban
chmod +x /etc/services/fail2ban
chkconfig --add fail2ban
chkconfig fail2ban on
elif [ "${PM}" == 'apt-get' ]; then
/bin/cp files/debian-initd /etc/services/fail2ban
sed -i 's@2 3 4 5@3 4 5@' /etc/services/fail2ban
sed -i "s@^DAEMON=.*@DAEMON=${python_install_dir}/bin/\$NAME-client@" /etc/services/fail2ban
chmod +x /etc/services/fail2ban
update-rc.d fail2ban defaults
fi
fi
[ -z "`grep ^Port /etc/ssh/sshd_config`" ] && now_ssh_port=22 || now_ssh_port=`grep ^Port /etc/ssh/sshd_config | awk '{print $2}' | head -1`
[ "${PM}" == 'yum' ] && LOGPATH=/var/log/secure
[ "${PM}" == 'apt-get' ] && LOGPATH=/var/log/auth.log
cat > /etc/fail2ban/jail.local << EOF
[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 86400
findtime = 600
maxretry = 5
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=${now_ssh_port}, protocol=tcp]
logpath = ${LOGPATH}
EOF
cat > /etc/logrotate.d/fail2ban << EOF
/var/log/fail2ban.log {
missingok
notifempty
postrotate
${python_install_dir}/bin/fail2ban-client flushlogs >/dev/null || true
endscript
}
EOF
sed -i 's@^iptables = iptables.*@iptables = iptables@' /etc/fail2ban/action.d/iptables-common.conf
kill -9 `ps -ef | grep fail2ban | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
service fail2ban start
popd > /dev/null
if [ -e "${python_install_dir}/bin/fail2ban-server" ]; then
echo; echo "${CSUCCESS}fail2ban installed successfully! ${CEND}"
else
echo; echo "${CFAILURE}fail2ban install failed, Please try again! ${CEND}"
fi
popd > /dev/null
}
Uninstall_fail2ban() {
service fail2ban stop
${python_install_dir}/bin/pip uninstall -y fail2ban > /dev/null 2>&1
rm -rf /etc/services/fail2ban /etc/fail2ban /etc/logrotate.d/fail2ban /var/log/fail2ban.* /var/run/fail2ban
echo; echo "${CMSG}fail2ban uninstall completed${CEND}";
}
+125
View File
@@ -0,0 +1,125 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
Nginx_lua_waf() {
pushd ${oneinstack_dir}/src > /dev/null
[ ! -e "${nginx_install_dir}/sbin/nginx" ] && echo "${CWARNING}Nginx is not installed on your system! ${CEND}" && exit 1
if [ ! -e "/usr/local/lib/libluajit-5.1.so.2.1.0" ]; then
[ -e "/usr/local/lib/libluajit-5.1.so.2.0.5" ] && find /usr/local -name *luajit* | xargs rm -rf
src_url=http://mirrors.linuxeye.com/oneinstack/src/luajit2-${luajit2_ver}.tar.gz && Download_src
tar xzf luajit2-${luajit2_ver}.tar.gz
pushd luajit2-${luajit2_ver}
make && make install
[ ! -e "/usr/local/lib/libluajit-5.1.so.2.1.0" ] && { echo "${CFAILURE}LuaJIT install failed! ${CEND}"; kill -9 $$; exit 1; }
popd > /dev/null
rm -rf luajit2-${luajit2_ver}
fi
src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-resty-core-${lua_resty_core_ver}.tar.gz && Download_src
tar xzf lua-resty-core-${lua_resty_core_ver}.tar.gz
pushd lua-resty-core-${lua_resty_core_ver}
make install
popd > /dev/null
rm -rf lua-resty-core-${lua_resty_core_ver}
src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz && Download_src
tar xzf lua-resty-lrucache-${lua_resty_lrucache_ver}.tar.gz
pushd lua-resty-lrucache-${lua_resty_lrucache_ver}
make install
popd > /dev/null
rm -rf lua-resty-lrucache-${lua_resty_lrucache_ver}
[ ! -h "/usr/local/share/lua/5.1" ] && { rm -rf /usr/local/share/lua/5.1 ; ln -s /usr/local/lib/lua /usr/local/share/lua/5.1; }
if [ ! -e "/usr/local/lib/lua/5.1/cjson.so" ]; then
src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-cjson-${lua_cjson_ver}.tar.gz && Download_src
tar xzf lua-cjson-${lua_cjson_ver}.tar.gz
pushd lua-cjson-${lua_cjson_ver}
sed -i 's@^LUA_INCLUDE_DIR.*@&/luajit-2.1@' Makefile
make && make install
[ ! -e "/usr/local/lib/lua/5.1/cjson.so" ] && { echo "${CFAILURE}lua-cjson install failed! ${CEND}"; kill -9 $$; exit 1; }
popd > /dev/null
fi
${nginx_install_dir}/sbin/nginx -V &> $$
nginx_configure_args_tmp=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
rm -rf $$
nginx_configure_args=`echo ${nginx_configure_args_tmp} | sed "s@--with-openssl=../openssl-\w.\w.\w\+ @--with-openssl=../openssl-${openssl11_ver} @" | sed "s@--with-pcre=../pcre-\w.\w\+ @--with-pcre=../pcre-${pcre_ver} @"`
if [ -z "`echo ${nginx_configure_args} | grep lua-nginx-module`" ]; then
src_url=http://nginx.org/download/nginx-${nginx_ver}.tar.gz && Download_src
src_url=https://www.openssl.org/source/openssl-${openssl11_ver}.tar.gz && Download_src
src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-${pcre_ver}.tar.gz && Download_src
src_url=http://mirrors.linuxeye.com/oneinstack/src/ngx_devel_kit.tar.gz && Download_src
src_url=http://mirrors.linuxeye.com/oneinstack/src/lua-nginx-module-${lua_nginx_module_ver}.tar.gz && Download_src
tar xzf nginx-${nginx_ver}.tar.gz
tar xzf openssl-${openssl11_ver}.tar.gz
tar xzf pcre-${pcre_ver}.tar.gz
tar xzf ngx_devel_kit.tar.gz
tar xzf lua-nginx-module-${lua_nginx_module_ver}.tar.gz
pushd nginx-${nginx_ver}
make clean
sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
./configure ${nginx_configure_args} --with-ld-opt="-Wl,-rpath,/usr/local/lib" --add-module=../lua-nginx-module-${lua_nginx_module_ver} --add-module=../ngx_devel_kit
make -j ${THREAD}
if [ -f "objs/nginx" ]; then
/bin/mv ${nginx_install_dir}/sbin/nginx{,`date +%m%d`}
/bin/cp objs/nginx ${nginx_install_dir}/sbin/nginx
kill -USR2 `cat /var/run/nginx.pid`
sleep 1
kill -QUIT `cat /var/run/nginx.pid.oldbin`
popd > /dev/null
echo "${CSUCCESS}lua-nginx-module installed successfully! ${CEND}"
sed -i "s@^nginx_modules_options='\(.*\)'@nginx_modules_options=\'\1 --with-ld-opt=\"-Wl,-rpath,/usr/local/lib\" --add-module=../lua-nginx-module-${lua_nginx_module_ver} --add-module=../ngx_devel_kit\'@" ../config/options.conf
rm -rf nginx-${nginx_ver}
else
echo "${CFAILURE}lua-nginx-module install failed! ${CEND}"
kill -9 $$; exit 1;
fi
fi
popd > /dev/null
}
enable_lua_waf() {
pushd ${oneinstack_dir}/src > /dev/null
. ../lib/check_dir.sh
rm -f ngx_lua_waf.tar.gz
src_url=http://mirrors.linuxeye.com/oneinstack/src/ngx_lua_waf.tar.gz && Download_src
tar xzf ngx_lua_waf.tar.gz -C ${web_install_dir}/conf
[ -e "${web_install_dir}/conf/resty" ] && /bin/mv ${web_install_dir}/conf/resty{,_bak}
sed -i "s@/usr/local/nginx@${web_install_dir}@g" ${web_install_dir}/conf/waf.conf
sed -i "s@/usr/local/nginx@${web_install_dir}@" ${web_install_dir}/conf/waf/config.lua
sed -i "s@/data/wwwlogs@${wwwlogs_dir}@" ${web_install_dir}/conf/waf/config.lua
[ -z "`grep 'include waf.conf;' ${web_install_dir}/conf/nginx.conf`" ] && sed -i "s@ vhost/\*.conf;@&\n include waf.conf;@" ${web_install_dir}/conf/nginx.conf
${web_install_dir}/sbin/nginx -t
if [ $? -eq 0 ]; then
service nginx reload
echo "${CSUCCESS}ngx_lua_waf enabled successfully! ${CEND}"
chown ${run_user}:${run_group} ${wwwlogs_dir}
else
echo "${CFAILURE}ngx_lua_waf enable failed! ${CEND}"
fi
popd > /dev/null
}
disable_lua_waf() {
pushd ${oneinstack_dir}/src > /dev/null
. ../lib/check_dir.sh
sed -i '/include waf.conf;/d' ${web_install_dir}/conf/nginx.conf
${web_install_dir}/sbin/nginx -t
if [ $? -eq 0 ]; then
rm -rf ${web_install_dir}/conf/{waf,waf.conf}
service nginx reload
echo "${CSUCCESS}ngx_lua_waf disabled successfully! ${CEND}"
else
echo "${CFAILURE}ngx_lua_waf disable failed! ${CEND}"
fi
popd > /dev/null
}