目的(前言?)

2016年7月毕业到现在,特不顺利,总是半途而废,损失很多时间和金钱。清单数量上二百了,障碍了。(请原谅我写作水平,但我还在努力。)

书名:跟老男孩学Linux运维 Shell编程实战

1.书的难点

2.软件上解决的笔记

2-1.我的本本 我的台式 服务器所需的准备

VMware Workstations 15 Pro

难点:对vmware网络模式没弄懂。
想法:看下来自亦是美网络,桥接设置。
clipboard.png

clipboard.png

clipboard.png

远程工具:SecureCRT、Xshell、Putty(没用过)

SecureCRT设置

clipboard.png

clipboard.png

clipboard.png

clipboard.png

3.整理旧笔记

3-1.yum mysql

[20:10:58][root@#localhost ~]# rpm -qa|grep mariadb
[20:10:59]mariadb-libs-5.5.52-1.el7.x86_64 #查找,删掉
[20:11:07][root@#localhost ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[20:11:19][root@#localhost ~]# rpm -qa|grep mysql
[20:14:32][root@#localhost ~]# mkdir /data
[20:22:32][root@#localhost ~]# wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
[20:23:15][root@#localhost ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm 
[20:24:13][root@#localhost ~]# yum install mysql-server -y  
  
[20:29:12][root@#localhost ~]# cat /etc/my.cnf #默认
[20:29:12]# For advice on how to change settings please see
[20:29:12]# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[20:29:12]
[20:29:12][mysqld]
[20:29:12]#
[20:29:12]# Remove leading # and set to the amount of RAM for the most important data
[20:29:12]# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
[20:29:12]# innodb_buffer_pool_size = 128M
[20:29:12]#
[20:29:12]# Remove leading # to turn on a very important data integrity option: logging
[20:29:12]# changes to the binary log between backups.
[20:29:12]# log_bin
[20:29:12]#
[20:29:12]# Remove leading # to set options mainly useful for reporting servers.
[20:29:12]# The server defaults are faster for transactions and fast SELECTs.
[20:29:12]# Adjust sizes as needed, experiment to find the optimal values.
[20:29:12]# join_buffer_size = 128M
[20:29:12]# sort_buffer_size = 2M
[20:29:12]# read_rnd_buffer_size = 2M
[20:29:12]datadir=/var/lib/mysql
[20:29:12]socket=/var/lib/mysql/mysql.sock
[20:29:12]
[20:29:12]# Disabling symbolic-links is recommended to prevent assorted security risks
[20:29:12]symbolic-links=0
[20:29:12]
[20:29:12]log-error=/var/log/mysqld.log
[20:29:12]pid-file=/var/run/mysqld/mysqld.pid

[20:30:41][root@#localhost ~]# service mysqld status #记法:系统在前,服务在后。systemctl status xxx service xxx status

[20:30:52][root@#localhost ~]# service mysqld start
[20:31:23][root@#localhost ~]# grep "password" /var/log/mysqld.log
[20:31:23]2019-03-21T12:31:07.638261Z 1 [Note] A temporary password is generated for root@localhost: QChl.QsN9IrY
[20:31:40][root@#localhost ~]# mysql -uroot -p
[20:32:09]Enter password: 
[20:32:57]mysql> alter user 'root'@'localhost' identified by 'you_password'; #字母大小写,数字,符号都要!也可以设置取消复杂要求。
[20:33:13]mysql> quit;
[20:33:30][root@#localhost ~]# service mysqld restart
[20:33:58][root@#localhost ~]# mysql -uroot -p       
[20:34:04]Enter password: 
[20:34:04]Welcome to the MySQL monitor.  Commands end with ; or \g.
[20:34:04]Your MySQL connection id is 2
[20:34:04]Server version: 5.7.25 MySQL Community Server (GPL)
[20:34:04]
[20:34:04]Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
[20:34:04]
[20:34:04]Oracle is a registered trademark of Oracle Corporation and/or its
[20:34:04]affiliates. Other names may be trademarks of their respective
[20:34:04]owners.
[20:34:04]
[20:34:04]Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[20:34:04]
[20:34:12]mysql> show databases;
[20:34:12]+--------------------+
[20:34:12]| Database           |
[20:34:12]+--------------------+
[20:34:12]| information_schema |
[20:34:12]| mysql              |
[20:34:12]| performance_schema |
[20:34:12]| sys                |
[20:34:12]+--------------------+
[20:34:12]4 rows in set (0.00 sec)
[20:34:12]
[20:34:18]mysql> quit;
[20:34:18]Bye  #注意:上面标点符号不准,csdn保存后,符号有变化!!!

3-2.rm -rf /var/run/yum.pid

[15:04:08][root@localhost ~]# yum install gcc gcc-c++ kernel-devel ncurses-devel bison cmake
[15:04:08]Loaded plugins: fastestmirror, langpacks
[15:04:08]Existing lock /var/run/yum.pid: another copy is running as pid 4258.
[15:04:08]Another app is currently holding the yum lock; waiting for it to exit...
[15:04:08]  The other application is: PackageKit
[15:04:08]    Memory : 197 M RSS (1.5 GB VSZ)
[15:04:08]    Started: Thu Mar 21 14:54:14 2019 - 09:55 ago
[15:04:08]    State  : Sleeping, pid: 4258
[15:04:10]Another app is currently holding the yum lock; waiting for it to exit...
[15:04:10]  The other application is: PackageKit
[15:04:10]    Memory : 197 M RSS (1.5 GB VSZ)
[15:04:10]    Started: Thu Mar 21 14:54:14 2019 - 09:57 ago
[15:04:10]    State  : Sleeping, pid: 4258
[15:04:11]^C
[15:04:11]Exiting on user cancel.
[15:05:01][root@localhost ~]# rm -rf /var/run/yum.pid 
[15:05:02][root@localhost ~]# yum install gcc gcc-c++ kernel-devel ncurses-devel bison cmake

3-3.vim hostname

[10:50:49][root@localhost ~]# hostname
[10:50:49]localhost.localdomain
[10:50:57][root@localhost ~]# cat /etc/hostname
[10:50:57]localhost.localdomain
[10:51:13][root@localhost ~]# vi /etc/hostname
[10:51:52][root@localhost ~]# cat /etc/hostname
[10:51:52]localhost
[10:51:52][root@localhost ~]# reboot

疑问:
[root@bogon ~],这也许是默认,但装系统的时候,输入hostname后,结果还是bogon,一直计划再装一次,还是没装上,就是除了默认和不输入bogon,再试试。

3-4.selinux

[10:52:40][root@localhost ~]# vi /etc/selinux/config
[11:05:25][root@localhost ~]# cat /etc/selinux/config
[11:05:25]
[11:05:25]# This file controls the state of SELinux on the system.
[11:05:25]# SELINUX= can take one of these three values:
[11:05:25]#     enforcing - SELinux security policy is enforced. #安全策略被强制执行
[11:05:25]#     permissive - SELinux prints warnings instead of enforcing. #打印警告而不是强制执行
[11:05:25]#     disabled - No SELinux policy is loaded. #没有加载SELinux策略
[11:05:25]SELINUX=disabled
[11:05:25]# SELINUXTYPE= can take one of three two values:
[11:05:25]#     targeted - Targeted processes are protected, #有针对性的过程受到保护
[11:05:25]#     minimum - Modification of targeted policy. Only selected processes are protected.  #目标政策的最小修改。只有选定的进程受到保护。
[11:05:25]#     mls - Multi Level Security protection. #多级安全保护。
[11:05:25]SELINUXTYPE=targeted 
[11:05:25]
[10:54:03][root@localhost ~]# reboot
[11:06:54][root@localhost ~]# /usr/sbin/sestatus   # 或者 sestatus
[11:06:54]SELinux status:                 disabled
[11:07:01][root@localhost ~]# getenforce  #
[11:07:01]Disabled

[15:46:31][root@localhost ~]# setenforce 0 | 1 # 1:启用,Enforcing;0:关闭,Permissive。
[15:46:31]usage:  setenforce [ Enforcing | Permissive | 1 | 0 ] #

3-5.查看 CentOS 版本信息

[08:48:03][root@#localhost ~]# cat /etc/redhat-release 
[08:48:03]CentOS Linux release 7.3.1611 (Core) 

4.重置root密码

CentOS 7.X

查看Linux版本
[root@linuxprobe ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)

rd.break方式更改root密码

重启Linux系统主机并出现引导界面时,按下e键进入内核编辑界面。

输入rd.break,位置就在fi下面,Ctrl+X。约30秒后,进入紧急求援模式。

mount -o remount,rw /sysroot
chroot /sysroot
passwd  # passwd root
touch /.autorelabel
exit
reboot

init方式修改root密码

重启Linux系统主机并出现引导界面时,按下e键进入内核编辑界面。

输入init=/bin/sh,位置就在fi下面,Ctrl+X。

mount -o remount,rw /
passwd root
touch /.autorelabel
exec /sbin/init # exec/sbin/reboot
# exit ?
# reboot ?

CentOS 6.X

重启Linux系统主机并出现引导界面时,按下e键进入内核编辑界面。

选择kernel,再按e键。

quiet结尾添加一个1或者single并回车,然后按b键,进入单用户模式。

看到Telling INIT to go to single user mode.

passwd root
New password:
Retype new password:
reboot

Ubuntu
按e键,init=/bin/bash,位置就在fi下面。

Ctrl+X。

mount -o remount,rw /
passwd # passwd root
#修改root密码
exec /sbin/reboot

伪程序员宅
1 声望1 粉丝