Ubuntu LXD下Centos7搭建OpenJDK8+MariaDB
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu LXD下Centos7搭建OpenJDK8+MariaDB相关的知识,希望对你有一定的参考价值。
# centos7
lxc launch images:centos/7/amd64 centos7
lxc exec centos7 -- /bin/bash
# 验证centos7版本
lxc exec centos7 -- cat /etc/redhat-release
# 显示网络配置
lxc exec centos7 -- ip addr
# 查看公网IP ifconfig.me网站可显示本机公网IP https://ip8.com/
curl ifconfig.me
# 网络路径追踪
tracepath www.baidu.com
# MariaDB (兼容MYSQL)前缀 lxc exec centos7 --
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
# 密码:123456
create user test IDENTIFIED by ‘123456‘;
grant select on testdb. to sytest;
grant show view on testdb. to test;
select host,user,password from user;
# 实现远程连接(改表法)
use mysql;
update user set host = ‘%‘ where user = ‘test‘;
# 修改root远程访问
GRANT ALL PRIVILEGES ON . TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
# 数据传输报Got a packet bigger than‘max_allowed_packet’bytes临时修改:
# 修改 #512M,在mysq下输入
set global max_allowed_packet=524288000;
# 刷新权限
flush privileges;
# 重新配置参照https://www.linuxidc.com/Linux/2016-03/128880.htm 和 服务器my.cnf
systemctl restart mariadb
# 安装 OpenJDK (WEB开发兼容Orcle JDK)前缀 lxc exec centos7 --
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
# 获取openjdk真实路径
dirname $(readlink $(readlink $(whereis java)))
# 配置java系统变量写入/etc/profile.d/java_env_export.sh
echo -e "
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
"
> /etc/profile.d/java_env_export.sh
# 应用系统变量
source /etc/profile.d/java_env_export.sh
# 永久打开,重启依然有效
vi /etc/sysctl.conf文件,将net.ipv4.ip_forward=1前面的#注释去掉,保存文件,然后执行sudo sysctl -p使其生效
# 在centos的之外的宿主操作系统临时保存端口转发,重启失效
sudo iptables -t nat -A PREROUTING -p tcp --dport 3306 -j DNAT --to 10.138.129.43:3306
sudo iptables -t nat -A PREROUTING -p tcp -s 192.168.188.0/24 --dport 80 -j DNAT --to 10.138.129.43:80
sudo iptables -t nat -A PREROUTING -p tcp -s 192.168.188.0/24 --dport 80 -j DNAT --to 10.138.129.43:80
# 保存当前iptables的所有规则
sudo iptables-save
# 共享主机用户目录
lxc config device add centos7 mntdir disk source=/home/ubuntu path=/mnt/outter
# 移除主机用户目录
lxc config device remove centos7 mntdir
# 查看容器配置
lxc config device show centos7
# 永久配置自脚本,无需登录,自建/etc/init.d/add-rules并在末尾添加,将/etc/init.d/add-rules链接加入到/etc/rcX.d/下,参考https://blog.csdn.net/apple_llb/article/details/50293179
echo 123456 | sudo -S iptables -t nat -A PREROUTING -p tcp --dport 80 -d 192.168.1.1/24 -j DNAT --to 10.0.3.26:80
echo 123456 | sudo -S iptables -t nat -A PREROUTING -p tcp --dport 3306 -d 192.168.1.1/24 -j DNAT --to 10.0.3.26:3306
以上是关于Ubuntu LXD下Centos7搭建OpenJDK8+MariaDB的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu 14.04 & ant: Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-7-openj