inst_for_mysql5.7.sh
#!/bin/bash
# Author: wangshenjin<wangshenjin233@foxmail.com>
# Description: install percona-server-5.7.18-14
# Lastdate: 2017/10/12
# Packages in /dist/dist: libunwind-1.1.tar.gz, gperftools-2.0.tar.gz boost_1_59_0.tar.gz, percona-server-5.7.18-14.tar.gz.
# add mysql user
if ! id mysql > /dev/null 2>&1 ; then
groupadd mysql
useradd -g mysql -M mysql
fi
# install dependent packages
yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* readline-devel
[ "$?" -eq 0 ] || (echo -e "\033[31m Install dependent packages error,check yum environment. \033[0m" ; exit 1)
# update cmake
if [ G`cmake -version | awk '{if($NF < 2.8)print "x"}'` == "Gx" ] ; then
yum update -y cmake
[ "$?" -eq 0 ] || (echo -e "\033[31m Update cmake packages error,check yum environment. \033[0m" ; exit 1)
fi
# install TCMalloc
if ! ldconfig -p | grep -w libtcmalloc > /dev/null 2>&1 ; then
cd /dist/src
tar xf /dist/dist/libunwind-1.1.tar.gz
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
cd /dist/src
tar xf /dist/dist/gperftools-2.0.tar.gz
cd gperftools-2.0
./configure
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig
fi
# 安装 boost_1.59.x
cd /dist/src
tar xf /dist/dist/boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/
# 安装percona-server
CPUcount=`cat /proc/cpuinfo | grep -c "processor"`
# wget https://www.percona.com/downloads/Percona-Server-LATEST/Percona-Server-5.7.18-14/source/tarball/percona-server-5.7.18-14.tar.gz
cd /dist/src
tar xf /dist/dist/percona-server-5.7.18-14.tar.gz
cd /dist/src/percona-server-5.7.18-14
CHOST="x86_64-pc-linux-gnu" CFLAGS="-march=nocona -O2 -pipe" CXXFLAGS="-march=nocona -O2 -pipe" \
cmake \
-DMYSQL_USER=mysql \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DSYSCONFDIR:PATH=/usr/local/mysql \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DMYSQL_DATADIR:PATH=/data/database/mysql \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_BIG_TABLES:BOOL=ON \
-DWITH_FAST_MUTEXES:BOOL=ON \
-DENABLE-PROFILING:BOOL=ON \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \
-DWITH_SERVER_SUFFIX=4399DB \
-DWITH_PLUGINS=heap,csv,partition,innodb_plugin,myisam \
-DEFAULT_COLLATION=utf8_general_ci \
-DEFAULT_CHARSET=utf8 \
-DENABLED_ASSEMBLER:BOOL=ON \
-DENABLED_LOCAL_INFILE:BOOL=ON \
-DENABLED_THREAD_SAFE_CLIENT:BOOL=ON \
-DENABLED_EMBEDDED_SERVER:BOOL=OFF \
-DWITH_CLIENT_LDFLAGS:STRING=all-static \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DCOMMUNITY_BUILD:BOOL=ON \
-DCMAKE_EXE_LINKER_FLAGS="-ltcmalloc" \
-DWITH_SAFEMALLOC=OFF \
-DWITH_BOOST=/usr/local/boost_1_59_0
make -j $CPUcount
make install
# 配置percona-server
mkdir -p /data/database/mysql
chown mysql:mysql -R /data/database/mysql
cd /usr/local/mysql
ln -sv /data/database/mysql /usr/local/mysql/var
sed -i '/Initialize script globals/ a export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' bin/mysqld_safe #让MySQL支持tcmalloc
# 配置文件
[ -f "/etc/my.cnf" ] && mv /etc/my.cnf /etc/my.cnf.old
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 16M
max_heap_table_size = 16M
table_open_cache = 2048
sort_buffer_size = 8M
net_buffer_length = 8K
read_buffer_size = 8M
read_rnd_buffer_size = 16M
myisam_sort_buffer_size = 16M
back_log = 200
skip-name-resolve
query_cache_size = 16M
join_buffer_size=8M
bulk_insert_buffer_size=16M
concurrent_insert=2
delay_key_write=ON
delayed_insert_limit=4000
delayed_insert_timeout=600
delayed_queue_size=4000
tmp_table_size = 16M
thread_cache_size=120
character-set-server=utf8
max_connections = 1024
log_output=FILE
slow_query_log=1
slow_query_log_file=/usr/local/mysql/var/slowquery.log
max_slowlog_size=10m
max_slowlog_files=20
long_query_time=1
wait_timeout=1814400
server-id=1
log-bin=mysql-bin
expire_logs_days=3
binlog_format=mixed
max-binlog-size=128M
binlog_cache_size = 4M
skip-slave-start=1
innodb_file_format=barracuda
innodb_strict_mode=1
binlog_direct_non_transactional_updates=1
innodb_data_home_dir = /usr/local/mysql/var/
innodb_data_file_path = ibdata1:200M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var/
innodb_file_per_table= 1
innodb_buffer_pool_size = 128M
innodb_log_file_size = 256M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 20
innodb_adaptive_flushing = 1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = 'O_DIRECT'
transaction-isolation=READ-COMMITTED
innodb_rollback_on_timeout = On
innodb_read_io_threads = 5
innodb_write_io_threads = 5
innodb_io_capacity=500
innodb_thread_concurrency = 8
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_fast_shutdown = 1
innodb_status_file=1
open-files-limit = 10240
memlock
datadir = /data/database/mysql/
tmpdir = /data/database/mysql/
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
# 初始化数据库,初始化过程中会产生初始化密码
result=`/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/var/ --user=mysql 2>&1`
[ "$?" -eq 0 ] || (echo -e "\033[31m Initialize MySQL error,check it. \033[0m" ; exit 1)
initpwd=`echo "$result" | awk '/A temporary password is generated for root@localhost:/{print $NF}'`
#启动数据库
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
# 修改root用户初始化密码
newpwd=`head /dev/urandom | md5sum | head -c16`
/usr/local/mysql/bin/mysqladmin -uroot -p"$initpwd" password "$newpwd"
mkdir -p /data/save && chmod 700 /data/save
echo -n "$newpwd" > /data/save/mysql_root && chmod 600 /data/save/mysql_root
cat > /root/mysql3306_start << EOF
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
EOF
cat > /root/mysql3306_stop << EOF
/usr/local/mysql/bin/mysqladmin -uroot -p`cat /data/save/mysql_root` "shutdown"
EOF
chmod +x /root/mysql3306_st*
inst_for_mysql5.7.sh的更多相关文章
- 数据库备份并分离日志表(按月)sh 脚本
#!/bin/sh year=`date +%Y` month=`date +%m` day=`date +%d` hour=`date +%H` dir="/data/dbbackup/f ...
- Linux下如何查找.sh后缀的文件
find / -name *.sh或locate *.shfind 与locate的区别:locate 配合数据库查看文件位置 find 实际搜寻硬盘查询文件名称
- sh 测试网段在线主机
yum install nmap nmap -sP 192.168.21.1/24 查看网段在线主机 grep -vwf file1 file2 文件内容比较 #!/bin/bash # day=` ...
- Maven打包生成可运行bat/sh脚本文件
利用Maven的appassembler-maven-plugin插件,就可以实现自动打包可运行的脚本,还可以跨平台. <plugin> <groupId>org ...
- 记一个简单的保护if 的sh脚本
真是坑爹,就下面的sh,竟然也写了很久! if [ `pwd` != '/usr/xx/bin/tomcat' ] then echo "rstall is not allowed in c ...
- 主机巡检脚本:OSWatcher.sh
主机巡检脚本:OSWatcher.sh 2016-09-26更新,目前该脚本只支持Linux操作系统,后续有需求可以继续完善. 注意: 经测试,普通用户执行脚本可以顺利执行前9项检查: 第10项,普通 ...
- Oracle巡检脚本:ORAWatcher.sh
Oracle巡检脚本:ORAWatcher.sh #!/usr/bin/ksh echo "" echo "ORAWatcher Version:1.0.1" ...
- 解决:/bin/sh: 1: /home/**/custom_app.sh: Permission denied错误
出现如下错误,一般是执行权限不够. /bin/sh: : /home/custom_app.sh: Permission denied 解决方法是:cd 到此文件目录,对提示的文件赋予可执行权限或读写 ...
- SH Script Grammar
http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...
随机推荐
- nginx 多级反向代理获取客户端真实IP
set_real_ip_from ; set_real_ip_from ; set_real_ip_from ; set_real_ip_from ; set_real_ip_from 127.0.0 ...
- 加载更多的ajax 字符串拼接
https://www.cnblogs.com/52fhy/p/5405541.html
- [LeetCode] 441. Arranging Coins_Easy tag: Math
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- JS--理解call、apply和bind
call.apply和bind call,apply是Function原型中的方法,它们的作用一样,区别在于传入参数的方式不同. call(thisArg, arg1, arg2...) 传入的参数不 ...
- java面试中经常会被问到分布式面试题
1.Dubbo的底层实现原理和机制 –高性能和透明化的RPC远程服务调用方案 –SOA服务治理方案 Dubbo缺省协议采用单一长连接和NIO异步通讯, 适合于小数据量大并发的服务调用,以及服务消费者机 ...
- python filter函数应用,过滤字符串
>>> candidate = 'dade142.;!0142f[.,]ad' >>> filter(str.isdigit, candidate) #保留数字 ' ...
- Cocos Code IDE (下载地址)
Cocos Code IDE 1.2.0 下载地址 Cocos Code IDE 1.2.0 Win32 下载地址: http://www.cocos2d-x.org/filedown/c ...
- php 下载完成后删除文件
最近遇到一个需求:下载用户上传的图片,但是图片不断更新. 1.需要将图片从图片服务器下载到网站后台服务器 2.压缩文件夹生成zip压缩包 3.下载压缩包 4.删除压缩包和临时文件夹 其中遇到了一个问题 ...
- 新节点在线加入PXC
环境 192.168.139.151 新增节点 192.168.139.148-150 集群节点 192.168.139.151 已经安装好PXC软件 计划: 选用192.168.139.150 节点 ...
- HTML-CSS线性渐变
实现背景的渐变可以通过为背景添加颜色渐变的图片,也可以使用浏览器的功能来为背景添加渐变的颜色 在IE6或IE7浏览器下可以使用一下示例的CSS语句,设置filter属性来实现颜色 filter:pro ...