页面“基于Docker的Jenkins持续集成”与“Mysql5.5 install”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
(Evan移动页面Mysql5.5installMysql5.5 install
 
第1行: 第1行:
=ins=
+
=binary install=
 
<pre>
 
<pre>
 +
#!/bin/bash
 +
# Author:  linuxsa.org
 +
# BLOG:
  
  
NOTE 注意  国内环境安装完 记得 Jenkins安装插件提速
+
mysql_install_dir=/home/apps/mysql
mkdir docker4jenkins
+
mysql_data_dir=/home/apps/mysql/data
cd docker4jenkins
+
Mem=`free -m | awk '/Mem:/{print $2}'`
#mkdir -p /data/jenkins
 
  
 +
Install_MySQL55() {
 +
  #pushd ${oneinstack_dir}/src > /dev/null
 +
  #id -u mysql >/dev/null 2>&1
 +
  [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
  
 +
  [ ! -d "${mysql_install_dir}" ] && mkdir -p ${mysql_install_dir}
 +
 
  
vi docker-compose.yml
+
   #if [ "${dbinstallmethod}" == "1" ]; then
 
+
     #tar xzf mysql-${mysql55_ver}-linux-glibc2.12-${SYS_BIT_b}.tar.gz
services:
+
tar xvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
   jenkins:
 
     #image: jenkins/jenkins:lts
 
    image: jenkins/jenkins:2.235.5-lts-alpine
 
    ports:
 
    - 7099:8080/tcp
 
    - 50000:50000/tcp
 
    environment:
 
      TZ: Asia/Shanghai
 
    restart: always
 
    volumes:
 
    #- /data/jenkins:/var/jenkins_home:rw
 
    - jenkins_home:/var/jenkins_home:rw
 
version: '3.0'
 
volumes:
 
  jenkins_home:
 
    driver: local
 
   
 
   
 
    #run
 
  docker-compose  up -d  jenkins
 
   
 
   
 
密码就查看logs
 
 
 
f47e158768be4c2ba0c891396cf5a55f
 
jenkins_1  |
 
jenkins_1  | This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
 
jenkins_1  |
 
   
 
   
 
docker run --name=jenkins -it -u root -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home 3f08dc4f3f5d
 
 
 
 
 
docker-compose up  -d
 
 
 
 
 
 
 
cat initialAdminPassword
 
05765dd93d604cd094b516ba9cc06c1a
 
 
 
重装要删除volumes  然后要重启 docker
 
/home/data/docker/volumes/docker4jenkins_jenkins_home/
 
 
 
如果默认 在这个目录
 
  /var/lib/docker/volumes
 
 
 
 
 
 
 
 
 
docker-compose up -d
 
ERROR: The Compose file './docker-compose.yml' is invalid because:
 
Unsupported config option for services.jenkins: 'name'
 
 
 
 
 
  
 +
    #mv mysql-${mysql55_ver}-linux-glibc2.12-${SYS_BIT_b}/* ${mysql_install_dir}
 +
mv  mysql-5.5.62-linux-glibc2.12-x86_64/*  ${mysql_install_dir}
 +
 +
mkdir -p ${mysql_data_dir};chown mysql.mysql -R ${mysql_data_dir}
 +
 +
#这个没执行
 +
    #sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' ${mysql_install_dir}/bin/mysqld_safe
 +
    sed -i "s@/usr/local/mysql@${mysql_install_dir}@g" ${mysql_install_dir}/bin/mysqld_safe
 +
  
 +
#这个是源码的 跳过
 +
  elif [ "${dbinstallmethod}" == "2" ]; then
 +
    tar xzf mysql-${mysql55_ver}.tar.gz
 +
    pushd mysql-${mysql55_ver}
 +
    [ "${armplatform}" == "y" ] && patch -p1 < ../mysql-5.5-fix-arm-client_plugin.patch
 +
    cmake . -DCMAKE_INSTALL_PREFIX=${mysql_install_dir} \
 +
    -DMYSQL_DATADIR=${mysql_data_dir} \
 +
    -DSYSCONFDIR=/etc \
 +
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 +
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
 +
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
 +
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 +
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
 +
    -DWITH_READLINE=1 \
 +
    -DWITH_EMBEDDED_SERVER=1 \
 +
    -DENABLE_DTRACE=0 \
 +
    -DENABLED_LOCAL_INFILE=1 \
 +
    -DDEFAULT_CHARSET=utf8mb4 \
 +
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
 +
    -DEXTRA_CHARSETS=all \
 +
    -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
 +
    make -j ${THREAD}
 +
    make install
 +
    popd
 +
  fi
  
 +
#这个if 不成理
 +
  if [ -d "${mysql_install_dir}/support-files" ]; then
 +
    #sed -i "s+^dbrootpwd.*+dbrootpwd='${dbrootpwd}'+" ../options.conf
 +
    echo "${CSUCCESS}MySQL installed successfully! ${CEND}"
 +
    if [ "${dbinstallmethod}" == "1" ]; then
 +
      rm -rf mysql-${mysql55_ver}-*-${SYS_BIT_b}
 +
    elif [ "${dbinstallmethod}" == "2" ]; then
 +
      rm -rf mysql-${mysql55_ver}
 +
    fi
 +
 +
  else
 +
  # rm -rf ${mysql_install_dir}
 +
    #echo "${CFAILURE}MySQL install failed, Please contact the author! ${CEND}"
 +
    kill -9 $$
 +
  fi
  
 +
  /bin/cp ${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
 +
  chmod +x /etc/init.d/mysqld
 +
  [ "${PM}" == 'yum' ] && { chkconfig --add mysqld; chkconfig mysqld on; }
 +
  [ "${PM}" == 'apt-get' ] && update-rc.d mysqld defaults
 +
  popd
  
不用  volumes 会报错
+
  # my.cnf
[root@prod-cailuw-marke-lvs02 docker4jenkins]# docker logs  7444b6cf02a2
+
  cat > /etc/my.cnf << EOF
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
+
[client]
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
+
port = 3306
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
+
socket = /tmp/mysql.sock
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
 
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
 
  
居然再来一次  没有初始化界面 ?
+
[mysql]
 +
prompt="MySQL [\\d]> "
 +
no-auto-rehash
  
firewall-cmd --permanent --add-port=7099/tcp
+
[mysqld]
firewall-cmd --reload 
+
port = 3306
 +
socket = /tmp/mysql.sock
  
还是不通  只能作域名了喽  hostname
+
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
  
</pre>
+
skip-name-resolve
 +
#skip-networking
 +
back_log = 300
  
= 常用命令=
+
max_connections = 1000
重启
+
max_connect_errors = 6000
http://localhost:8080/restart  http://localhost:8080/reload
+
open_files_limit = 65535
=install plugins=
+
table_open_cache = 128
==maven==
+
max_allowed_packet = 500M
 +
binlog_cache_size = 1M
 +
max_heap_table_size = 8M
 +
tmp_table_size = 16M
  
=== ins maven===
+
read_buffer_size = 2M
因为jenkins本身不带maven插件,所以需要自己安装下,由于我们的虚拟机中是没有直接安装maven软件的,我们可以在全局工具配置中安装maven, 选择一个合适的版本,勾选自动安装,之后直接保存,需注意的是,现在jenkins并不会立即给你安装maven软件
+
read_rnd_buffer_size = 8M
 +
sort_buffer_size = 8M
 +
join_buffer_size = 8M
 +
key_buffer_size = 4M
  
这是要做的动作 note
+
thread_cache_size = 8
接下来我们在插件管理中查找maven插件,我们选择好Maven Integration plugin插件,然后点击直接安装
 
  
===配置maven===
+
query_cache_type = 1
大家都知道我们要从maven库下载代码需要配置setting.xml,用jenkins时也需要把setting.xml配置好。在目录/docker/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf下修改setting.xml文件
+
query_cache_size = 8M
 +
query_cache_limit = 2M
  
 +
ft_min_word_len = 4
  
新建  就可以看到 列表 有 构建一个maven 项目  安装成功
+
log_bin = mysql-bin
 +
binlog_format = mixed
 +
expire_logs_days = 7
  
====maven 配置文件  ====
+
log_error = ${mysql_data_dir}/mysql-error.log
<pre>maven 配置  可以在母机修改
+
slow_query_log = 1
 +
long_query_time = 1
 +
slow_query_log_file = ${mysql_data_dir}/mysql-slow.log
  
/docker/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf下修改setting.xml文件。
+
performance_schema = 0
母机可能的目录
 
/home/data/docker/volumes/docker4jenkins_jenkins_home/_data/tools/hudson.tasks.Maven_MavenInstallation/maven3.6.2/conf</pre>
 
  
==JDK==
+
#lower_case_table_names = 1
<pre>
 
1.JDK和JRE的区别
 
JRE: Java Runtime Environment
 
JDK:Java Development Kit
 
  
JRE顾名思义是java运行时环境,包含了java虚拟机,java基础类库。是使用java语言编写的程序运行所需要的软件环境,是提供给想运行java程序的用户使用的。
+
skip-external-locking
JDK顾名思义是java开发工具包,是程序员使用java语言编写java程序所需的开发工具包,是提供给程序员使用的。JDK包含了JRE,同时还包含了编译java源码的编译器javac,还包含了很多java程序调试和分析的工具:jconsole,jvisualvm等工具软件,还包含了java程序编写所需的文档和demo例子程序。
 
如果你需要运行java程序,只需安装JRE就可以了。如果你需要编写java程序,需要安装JDK。
 
  
Jenkins-->
+
default_storage_engine = InnoDB
Update Center-->
+
innodb_file_per_table = 1
安装/更新 插件中 ->
+
innodb_open_files = 500
Oracle Java SE Development Kit Installer
+
innodb_buffer_pool_size = 64M
可见 oracle jdk安装了
+
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
  
注意,自动安装jdk需要你填入oracle的账号密码,这样Jenkins才能自动帮你到oracle安装。如果没有oracle账号</pre>
+
bulk_insert_buffer_size = 8M
 +
myisam_sort_buffer_size = 8M
 +
myisam_max_sort_file_size = 10G
 +
myisam_repair_threads = 1
  
[https://blog.csdn.net/anning_88/article/details/50635940 jenkins配置多个JDK]
+
interactive_timeout = 28800
 +
wait_timeout = 28800
  
==ssh plgins==
+
[mysqldump]
<pre>
+
quick
--> Manager plugin ->  Publish Over SSH
+
max_allowed_packet = 500M
  
usage
+
[myisamchk]
 +
key_buffer_size = 8M
 +
sort_buffer_size = 8M
 +
read_buffer = 4M
 +
write_buffer = 4M
 +
EOF
  
全局配置 -》SSH Servers
+
  sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
Name 可以是别名  hostname 是ip
+
  if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
 +
    sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
 +
    sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
 +
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
 +
    sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
 +
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
 +
    sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
 +
    sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
 +
  elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
 +
    sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
 +
    sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
 +
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
 +
    sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
 +
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
 +
    sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
 +
    sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
 
 
ssh 那要添加你的pri key  远程服务器添加pubkey </pre>
+
  elif [ ${Mem} -gt 3500 ]; then
 
+
    sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
[https://tendcode.com/article/Publish-Over-SSH/ 【Jenkins 插件】使用 Publish Over SSH 远程传输文件和自动部署]
+
    sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
 
+
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
==dokcer 插件 ==
+
    sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
为了发布 docker
+
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
 
+
    sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
=生成SSHKey=
+
    sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
 +
  fi
  
<pre>先进入容器
+
  ${mysql_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${mysql_install_dir} --datadir=${mysql_data_dir}
  
docker exec -it jenkins /bin/bash
+
echo 'export PATH=/home/apps/mysql/bin/:$PATH' >> /etc/profile && source /etc/profile
进入容器后生成sshkey
 
  
ssh-keygen -t dsa -C "123@qq.com"
+
  [ "${Wsl}" == true ] && chmod 600 /etc/my.cnf
 +
  chown mysql.mysql -R ${mysql_data_dir}
 +
  [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
 +
  service mysqld start
 +
  #[ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mysql_install_dir}/bin:\$PATH" >> /etc/profile
 +
  #[ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mysql_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${mysql_install_dir}/bin:\1@" /etc/profile
 +
  . /etc/profile
  
获取公钥
+
dbrootpwd=1234Kuycs886Q
1.进入容器 
 
2. 直接cat 一下 mount的目录  eg tail /var/lib/docker/volumes/jenkins/_data/.ssh/id_rsa.pub</pre>
 
  
=jenkins时区设置=
+
  ${mysql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${dbrootpwd}\" with grant option;"
<pre>
+
  ${mysql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${dbrootpwd}\" with grant option;"
 +
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='';"
 +
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
 +
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
 +
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
 +
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
 +
  rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
 +
  [ -e "${mysql_install_dir}/my.cnf" ] && rm -f ${mysql_install_dir}/my.cnf
 +
  echo "${mysql_install_dir}/lib" > /etc/ld.so.conf.d/z-mysql.conf
 +
  ldconfig
 +
  service mysqld stop
 +
}
  
【系统管理】-【脚本命令行】里运行
 
System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')
 
  
如果想永久 还是加在 yaml文件里
 
  
 +
##提示的
 +
/home/apps/mysql/bin/mysqladmin -u root password 'new-password'
 +
/home/apps/mysql/bin/mysqladmin -u root -h 10.3.10.139
 +
172.23.11.139 password 'new-password'
  
时间问题 以前思源的文档有
+
Alternatively you can run:
-v /etc/localtime:/etc/localtime 让容器使用和服务器同样的时间设置</pre>
+
/home/apps/mysql/bin/mysql_secure_installation
 
 
 
 
https://wiki.jenkins.io/display/JENKINS/Change+time+zone
 
 
 
=trouble =
 
 
 
第二天不能登录  这个是输入错了吧 
 
Invalid username or password
 
 
 
 
 
==Jenkins安装插件提速==
 
<pre>
 
 
 
docker-compose  exec  --user root  jenkins  bash
 
 
cd /var/jenkins_home/updates
 
 
sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json
 
 
 
sed -i 's#http://updates.jenkins-ci.org/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json
 
sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json
 
 
 
http://192.168.10.54:7099/restart
 
 
 
重试生效
 
  
 
</pre>
 
</pre>
https://blog.csdn.net/weixin_43557605/article/details/104587304
 
  
==Jenkins忘记密码 ==
 
<pre>
 
 
#note 这是基于docker的jenkins
 
jenkins@c58dc265c073:~/users$ pwd
 
/var/jenkins_home/users
 
 
cat users.xml
 
<entry>
 
      <string>lxtxadmin</string>
 
      <string>lxtxadmin_7295399102977240796</string>
 
 
cd  lxtxadmin_7295399102977240796/
 
 
  cat config.xml  | grep passwordHash
 
      <passwordHash>#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW</passwordHash>
 
 
 
sed  -i  's!#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW!#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS!' config.xml
 
 
后者是111111的hash值
 
 
docker-compose  restart
 
当然 最后记得要改回得比较强的密码喽
 
 
</pre>
 
 
[https://www.jianshu.com/p/e8bc90a1aad8 Jenkins - Jenkins 忘记密码]
 
 
==该Jenkins实例似乎已离线。 ==
 
<pre>
 
Jenkins 2.176.3
 
 
原因  近来网络管理又严格了
 
 
updates/default.json
 
 
jenkins在下载插件之前会先检查网络连接,其会读取这个文件中的网址。默认是:
 
访问谷歌
 
 
处理办法  改成可以直接访问的就行了
 
 
jenkins@jenkins-hellotest:~/updates$ pwd
 
/var/jenkins_home/updates
 
 
sed  -i 's/google/baidu/' default.json
 
 
</pre>
 
 
==打开主页空白==
 
<pre>打开 
 
http://192.168.10.214:7099/pluginManager/advanced
 
 
最后要恢复回来 ,不然打开主页空白呢
 
http://updates.jenkins.io/update-center.json
 
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
 
 
/pluginManager/advanced  改回原来的
 
http://updates.jenkins.io/update-center.json
 
 
 
</pre>
 
 
https://blog.csdn.net/harry5508/article/details/91958249
 
 
https://www.cnblogs.com/effortsing/p/10013412.html
 
 
https://blog.csdn.net/huoyunshen88/article/details/8509886
 
 
https://www.jianshu.com/p/1e411d225186
 
  
 
=see also=
 
=see also=
https://hub.docker.com/r/jenkins/jenkins
+
http://dev.mysql.com/doc/refman/5.5/en/installing.html
 
 
[https://www.cnblogs.com/xiaoqi/p/docker-jenkins-cicd.html Docker+Jenkins持续集成环境(1)使用Docker搭建Jenkins+Docker持续集成环境]
 
 
 
[http://dockone.io/article/2594 Jenkins与Docker的持续集成实践 ]
 
 
 
http://www.itmuch.com/work/jenkins-in-action/  
 
 
 
[https://blog.csdn.net/xxsstf/article/details/84991931  Jenkins使用, maven插件配置修改]
 
 
 
[https://www.jianshu.com/p/7883c251eb09 Jenkins+maven+docker 解决项目持续集成]
 
 
 
[https://www.jianshu.com/p/0391e225e4a6 Docker版本Jenkins的使用]
 
 
 
==learn==
 
[https://www.cnblogs.com/dzblog/category/945869.html Jenkins学习之路]
 
 
 
[[category:ops]]
 

2020年8月26日 (三) 10:10的版本

binary install

#!/bin/bash
# Author:  linuxsa.org
# BLOG: 


mysql_install_dir=/home/apps/mysql 
mysql_data_dir=/home/apps/mysql/data
Mem=`free -m | awk '/Mem:/{print $2}'`

Install_MySQL55() {
  #pushd ${oneinstack_dir}/src > /dev/null
  #id -u mysql >/dev/null 2>&1
  [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql

  [ ! -d "${mysql_install_dir}" ] && mkdir -p ${mysql_install_dir}
  

  #if [ "${dbinstallmethod}" == "1" ]; then
    #tar xzf mysql-${mysql55_ver}-linux-glibc2.12-${SYS_BIT_b}.tar.gz
	tar xvf  mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

    #mv mysql-${mysql55_ver}-linux-glibc2.12-${SYS_BIT_b}/* ${mysql_install_dir}
	mv  mysql-5.5.62-linux-glibc2.12-x86_64/*  ${mysql_install_dir}
	
	mkdir -p ${mysql_data_dir};chown mysql.mysql -R ${mysql_data_dir}
	
	#这个没执行
    #sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' ${mysql_install_dir}/bin/mysqld_safe 
    sed -i "s@/usr/local/mysql@${mysql_install_dir}@g" ${mysql_install_dir}/bin/mysqld_safe
	

#这个是源码的 跳过	
  elif [ "${dbinstallmethod}" == "2" ]; then
    tar xzf mysql-${mysql55_ver}.tar.gz
    pushd mysql-${mysql55_ver}
    [ "${armplatform}" == "y" ] && patch -p1 < ../mysql-5.5-fix-arm-client_plugin.patch
    cmake . -DCMAKE_INSTALL_PREFIX=${mysql_install_dir} \
    -DMYSQL_DATADIR=${mysql_data_dir} \
    -DSYSCONFDIR=/etc \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_READLINE=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DENABLE_DTRACE=0 \
    -DENABLED_LOCAL_INFILE=1 \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
    -DEXTRA_CHARSETS=all \
    -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
    make -j ${THREAD}
    make install
    popd
  fi

#这个if 不成理 
  if [ -d "${mysql_install_dir}/support-files" ]; then
    #sed -i "s+^dbrootpwd.*+dbrootpwd='${dbrootpwd}'+" ../options.conf
    echo "${CSUCCESS}MySQL installed successfully! ${CEND}"
    if [ "${dbinstallmethod}" == "1" ]; then
      rm -rf mysql-${mysql55_ver}-*-${SYS_BIT_b}
    elif [ "${dbinstallmethod}" == "2" ]; then
      rm -rf mysql-${mysql55_ver}
    fi
	
  else
   # rm -rf ${mysql_install_dir}
    #echo "${CFAILURE}MySQL install failed, Please contact the author! ${CEND}"
    kill -9 $$
  fi

  /bin/cp ${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
  chmod +x /etc/init.d/mysqld
  [ "${PM}" == 'yum' ] && { chkconfig --add mysqld; chkconfig mysqld on; }
  [ "${PM}" == 'apt-get' ] && update-rc.d mysqld defaults
  popd

  # my.cnf
  cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock

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

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

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

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

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7

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

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB
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

  sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
  if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
    sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
    sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
    sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
    sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
    sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
    sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
    sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
    sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
    sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
    sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
	
  elif [ ${Mem} -gt 3500 ]; then
    sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
    sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
    sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
    sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
    sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  fi

  ${mysql_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${mysql_install_dir} --datadir=${mysql_data_dir}

echo 'export PATH=/home/apps/mysql/bin/:$PATH' >> /etc/profile && source /etc/profile

  [ "${Wsl}" == true ] && chmod 600 /etc/my.cnf
  chown mysql.mysql -R ${mysql_data_dir}
  [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  service mysqld start
  #[ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mysql_install_dir}/bin:\$PATH" >> /etc/profile
  #[ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mysql_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${mysql_install_dir}/bin:\1@" /etc/profile
  . /etc/profile

dbrootpwd=1234Kuycs886Q

  ${mysql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${dbrootpwd}\" with grant option;"
  ${mysql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${dbrootpwd}\" with grant option;"
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='';"
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
  ${mysql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
  rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
  [ -e "${mysql_install_dir}/my.cnf" ] && rm -f ${mysql_install_dir}/my.cnf
  echo "${mysql_install_dir}/lib" > /etc/ld.so.conf.d/z-mysql.conf
  ldconfig
  service mysqld stop
}



##提示的
/home/apps/mysql/bin/mysqladmin -u root password 'new-password'
/home/apps/mysql/bin/mysqladmin -u root -h 10.3.10.139
172.23.11.139 password 'new-password'

Alternatively you can run:
/home/apps/mysql/bin/mysql_secure_installation


see also

http://dev.mysql.com/doc/refman/5.5/en/installing.html