https://www.jb51.net/article/217014.htm
基础
1)依赖库安装:
- libaio.so.1
https://blog.csdn.net/cycxl/article/details/134683513
apt-get install libaio1 libaio-dev
- error while loading shared libraries: libncurses.so.5: cannot open shared object file
找到libncurses.so.6库的位置,然后链接到libncurses.so.5
同理libtinfo.so.5也需要链接
2)文件权限:
-
Could not open file '/usr/local/mysql/log/mysqld.log' for error logging: Per
https://blog.csdn.net/wdyj517506/article/details/105273227
sudo chown -R mysql:mysql /usr/local/mysql
-
mysqld: File ‘./binlog.index‘ not found (OS errno 13 - Permission denied)
对datadir目录要赋予权限
https://blog.csdn.net/qq_27884227/article/details/132596525
3)配置文件:
https://www.cnblogs.com/syw20170419/p/16187519.html
https://blog.51cto.com/ludihua/1542612
- mysqld: [ERROR] Found option without preceding group in config file
https://blog.51cto.com/u_16213346/7196687
4)bin目录文件说明:
https://www.php.cn/faq/584217.html
5)其它bug:
- Failed to start mysql.service: Unit mysql.service is masked
https://linuxcpp.0voice.com/?id=111342
sudo systemctl unmask mysql.service
正式安装
https://blog.csdn.net/zhizhengguan/article/details/83342654 (x86平台)
https://blog.csdn.net/weixin_29665183/article/details/113137134 (下载方法和地址,但是没有找到linux aarch64包)
社区版本下载:https://downloads.mysql.com/archives/community/
- 安装脚本
大致步骤:
1)解压mysql包到/usr/local/mysql目录
2)赋予datadir权限
3)安装mysql相关程序启动的依赖库
4)初始化数据库,bin/mysqld --initialize --user=root,会在日志里生成初始化密码。
5)通过服务启动mysqld_safe,主要是为了启动mysqld
6)然后拿着初始化密码通过mysql程序修改密码为root
mysql.service
[Unit]
Description=mysql Service
[Service]
Type=simple
ExecStart=/bin/bash /usr/local/mysql/bin/mysqld_safe --user=root
Restart=on-failure
RestartSec=5s
PrivateTmp=false
KillMode=process
[Install]
WantedBy=multi-user.target
install.sh
#!/bin/bash
echo_m(){
echo "$(date +%F%T) $1"
}
if [ "$(whereis php)" = "php:" ]; then
echo_m "install php start"
apt-get install -y php=2:7.4+76
echo_m "install php success"
fi
if [ "$(whereis php-fpm)" = "php-fpm:" ]; then
echo_m "install php-fpm start"
apt-get install -y php-fpm=2:7.4+76
echo_m "install php-fpm success"
echo_m "replace www.conf listen port"
find /etc -type f -name www.conf | xargs sed -i "s/^listen = \S*/listen = 9000/"
echo_m "replace www.conf listen port success"
fi
if [ "$(whereis bmc_nginx)" = "bmc_nginx:" ]; then
echo_m "install bmc_nginx start"
cd /opt/tkroot/nginx
bash install.sh
echo_m "install bmc_nginx success"
fi
mysql_location="$(whereis mysql)"
if [[ "$mysql_location" = "mysql:*" || "$mysql_location" =~ "/etc/mysql" ]]; then
echo_m "install mysql start"
MYSQL_ROOT=/usr/local/mysql
cd /opt/tkroot/mysql
tar xvf mysql-5.7.27-aarch64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.27-aarch64 $MYSQL_ROOT
ln -sf $MYSQL_ROOT/my.cnf /etc/my.cnf
cp -rf $MYSQL_ROOT/extra/lib* /usr/lib64/
echo_m "install env libs"
apt-get install -y libaio1 libaio-dev
ln -s /usr/lib/aarch64-linux-gnu/libncurses.so.6 /usr/lib/aarch64-linux-gnu/libncurses.so.5
ln -s /usr/lib/aarch64-linux-gnu/libtinfo.so.6 /usr/lib/aarch64-linux-gnu/libtinfo.so.5
echo_m "install env libs end"
#my.cnf
sed -i "s/^user = \S*/user = root/" /etc/my.cnf
datadir=$(cat /etc/my.cnf | grep "datadir = " | awk '{print $3}')
echo "datadir:$datadir"
mkdir -p "$datadir"
chmod +777 "$datadir"
#init data
cd $MYSQL_ROOT
mkdir logs
chown -R root:root $MYSQL_ROOT
bin/mysqld --initialize --user=root
#create soft link for mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# start mysqld first before mysql start
TK_ROOT=/opt/tkroot
echo "cp ${TK_ROOT}/mysql/mysql.service /lib/systemd/system/"
cp -f "$TK_ROOT"/mysql/mysql.service /lib/systemd/system/
systemctl daemon-reload
systemctl start mysql
systemctl enable mysql
#find password
# shellcheck disable=SC2002
init_password=$(cat $MYSQL_ROOT/logs/mysql-error.log | grep "A temporary password is generated for root@localhost:\S*" | awk '{print $NF}')
echo_m "init_password:$init_password"
#set new password
# shellcheck disable=SC2016
#wait mysqld to start
mysqld_start_fail=$(ps -e | grep -w mysqld | grep -v grep)
if [[ $mysqld_start_fail = "" ]];then
mysqld_start_fail=1
else
mysqld_start_fail=0
fi
echo_m "mysqld_start_fail:$mysqld_start_fail"
while [ $mysqld_start_fail -eq 1 ]
do
echo_m "wait mysqld start ..."
sleep 1
mysqld_start_fail=$(ps -e | grep -w mysqld | grep -v grep)
if [[ $mysqld_start_fail = "" ]];then
mysqld_start_fail=1
else
mysqld_start_fail=0
fi
done
#wait mysqld ready
mysql_exec_result=$($MYSQL_ROOT/bin/mysql 2>&1)
echo "mysql_exec_result:$mysql_exec_result"
socket_fail_str="Can't connect to local MySQL server through socket"
if [[ ${mysql_exec_result} =~ ${socket_fail_str} ]];then
connect_fail=1
else
connect_fail=0
fi
echo_m "connect_fail:$connect_fail"
while [ $connect_fail -eq 1 ];
do
echo_m "wait mysqld prepared ..."
sleep 1
mysql_exec_result=$($MYSQL_ROOT/bin/mysql 2>&1)
echo "mysql_exec_result:$mysql_exec_result"
if [[ ${mysql_exec_result} =~ ${socket_fail_str} ]];then
connect_fail=1
else
connect_fail=0
fi
echo_m "connect_fail:$connect_fail"
done
# shellcheck disable=SC2016
$MYSQL_ROOT/bin/mysql -uroot -p"$init_password" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';"
# create and import db
$MYSQL_ROOT/bin/mysql -uroot -proot -e "CREATE DATABASE tiktok;"
$MYSQL_ROOT/bin/mysql -uroot -proot tiktok < /opt/tkroot/tkcloud/tk.sql
echo_m "install mysql success"
fi
if [ "$(whereis php-mysql)" = "php-mysql:" ]; then
echo_m "install php-mysql start"
apt-get install -y php-mysql=2:7.4+76
echo_m "install php-mysql success"
fi
if [ "$(whereis redis)" = "redis:" ]; then
echo_m "install redis start"
apt-get install -y redis=5:6.0.16-1+deb11u2
echo_m "install redis success"
fi
if [ "$(whereis php-redis)" = "php-redis:" ]; then
echo_m "install php-redis start"
apt-get install -y php-redis=5.3.2+4.3.0-2+deb11u1
echo_m "install php-redis success"
fi
# replace ./tkcloud/public/url.json ip
url_json_file=/opt/tkroot/tkcloud/public/url.json
# shellcheck disable=SC2002
local_host_str=$(cat $url_json_file | grep localhost)
echo "local_host_str:$local_host_str"
if [ $local_host_str != "" ]; then
ln -s /usr/sbin/ifconfig /usr/bin
localIP=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
echo "localIp:$localIP"
if [ -z $localIP ]; then
echo "local ip is empty,网络异常,/opt/tkroot/tkcloud/public/url.json replace fail"
exit 0
fi
sed -i "s/localhost/$localIP/" $url_json_file
fi
0 条评论