liunx deploy下的centos安装java与MySQL

liunx deploy下的centos安装java与MySQL

东拼西凑后各种文章的总结

一:禁用Yum插件

找到plugins这一行改为0即可

vi /etc/yum.conf

二:替换yum源

目录 -> /etc/yum.repos.d/CentOS-Base.repo
将下面的7.7.1908换成当前系统的版本号
适用于aarch64构架的阿里云镜像源配置文件
CentOS-Base.repo


[base]
name=CentOS-7.7.1908 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-altarch/7.7.1908/os/aarch64/
        http://mirrors.aliyuncs.com/centos-altarch/7.7.1908/os/aarch64/
        http://mirrors.cloud.aliyuncs.com/centos-altarch/7.7.1908/os/aarch64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-7.7.1908 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-altarch/7.7.1908/updates/aarch64/
        http://mirrors.aliyuncs.com/centos-altarch/7.7.1908/updates/aarch64/
        http://mirrors.cloud.aliyuncs.com/centos-altarch/7.7.1908/updates/aarch64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-7.7.1908 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-altarch/7.7.1908/extras/aarch64/
        http://mirrors.aliyuncs.com/centos-altarch/7.7.1908/extras/aarch64/
        http://mirrors.cloud.aliyuncs.com/centos-altarch/7.7.1908/extras/aarch64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7.7.1908 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-altarch/7.7.1908/centosplus/aarch64/
        http://mirrors.aliyuncs.com/centos-altarch/7.7.1908/centosplus/aarch64/
        http://mirrors.cloud.aliyuncs.com/centos-altarch/7.7.1908/centosplus/aarch64/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-7.7.1908 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-altarch/7.7.1908/contrib/aarch64/
        http://mirrors.aliyuncs.com/centos-altarch/7.7.1908/contrib/aarch64/
        http://mirrors.cloud.aliyuncs.com/centos-altarch/7.7.1908/contrib/aarch64/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-altarch/RPM-GPG-KEY-CentOS-7

更新下载新的rpm秘钥:下面的7.9.2009替换成自己的版本号
地址:https://mirrors.aliyun.com/centos-altarch/7.9.2009/os/aarch64/
下载 RPM-GPG-KEY-CentOS-7 与 RPM-GPG-KEY-CentOS-Testing-7
这个目录下替换 /etc/pki/rpm-gpg/
然后执行更新命令

yum makecache
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7-aarch64
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

三:添加环境变量

这里默认/usr/local/bin并不在系统变量中,我们需要在/etc/bashrc中添加之

echo export PATH=$PATH:/usr/local/bin >> /etc/bashrc

四:寻找systemctl的替代品

从代码中的github地址你可以发现怎么在chroot容器中实现systemctl类似的效果

wget https://github.com/smaknsk/servicectl/archive/1.0.tar.gz
tar -xf 1.0.tar.gz -C /usr/local/lib/
ln -s /usr/local/lib/servicectl-1.0/servicectl /usr/local/bin/servicectl
ln -s /usr/local/lib/servicectl-1.0/serviced /usr/local/bin/serviced

如何使用servicectl
sudo servicectl action service
‎此命令仅执行文件 /usr/lib/systemd/system/ s e r v i c e . s e r v i c e 中 的 {service}.service中的 service.service{action}, 如果通过的操作启用或禁用,则servicectl将在 ${service}.service上创建或删除symlink以供使用服务。‎

参数:
action - 可以是 {start, stop, restart, reload, enable, disable}
service -在/usr/lib/systemd/system/文件夹中的文件

serviced#
sudo serviced action
‎此命令执行 ${action} 为所有启用服务。‎

参数:
action -默认是start,也可以是: {start, stop, restart, reload, disable}

五:安装gcc

yum -y install gcc gcc-c++ kernel-devel

六:安装vim

yum install vim 

七:安装jdk8

手动下载arm架构的jdk 华为云地址 https://repo.huaweicloud.com/java/jdk/8u151-b12/
上传到 /usr/local/
目录解压:jdk后面的… 是你自己下的版本号

tar -zxvf jdk-...

顺手删掉jdk源码包

rm -f jdk-...

配置jdk环境变量

vim /etc/profile

按i进入编辑,在profile文件尾部添加如下内容

export JAVA_HOME=/usr/local/jdk...  #替换jdk安装目录
 
export JRE_HOME=${JAVA_HOME}/jre
 
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
 
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
 
export PATH=$PATH:${JAVA_PATH}

通过命令让profile文件立即生效

source /etc/profile

查看版本

java -version

八:安装mysql

1.添加mysql用户组和mysql用户

groupadd mysql     //创建mysql组
useradd -g mysql mysql //创建mysql用户添加到mysql组
usermod -a -G aid_inet,aid_net_raw mysql   //添加mysql在安卓中的网络访问权限

2.安装依赖库

yum install -y libaio*

3.下载解压arm结构的Mysql,主意解压命令只有xvf

wget https://obs.cn-north-4.myhuaweicloud.com/obs-mirror-ftp4/database/mysql-5.7.27-aarch64.tar.gz
tar xvf mysql-5.7.27-aarch64.tar.gz -C /usr/local/    

4.配置Mysql

mv /usr/local/mysql-5.7.27-aarch64 /usr/local/mysql
mkdir -p /usr/local/mysql/logs
chown -R mysql:mysql /usr/local/mysql 
ln -sf /usr/local/mysql/my.cnf /etc/my.cnf
cp -rf /usr/local/mysql/extra/lib* /usr/lib64/ 
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.old
ln -s /usr/lib64/libstdc++.so.6.0.24 /usr/lib64/libstdc++.so.6

5. 添加环境变量

vim /etc/profile

添加下面两行代码:

export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

使profile生效

source /etc/profile

6.mysql 初始化

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

7 mysql 启动(service mysqld start),关闭(service mysqld stop)

设置开机启动
可使用的指令 service mysqld {start|stop|restart|reload|force-reload|status}

cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
chmod +x /etc/init.d/mysqld
service mysqld start  #启动

9 安卓内核链接MySQL

usermod -aG aid_inet mysql

10 初始化密码等

mysql_secure_installation
Press y|Y for Yes, any other key for No: n //是否采用mysql密码安全检测插件(这里作为演示选择否,密码检查插件要求密码复杂程度高,大小写字母+数字+字符等)
Remove anonymous users? [Y/n] Y //是否删除匿名用户
Disallow root login remotely? [Y/n] n //是否禁止远程登录,这里设置还不算真管用
Remove test database and access to it? [Y/n] Y //删除测试数据库,并登录
Reload privilege tables now? [Y/n] Y //重新载入权限表

11 允许远程访问

mysql -u root -p  // 随后输入密码
mysql> use mysql;
Database changed
mysql> select 'host' from user where user='root';
+------+
| host |
+------+
| host |
+------+
1 row in set (0.00 sec)
 
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

九:安装docker:装了也运行不起来

想手机玩docker 看这里 https://blog.csdn.net/a8267587/article/details/121678730

yum install docker -y

直接等待安装成功,查看版本

docker --version

安装docker-compose
此时的列表里应该还可以找到docker-compose.aarch64的包,建议也安装

yum list docker-compose
yum install docker-compose -y

你可能感兴趣的:(linux,centos,java,mysql)