ubuntu18.04操作记录

一、解禁Ubuntu系统默认禁止root用户ssh登录
"PermitRootLogin” 设置是否允许root通过ssh登录。实际生产环境里是设成 “no”

#修改sshd服务配置文件
vim   /etc/ssh/sshd_config

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

重启服务

service  sshd  restart   
#或者  
systemctl   restart  sshd 

二、配置静态ip地址
打开配置文件

root@ubuntu:~# vim /etc/netplan/00-installer-config.yaml

编辑

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.0.79/24
      gateway4: 192.168.0.1
      nameservers:
        addresses:
        - 223.5.5.5
        - 223.6.6.6
  version: 2

保存

三、开放root登入,修改用户名密码
https://www.cnblogs.com/leisurelylicht/p/ubuntu1804-xiu-gai-yong-hu-ming-mi-ma.html

四、ubuntu挂载新硬盘
1.查看linux挂载系统文件类型:df -T -h
2.显示硬盘所属分区情况:sudo fdisk -l

root@ubuntu:/# fdisk -l
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E95CD27D-5853-4DA8-982B-DD2D59323625

Device       Start       End   Sectors Size Type
/dev/sda1     2048      4095      2048   1M BIOS boot
/dev/sda2     4096   2101247   2097152   1G Linux filesystem
/dev/sda3  2101248 209713151 207611904  99G Linux filesystem

Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 49.5 GiB, 53150220288 bytes, 103809024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

可以看到Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors为新加入的磁盘
3.对挂载的磁盘进行分区:sudo fdisk /dev/sdb

root@ubuntu:/# fdisk /dev/sdb 

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1a9d1b7b.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Extended' and of size 20 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1a9d1b7b

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 41943039 41940992  20G  5 Extended

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@ubuntu:/# 

4.输入m显示提示信息
5.输入n添加一个新的分区
6.输入e指定为扩展分区
7.输入1指定扩展磁盘只分一个区
8.输入p显示分区表
9.输入w保存分区表
10.再次输入fdisk -l可以看到系统已经识别了

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 41943039 41940992  20G  5 Extended

11.格式化硬盘,-t ext4 表示将分区格式化成ext4文件系统类型(ubuntu文件系统一般为ext4)

root@ubuntu:/# sudo mkfs -t ext4 /dev/sdb
mke2fs 1.44.1 (24-Mar-2018)
Found a dos partition table in /dev/sdb
Proceed anyway? (y,N) y
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: b4c02849-c773-4d26-a713-f88c89e609e5
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

12.挂载新加入的硬盘
首先在根目录下(/)新建一个挂载点文件夹(这个文件夹可以在任何地方)
挂载到新建的挂载点/homedata
sudo mount -t ext4 /dev/sdb /homedata
13.再次输入df -h可以看到新加入的磁盘

root@ubuntu:/# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               1.9G     0  1.9G   0% /dev
tmpfs                              393M  1.2M  391M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   49G  6.8G   40G  15% /
tmpfs                              2.0G     0  2.0G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda2                          976M  149M  761M  17% /boot
tmpfs                              393M     0  393M   0% /run/user/0
/dev/sdb                            20G   45M   19G   1% /homedata

14.配置硬盘在系统启动自动挂载。在文件 /etc/fstab 中加入如下配置,保存,完成

/dev/sdb        /homedata  ext4 defaults         0 0

应用安装
1.安装mysql
https://blog.csdn.net/qq_41375318/article/details/115693362

2.由于ubuntu特性,我们一般为/home单独挂载一块磁盘,这里设置mysql更换数据存储路径
配置生效文件路径:/etc/mysql/my.cnf
数据默认安装路径:/var/lib/mysql
操作:
停止数据库运行:sudo service mysql stop
带权限递归赋值:sudo cp -arp /var/lib/mysql /home/data/mysql
修改配置文件my.cnf中默认的数据存储路径
修改安全机制:

sudo vim /etc/apparmor.d/usr.sbin.mysqld

# Allow data dir access
#  /var/lib/mysql/ r,
#  /var/lib/mysql/** rwk,
  /home/data/mysql/ r,
  /home/data/mysql/** rwk,

重启安全机制:sudo service apparmor restart
使用/etc/mysql/debian.cnf中的用户名和密码登入mysql
后续可以重置root用户密码:https://blog.csdn.net/qq_41375318/article/details/115693362

use mysql;
  desc user;
  update mysql.user set authentication_string=password('root') where user='root' and Host='localhost'; 
  update user set  plugin='mysql_native_password' where user='root' and Host='localhost'; 
  flush privileges;

目录切换参考:https://www.cnblogs.com/0xcafebabe/p/6087139.html

附录:
ubuntu下mysql迁移数据文件
https://www.cnblogs.com/0xcafebabe/p/6087139.html
ubuntu下安装mysql
https://blog.csdn.net/qq_41375318/article/details/115693362
ubuntu下彻底删除mysql
https://blog.csdn.net/iehadoop/article/details/82961264
Ubuntu系统挂载新硬盘
https://blog.csdn.net/mier9042/article/details/105855755
https://blog.51cto.com/u_12348890/2092339

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值