一键安装Redis脚本,一劳永逸

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!bin/sh
cd ~
FILE=/root/redis-5.0.8.tar.gz

# 判断文件是否存在
if test -f "$FILE"; then
echo "$FILE exist"
else
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
fi
# 解压安装包
tar -zxvf redis-5.0.8.tar.gz
# 重命名
mv redis-5.0.8 redis
# 移动文件
mv -f redis /usr/local/redis

cd /usr/local/redis
mkdir data

make MALLOC=lib
make install

cp /usr/local/redis/redis.conf /etc/redis/6354.conf

cd /etc/init.d
touch redis
chmod 777 redis
cat << EOF > redis

REDISPORT=6354
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
password="Admin123"

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a $password -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
EOF

chkconfig --add redis
chkconfig --list redis

service redis start

一键安装MySQL5.7脚本,一劳永逸

MySQL5.0脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# 提示:本脚本只支持centos 7 安装MySQL版本5.7
# 安装完成后脚本会打印出MySQL的root用户的初始登录密码
# mysql -u root -p
# 输入初始密码即可登录

#wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.36-el7-x86_64.tar.gz
REMOVE=`rpm -qa | grep -i mariadb-libs`
#卸载系统预置的mariadb
yum remove $REMOVE -y
#安装依赖库
yum install libaio -y
yum install libncurses* -y
yum install wget -y
#下载
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.36-el7-x86_64.tar.gz
tar -zxvf mysql-5.7.36-el7-x86_64.tar.gz
mv mysql-5.7.36-el7-x86_64 mysql
mv mysql /usr/local/
useradd -s/sbin/nlogin -M mysql
id mysql
mkdir /usr/local/mysql/{data,log}
chown -R mysql.mysql /usr/local/mysql/
#编辑my.cnf
cat << EOF > /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data/
pid-file = /usr/local/mysql/data/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
log-bin=mysql-bin
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend

#####====================================[log]==============================
log_error = /usr/local/mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/log/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
EOF

#编译
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
#授权
chown -R mysql:mysql /usr/local/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysqld
chkconfig --list
cp /usr/local/mysql/bin/* /usr/local/sbin/
cd /lib/systemd/system
## 启动服务并查看
/etc/init.d/mysql start
netstat -lntup|grep mysql
grep "password" /usr/local/mysql/log/mysql-error.log

MySQL8.0脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh

# 使用
# 去到https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads
# 选中合适的mysql版本并修改脚本中的链接

export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

Install_MySQL() {
# CentOS 8 mysql: error while loading shared libraries: libncurses.so.5
yum install ncurses ncurses-compat-libs -y
# Install dependencies
setenforce 0
yum -y install epel-release
yum -y install wget tar jemalloc jemalloc-devel gcc gcc-c++

# MySQL configuration
# 此处应当进行适当修改
mysql_version="8.0.26"
mysql_password="123456"
mkdir -p /apps/server/mysql/data
mysql_install_dir="/usr/local/mysql"
mysql_data_dir="/usr/local/mysql/data"
download_mysql="https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads"

# Download MySQL
cd /mnt
useradd -M -s /sbin/nologin mysql >/dev/null 2>&1
wget -c ${download_mysql}/MySQL-8.0/mysql-${mysql_version}-linux-glibc2.12-x86_64.tar.xz --no-check-certificate
echo "========== Start installing MySQL ============"
tar xJf mysql-${mysql_version}-linux-glibc2.12-x86_64.tar.xz
mkdir ${mysql_install_dir}
mv mysql-${mysql_version}-linux-glibc2.12-x86_64/* ${mysql_install_dir}/

if [[ -d "${mysql_install_dir}/support-files" ]]; then
rm -rf mysql-${mysql_version}-linux-glibc2.12-x86_64
else
rm -rf ${mysql_install_dir}
echo "Error: MySQL install failed, Please contact the author"
kill -9 $$
fi

# Initialize the database
${mysql_install_dir}/bin/mysqld --initialize-insecure --user=mysql --basedir=${mysql_install_dir} --datadir=${mysql_data_dir}
chown -R root . ${mysql_install_dir}
chown -R mysql.mysql ${mysql_data_dir}
cp -f ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
sed -i "s@^basedir=.*@basedir=${mysql_install_dir}@" /etc/init.d/mysqld
sed -i "s@^datadir=.*@datadir=${mysql_data_dir}@" /etc/init.d/mysqld
sed -i "s@/usr/local/mysql@${mysql_install_dir}@g" ${mysql_install_dir}/bin/mysqld_safe
sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/lib64/libjemalloc.so@' ${mysql_install_dir}/bin/mysqld_safe
#删除配置文件中原有的环境变量
sed -ie '/MYSQL_HOME/d' /etc/profile
#修改mysql的环境变量,直接写入配置文件
echo "export MYSQL_HOME=${mysql_install_dir}" >>/etc/profile
echo "export PATH=\$PATH:\$MYSQL_HOME/bin" >>/etc/profile
source /etc/profile
# my.conf configuration
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash

[mysqld]
port = 3306
socket = /tmp/mysql.sock
default_authentication_plugin = mysql_native_password

basedir = ${mysql_install_dir}
datadir = ${mysql_data_dir}
pid-file = ${mysql_data_dir}/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1

init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
collation-server = utf8mb4_0900_ai_ci

skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M

thread_cache_size = 8

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
binlog_expire_logs_seconds = 604800

log_error = ${mysql_data_dir}/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = ${mysql_data_dir}/mysql-slow.log

performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

[mysqldump]
quick
max_allowed_packet = 500M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
# Set up MySQL
chmod 600 /etc/my.cnf
chmod +x /etc/init.d/mysqld
cp /etc/init.d/mysqld /usr/bin
systemctl enable mysqld
systemctl start mysqld
${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "create user root@'127.0.0.1' identified by \"${mysql_password}\";"
${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'127.0.0.1' with grant option;"
${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'localhost' with grant option;"
${mysql_install_dir}/bin/mysql -uroot -hlocalhost -e "alter user root@'localhost' identified by \"${mysql_password}\";"
${mysql_install_dir}/bin/mysql -uroot -p${mysql_password} -e "reset master;"
rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
echo "${mysql_install_dir}/lib" > /etc/ld.so.conf.d/mysql_renwole.com.conf
ldconfig
echo "========== MySQL installing Successfully ====="
echo "MySQL:"
echo "account: root"
echo "password: ${mysql_password}"
echo "database: ${mysql_data_dir}"
echo "=============================================="
}

Install_MySQL
source /etc/profile

登录MySQL

脚本执行后最后一行输出一下内容

1
[Note] A temporary password is generated for root@localhost: 2t<q#r;>2EBM

输入以下命令

1
mysql -u root -p

将2t<q#r;>2EBM输入即可登陆,注意输入时密码不回显

登陆成功后修改密码

1
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

123456就是root用户的登陆密码

允许远程连接

  • 新建用户允许远程连接
1
2
grant all on *.* to admin@'%' identified by '123456' with grant option;
flush privileges;
  • 现有用户下允许远程连接
1
2
3
use mysql;
update user set host='%' where user='root' and host='localhost';
flush privileges;
  • 查看用户
1
2
use mysql;
select host,user from user;

一键安装Java脚本,一劳永逸

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
echo "---------------uninstall old java ------------------"
#卸载旧版本的java
rpm -qa | grep java | xargs rpm -e --nodeps
rpm -qa | grep jdk | xargs rpm -e --nodeps
rpm -qa | grep gcp | xargs rpm -e --nodeps

#删除旧版本的JAVA_HOME
sed -ie '/JAVA_HOME/d' /etc/profile
echo "finished"
echo "------------------start yum install java-1.8.0-openjdk --------------"

#yum安装Java
yum install java-1.8.0-openjdk* -y

#在/etc/profile追加JAVA_HOME
cat >> /etc/profile<<EOF
export JAVA_HOME=/usr/lib/jvm/java
export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar:\$JAVA_HOME/jre/lib/rt.jar
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

#刷新JAVA_HOME
source /etc/profile

#检测是否安装成功
java -version

echo "----------------yum install java-1.8.0-openjdk success ---------------------"

简介

​ Jenkins是一个开源的、提供友好操作界面的持续集成(CI)工具。它可以根据设定持续定期编译,运行相应代码;运行UT或集成测试;将运行结果发送至邮件,或展示成报告。

​ 本文将介绍Jenkins的下载安装,Jenkins集成邮件服务系统、SVN版本控制工具,Ant构建工具以及静态分析工具Checkstyle、Findbugs、PMD,运用流水线

目录

Jenkins的下载安装

​ Jenkins集成邮件服务系统

​ SVN版本控制工具

​ Jenkins配置ant、maven、java、git

​ Jenkins集成静态分析工具Checkstyle、Findbugs、PMD

​ Jenkins集成流水线

​ CI/CD

前言

​ WebSocket是一种浏览器与服务器之间进行全双工的通信协议,属于应用层协议,基于Http协议。它有以下几个优点:

  • WebSocket可以在浏览器里使用;

  • 支持双向通信,实时性更强;

  • 使用很简单。

    后面将用一个小例子来学习WebSocket。

阅读全文 »

前言

​ 一般来说,数据库作为数据存储工具是很敏感的,特别需要安全防护和容灾备份。在生产环境中数据库是在内网下才能进行连接,外网是不允许连接的,因为外网连接下很有可能被暴力破解。但有些时候又不得不开放外网连接,这时候就需要重视暴力破解了,而MySQL官方中提供了一个缓解暴力破解数据库的方法:当用户错误登陆次数达到一定次数时,在一段时间内禁止再次请求登录,从而避免了数据库被暴力破解。以下是官方文档的原文描述:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
As of MySQL 5.7.17, MySQL Server includes a plugin library that enables
administrators to introduce an increasing delay in server response to
connection attempts after a configurable number of consecutive failed attempts.
This capability provides a deterrent that slows down brute force attacks
against MySQL user accounts. The plugin library contains two plugins:

CONNECTION_CONTROL checks incoming connection attempts and adds a delay
to server responses as necessary.
This plugin also exposes system variables that enable its operation to be
configured and a status variable that provides rudimentary monitoring information.

The CONNECTION_CONTROL plugin uses the audit plugin interface
(see Writing Audit Plugins). To collect information, it subscribes
to the MYSQL_AUDIT_CONNECTION_CLASSMASK event class, and processes
MYSQL_AUDIT_CONNECTION_CONNECT and MYSQL_AUDIT_CONNECTION_CHANGE_USER
subevents to check whether the server should introduce a delay before
responding to connection attempts.

CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS implements an INFORMATION_SCHEMA
table that exposes more detailed monitoring information for failed
connection attempts.
阅读全文 »

​ 上期说到搭建一个SpringBoot程序,该程序创建的若干符合Restful风格的接口,同时返回一些字符串,但在实际情况中,返回的字符串是有查询数据库操作的,所以这期内容是搭建集成Mybatis的Web应用程序。

阅读全文 »