mkdir -p /mnt/cdrom
vi /etc/fstab
/dev/cdrom /mnt/cdrom iso9660 auto,ro 0 0 (开机自动挂载)
mount -a(只要报错,千万不要重启)
cd /etc/yum.repos.d/
rm -rf *
touch centos.repo
vi centos.repo
[local]
name=cdrom
baseurl=file:///mnt/cdrom
gpgcheck=0
enable=1
yum clean all
yum makecache
常用命令
wc -l (c:count-l:line)
ls /var/log/ | grep -l
rm -rf /var/log (r递归的意思f:文件)
find / -name *.log
mv
top
sha1sum
renice -n 10 pid
nice -n 10 sha1sum /dev/zero
ps -o pid,pcpu,nice,comm --sort=-nice $(pgrep sha1sum)
free -h(内存空间,-h会以单位的形式来表示,如果G,M)
df -h(磁盘空间,-h会以单位的形式来表示,如果G,M)
uptime(查看系统负载)
who
w -h -u test1
last(查看最近登录的用户信息)
last -n 10
ro:read-only
yum list at
yum list httpd(查看仓库里面有没有这个安装包)
yum info httpd(查看软件包的详细信息)
rpm -qi at (q:query i:install)
yum localinstall
yum groupinstall
rpm -ivh net-tools*
find / -name test1.txt
find / -name *.txt
find / -name tes*.txt
find /home -type f | xagrs grep -n hello (-n: number查询的内容所处在文件的行号)
df --->du
df-->cd /mnt/cdrom-->du images/ -h(解决哪些目录使用率接近100%情况下会连环用该命令)
cat /etc/passwd | grep -n root
pwd(pwd这个命令,它的使用场景,比如你进入目录特别长,你记不住了,那么需要查看一下当前你正在工作的目录;还有一种,主要复制目录特别用。)
cat /var/log/message
more /var/log/message
less /var/log/message
head -n 10 message
tail -n 20 message
hostname client
usemod -d /tmp/test1 test1
cat /etc/passwd
useradd -d /tmp/test3 test3
useradd -G test test3 -M
userdel test2(不彻底的删除账号)
userdel -r test2(-r 彻底删除账号,包括目录)
passwd test2 或者 echo 123456 | passwd --stdin test2
echo $PATH
echo $HOME
echo "hello world" > test2.txt
export test=/home/lgb
export PATH=$PATH:/usr/local/mysql/bin
export -p
unset test
chkconfig --level 35 mysqld on (3代表多用户模式,说白了就是命令模式,文本模式;5代表图形化模式)
chkconfig --list
--level(0-6)
runlevel (看看系统运行级别)
getenforce(查看系统层面的安全,说白了也是系统上安装的各个应用程序对应的自身安全,如:httpd,ftp)
setenforce 0(关掉系统层面的安全)
重启系统:Init 6、关闭系统:init 0
service httpd start
service sshd start
netstat -anp | more
mount -t auto /dev/cdrom /mnt/cdrom
挂载U盘:
fdisk -l
mkdir -p /mnt/udisk
mount -t auto /dev/sdc4 /mnt/udisk
umount /mnt/udisk
看看路由:
ip route
tar zcvf (z:gz(zip),c:compress v:ver f:file)
yum install -y zip unzip
zip lgb.zip -r lgb
unzip test.zip -d /home
-------------------------------------
usermod -d /home/test1 test1
su - test1
touch hello.txt
find / -user test1 -type f -exec cp av {} /tmp/test \;
任务计划
yum install -y at cron
systemctl start atd
date >> /tmp/time.txt | at now +1min
crontab -e -u test1
*/2 * * * 1-5 date >> /tmp/time.txt
su - test1
crontab -l
crontab -r -u test1
nmcli配置网络
client:
nmc con add con-name "static" ifname eno16777736 type ethernet ip4 10.1.1.2/24 gw4 10.1.1.1
nmc con mod "static" ipv4.address 10.1.1.2/24 ipv4.gateway 10.1.1.1
server:
nmc con add con-name "static" ifname eno16777736 type ethernet ip4 10.1.1.3/24 gw4 10.1.1.1
nmc con mod "static" ipv4.address 10.1.1.3/24 ipv4.gateway 10.1.1.1
storage:
nmc con add con-name "static" ifname eno16777736 type ethernet ip4 10.1.1.4/24 gw4 10.1.1.1
nmc con mod "static" ipv4.address 10.1.1.4/24 ipv4.gateway 10.1.1.1
验证:
nmcli con show
nmcli con up static(只要网卡脚本发生更改,一定要使用这个命令)
dhcp \static \none
服务器端:
0、nmcli con add con-name server-eno33554960 ifname eno33554960 type ethernet ip4 10.1.1.2/24 gw4 10.1.1.254
1、yum install -y dhcp
2、find / -name dhcp*
3、cd /etc/dhcp
4、vi dhcpd.conf
subnet 10.1.1.0 netmask 255.255.255.0 {
range 10.1.1.1 10.1.1.10;
#option domain-name-servers ns1.internal.example.org;
#option domain-name "internal.example.org";
option routers 10.1.1.254;
option broadcast-address 10.1.1.255;
default-lease-time 600;
max-lease-time 7200;
}
5、systemctl restart dhcpd
6、ps axf | grep dhcpd
注释:如果地址配置错了,想重新修改,使用该命令:nmcli con mod server-eno33554960 ifname eno33554960 type ethernet ip4 10.1.1.2/24 gw4 10.1.1.254
学习:cat 文件名>> 文件名 (文件内容重定向)
显示:cat/echo
客户端:
cd /etc/sysconfig/network-scripts/
学习:(nmcli con show 查看
nmcli con down 下线原来的以太网
nmcli con add type ethernet ifname eno16777728 con-name dhcp
添加一个dhcp的以太网类型
nmcli con up dhcp上线)
vi ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=dhcp (此处修改为dhcp)
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno33554960
UUID=1e003d18-5f6e-44ba-ab3f-d4e71a346e48
DEVICE=eno33554960
ONBOOT=yes (此处修改为yes)
------------------------------------------
0、nmcli con show
1、nmcli con down static
2、nmcli con show
3、ip addr del 10.1.1.2/24 dev eno16777736
4、ip add
5、nmcli con up eno16777736
6、ip addr
7、nmcli con down eno16777736
8、nmcli con show
9、ip add
10、dhclient -r(释放IP地址)
注释:证明DNS是否正确获取和IP地址是否正确获取和默认网关是否正确获取
1、ip route del default via 10.1.1.3 dev eno16777736;ip route
2、>/etc/resolv.conf
3、nmc con down eno16777736;ip add;nmc con up eno16777736
11、[root@client network-scripts]# init 6
yum install mariadb-server
1、mount /dev/cdrom /mnt/cdrom
2、yum groupinstall mariadb mariadb-client -y
3、systemctl enable --now mariadb
4、ps axf
5、pgrep mysql
6、ps -ao pid,pcpu,nice,comm $(pgrep mysql)
7、renice -n -10 $(pgrep mysql)
8、mysql
9、show databases;
10、exit;
11、mysql_secure_installation (所有的都按y吧)
12、mysql(验证是否不通过密码登陆)
13、mysql -uroot -predhat
14、mysql -uroot -p(如果您不希望别人看到您输入的密码那么使用该命令)
15、show databases;(查看当前有哪些数据库)
16、create database inventory;
17、show databases;
18、use inventory;
19、show tables;
20、创建三个表(product,category,manufacturer)
create table product
(
id int(11) not null auto_increment,
name varchar(100) not null,
price double not null,
stock int(11) not null,
id_category int(11) not null,
id_manufacturer int(11),
primary key(id)
)charset=utf8;
create table category
(
id int(11) not null auto_increment,
name varchar(100) not null,
primary key(id)
)charset=utf8;
create table manufacturer
(
id int(11) not null auto_increment,
name varchar(100) not null,
seller varchar(100) not null,
phone_number varchar(100) not null,
primary key(id)
)charset=utf8;
21、分别在三个表中插入数据(product,category,manufacturer)
insert into product(name,price,stock,id_category,id_manufacturer) values("ThinkServer TS140",539.88,20,2,4);
insert into product(name,price,stock,id_category,id_manufacturer) values("ThinkServer TS440",1736.00,10,2,4);
insert into product(name,price,stock,id_category,id_manufacturer) values("RT-AC68U",219.99,10,1,3);
insert into product(name,price,stock,id_category,id_manufacturer) values("X110 64GB",73.84,100,3,1);
-------------------------------------------------------------------------------------------------------------------------
insert into category(name) values("Networking");
insert into category(name) values("Servers");
insert into category(name) values("Ssd");
------------------------------------------------------------------------------------------------------------------------
insert into manufacturer(name,seller,phone_number) values("SanDisk","John Miller","13688084569");
insert into manufacturer(name,seller,phone_number) values("Kingston","Mike Taylor","13688084598");
insert into manufacturer(name,seller,phone_number) values("Asus","Wilson Jckson","13699084598");
insert into manufacturer(name,seller,phone_number) values("Lenovo","Allen Scott","13699062598");
show tables;
select * from product;
select * from product limit 2;(限制查询的行数)
desc product;
update product set stock=30 where id=1;(更新某行数据的内容)
delete from product where id=4;(删除指定数据)
select name,price from product;(你想查询指定字段值)
select name,price from product where price>200;
select name,price from product where price<200;
select name,price from product where price=1736;
select name,price from product where price>=1736;
select * from product where name like 'Think'; (模糊查询)
select * from product where name like "%Think%"; (模糊查询)
select * from product where price in(1736,539.88,179);(查询某一列可能值)
select * from product where price >=200 and price <=500;(查找指定范围的内容)
select * from product limit 2 offset 1;
select * from product limit 2 offset 3;
select distinct * from product;
select distinct * from product where price<=100 or price <=300;
select distinct * from product order by price desc;
select distinct * from product order by price asc;
select HOST,User,Password from user;
create user lgb@10.1.1.1 identified by 'redhat';(创建一个远程登陆的用户)
select HOST,User,Password from user;(验证是否创建成功)
grant all privileges on *.* to 'lgb'@'%' identified by 'redhat' with grant option; (如果带with grant option,那么lgb这个账户也可以给其它账户授权)
show grants for lgb;
-------------------------------------------------------
备份数据库
1、mysqldump -uroot -predhat inventory > /tmp/inventory.sql
2、mysqldump -uroot -predhat --all-databases > /tmp/all-databases.sql
3、mysqladmin -uroot -predhat variables | grep datadir
4、show variables like "%data%"
5、show variables like "datadir";
6、cd /var/lib/mysql/
7、ls -al
--------------------------------------------------------------
恢复数据库
1、drop database inventory;
2、MariaDB [(none)]> create database inventory;
3、mysql -proot -predhat
4、exit
5、mysql -uroot -predhat inventory < /tmp/inventory.sql
6、mysql -proot -predhat
7、show databases;
8、use inventory;
9、show tables;
----------------------------------------------------------------------
客户端的操作:
mount /dev/cdrom /mnt/cdrom
,
yum groupinstall mariadb-client -y
mysql -ulgb -predhat -h 10.1.1.2
LAMP
http/https
html
php
静态的和动态的
本地文件,或者说某些文字使用数据库来存,比如MYSQL
LAMP:
L:linux;
A:apache
M:mariadb
P:php
yum install -y httpd
systemctl enable --now httpd
pgrep httpd
pgrep httpd | wc -l
http://10.1.1.2
8080/8081/
ps -ao user,group,pid,nice,comm $(pgrep httpd) (打印出我们的httpd所关联用户是否是主配置文件里面的定义的用户和组)
*.htaccess
*.htpasswd
ll | grep '^user'
mkdir -p /etc/httpd/conf.d/vhost
mkdir -p /var/www/html/{test1,test2}
cd /etc/httpd/conf.d/vhost
touch test1.conf
vi test1.conf
<VirtualHost *:9090>
DocumentRoot "/var/www/html/test1"
DirectoryIndex index.html
</VirtualHost>
<Directory "/var/www/html/test1">
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
touch test2.conf
vi test2.conf
<VirtualHost *:9091>
DocumentRoot "/var/www/html/test2"
DirectoryIndex index.html
</VirtualHost>
<Directory "/var/www/html/test2">
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
cd /var/www/html/test1
touch index.html
echo "hello world test1!" > index.html
cd /var/www/html/test2
touch index.html
echo "hello world test2!" > index.html
------------------------动态PHP网站开发----------------------------------------------------
mount /dev/cdrom /mnt/cdrom
yum install -y php
vi test1.conf
<VirtualHost *:9090>
DocumentRoot "/var/www/html/test1"
DirectoryIndex index.php
</VirtualHost>
<Directory "/var/www/html/test1">
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
touch test2.conf
vi test2.conf
<VirtualHost *:9091>
DocumentRoot "/var/www/html/test2"
DirectoryIndex index.php
</VirtualHost>
<Directory "/var/www/html/test2">
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
cd /var/www/html/test1
touch index.php
echo "hello world test1 php!" > index.php
cd /var/www/html/test2
touch index.php
echo "hello world test2 php!" > index.php
systemctl restart httpd
----------------------------------------
name=value
key=value
变量=值
---------------------------------------------------------------------
yum install php-mysql php-odbc
systemctl restart mariadb
systemctl restart httpd
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'redhat';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(!$conn )
{
die('连接失败: ' . mysqli_error($conn));
}
else
{
echo '连接成功<br />';
}
mysqli_query($conn , "set names utf8");
$sql = "select * from product";
mysqli_select_db( $conn, 'inventory' );
$retval = mysqli_query( $conn, $sql );
if(! $retval ) { die('查询失败: ' . mysqli_error($conn)); }
else
{
echo "数据查询成功\n";
}
while($row=mysqli_fetch_row($retval)){
echo "<br>";
echo "{id=$row[0],name=$row[1]}.<br>";
}
mysqli_close($conn);
?>