20181210 visualbox 安装 ubuntu 18.04 后续操作:设置ip、换源、安装LAMP、phpmyadmin
下载地址
http://releases.ubuntu.com/18.10/
找到 ubuntu-18.10-live-server-amd64.iso ,也就是下面的 连接地址
http://119.90.25.13/releases.ubuntu.com/18.10/ubuntu-18.10-live-server-amd64.iso
或者直接去掉前面的 ip (为什么会加上119.90.25.13 ?我也没有搞明白!)
http://releases.ubuntu.com/18.10/ubuntu-18.10-live-server-amd64.iso
官网太慢,改用 阿里云镜像
http://mirrors.aliyun.com/ubuntu-releases/18.10/ubuntu-18.10-live-server-amd64.iso
顺便纪录一下 16.04 的镜像
wget http://mirrors.aliyun.com/ubuntu-releases/16.04/ubuntu-16.04.5-server-amd64.iso
官网文档
https://help.ubuntu.com/lts/serverguide/serverguide.pdf
首先设置网络方式为 桥接
ip a
如果发现和物理机不在同一个网段,说明连接方式是 NAT
虚拟机菜单: Network —Network setting —Bridget adapter
再次 ip a
这次和物理机在同一个网段
然后就可以 ssh 操作了!
ssh dhbm@192.168.1.194
检查系统
uname -a
Linux ubuntu1804194 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/issue
Ubuntu 18.04.1 LTS \n \l
1、设置静态ip
cd /etc/netplan
ls
50-cloud-init.yaml
sudo sudo vim 50-cloud-init.yaml
*** 按照以下内容修改,注意 yaml 语法
network:
ethernets:
enp0s3:
addresses: [192.168.1.194/24]
gateway4:
192.168.1.1
dhcp4: false
nameservers:
addresses: [223.5.5.5,114.114.114.114]
version: 2
应用新网址
sudo netplan apply
再次确认
ip a
** 如果是本地操作,无需重新启动服务器
** 如果是 ssh 链接 ,最好重新连接新地址之后再继续
** 如果 dhcp4 : true ,可能会看到 新旧 2 个 ip都是有效的
2、 换国内源
备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
添加阿里源
sudo vim /etc/apt/sources.list
使用 vim 替换命令
:s/cn.archive.ubuntu.com/mirrors.aliyun.com/g
或者删除全部后(vim 删除全部命令 :%d),粘贴以下内容
#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
更新、升级
sudo apt update
sudo apt upgrade
顺便纪录一下 ubuntu 16.04 阿里云源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
3、安装 LAMP
安装 tasksel
sudo apt install tasksel
安装 lamp-server
sudo tasksel install lamp-server
测试结果:
curl 127.0.0.1
或者: 浏览器打开 192.168.1.194
4、中文乱码处理
sudo vim /etc/apache2/conf-available/charset.conf
把AddDefaultCharset UTF-8前面的#去掉
5、安装 phpadmin
sudo apt install phpmyadmin
设置 config
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
重启 apache
sudo systemctl reload apache2.
测试结果
http://192.168.1.194/phpmyadmin/index.php
这个时候,mysql 的 root 密码不知道是什么了!
重复一次,确认安装过成功没有 mysql 密码设置,只有一次 phpmyadmin 密码设置(干嘛用的?)
6、重设 mysql 初始密码
检查 mysql 是否安装运行
sudo netstat -tap | grep mysql
或者
sudo netstat -ano |grep 3306
查看版本
mysql --version
mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper
或者
mysql -V
参考
https://blog.csdn.net/ZT0518/article/details/82709573
https://blog.csdn.net/weixin_43217860/article/details/82735095
使用超级权限直接进入MySQL
sudo mysql
在 mysql 状态下
show database;
use mysql;
查询plugin字段值
select plugin from user where user = 'root';
返回结果:
+-------------+
| plugin |
+-------------+
| auth_socket |
+-------------+
1 row in set (0.00 sec)
更新 plugin 字段为 mysql 默认值
update user set plugin="mysql_native_password";
返回结果:
Query OK, 1 row affected (0.01 sec)
Rows matched: 5 Changed: 1 Warnings: 0
开始更改密码:
update user set authentication_string=password('123456') where user='root' and host='localhost';
返回结果:
Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 1
刷新权限:
flush privileges;
退出
quit
重启 mysql
sudo systemctl restart mysql.service
** 或者使用过去的方式
停止 mysql
sudo /etc/init.d/mysql stop
启动 mysql
sudo /etc/init.d/mysql start
测试 mysql
mysql -u root -p
123456
再次登陆 phpadmin 确认
http://192.168.1.195/phpmyadmin/index.php
7、 修改主机名称
ubuntu 18.04 不能直接修改/etc/hostname中主机名称,重启后又恢复到安装时设置的主机名称
sudo vim /etc/cloud/cloud.cfg
将 preserve_hostname: false
改为 preserve_hostname: ture
然后按照以前的方法修改 hostname
sudo vim /etc/hostname
ubuntu 18.04 的 hosts 中没有 127.0.0.1 对应主机名这一行了,也就不用修改了
现在只有以下这一行
127.0.0.1 localhost.localdomain localhost
修改完主机名,只能 reboot ,好像没有找到 systemctl 哪个命令可以直接生效
查看当前的主机名称 (3 种名称!不知道都有什么作用?)
8、使用 hostnamectl 修改主机名称
hostnamectl --static
hostnamectl --transient
hostnamectl --pretty
重设主机名称
sudo hostnamectl set-hostname ubuntu1804-76
sudo hostnamectl set-hostname ubuntu1804-76 --transient
sudo hostnamectl set-hostname ubuntu1804-76 --pretty
修改 hosts
vim /etc/hosts
# 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
# ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 ubuntu1804-76
::1 ubuntu1804-76
直接查看名称已经改变
sudo reboot 才能看到显示改变了?
疑问:127.0.0.1 localhost... 需要注释掉吗?会不会不认识 localhost?待处理
9 、 重设时区
安装的英文版,没有注意时区选择,时间总是相差 8 小时!在这里重设一下
记住命令 timedatectl 就可以了,help 一下就都找到了!
timedatectl --help
timedatectl list-timezones |grep Asia
找到 Asia/Shanghai
timedatectl set-timezone "Asia/Shanghai"
10、翻墙安装 IPFS (待处理)
首先 http://ping.chinaz.com/ 多个地址 ping 域名 dist.ipfs.io ,找到其中比较快的一个
修改之前
wget https://dist.ipfs.io/go-ipfs/v0.4.13/go-ipfs_v0.4.13_linux-amd64.tar.gz
返回结果:
--2018-12-12 06:10:51-- https://dist.ipfs.io/go-ipfs/v0.4.13/go-ipfs_v0.4.13_linux-amd64.tar.gz
Resolving dist.ipfs.io (dist.ipfs.io)... 31.13.66.23
Connecting to dist.ipfs.io (dist.ipfs.io)|31.13.66.23|:443... ^C
等不到结果直接 ctrl C 中断
sudo vim /etc/hosts 加入一行 域名映射到找到的这个 ip
# add by wzh 20181211 for IPFS
209.94.90.1 dist.ipfs.i
重启 apachect2
sudo systemctl restart apache2
修改之后
sudo wget https://dist.ipfs.io/go-ipfs/v0.4.13/go-ipfs_v0.4.13_linux-amd64.tar.gz
返回结果: (可以看到目标 ip 地址变化了)
2018-12-12 06:13:18-- https://dist.ipfs.io/go-ipfs/v0.4.13/go-ipfs_v0.4.13_linux-amd64.tar.gz
Resolving dist.ipfs.io (dist.ipfs.io)... 209.94.90.1
Connecting to dist.ipfs.io (dist.ipfs.io)|209.94.90.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12635297 (12M) [application/gzip]
Saving to: ‘go-ipfs_v0.4.13_linux-amd64.tar.gz’
.4.13_linux-amd64.t 55%[==========> ] 6.69M 21.1KB/s eta 4m 27s
ipfs init
返回结果:
initializing IPFS node at /home/dhbm/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmeTpmUPu6iFg2dxgJAhxTWfFYM1eS9otBrgmqwrEDRLr9
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
dhbm@dhbm1804:~/go-ipfs$ ipfs init
initializing IPFS node at /home/dhbm/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmX7i3TxTSwPeLLAzDJA34RnMP5fc7wKNMAz3ssrbzyKSs
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme