记录Linux中使用到的命令

后台启动

1
sh test.sh&

打zip包

1
zip -r -q -o Django.zip /home/project/Django

查看网络数据传输

1
tcpdump -i eth0 host 103.254.76.103 -vvv -A -x

关闭网卡

1
ifconfig [NIC_NAME] down

设置主机名

1
vi /etc/hostname

设置主机名与ip映射

1
vi /etc/hosts

W10: Warning: Changing a readonly file

出现原因:

  1. 文件被锁定;
  2. 当前角色只有读的权限;

解决办法:

1
chmod u+w 文件路径

无法创建目录:权限不够

1
sudo chown -R 用户名 路径

防火墙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

firewall-cmd --zone=public --add-port=9111/tcp --permanent

#重新载入

firewall-cmd --reload

#查看

firewall-cmd --zone=public --query-port=80/tcp

#删除

firewall-cmd --zone=public --remove-port=80/tcp --permanent

firewall-cmd --zone=public --list-ports

#关闭
systemctl stop firewalld.service

显示文件行数

1
set nu

查看端口信息

1
netstat -nltp

磁盘相关

1
2
3
4
5
#查看磁盘分区大小
df -h

#查看根目录下文件夹大小
cd / && du -h -x --max-depth=1

软件安装

1.telnet

1
2
3
4
5
6
7
8
//先检查rpm包是否安装
rpm -qa telnet-server
//安装telnet-server
yum install telnet-server
//检测telnet的rpm包是否安装
rpm -qa telnet
//安装telnet
yum install telnet

2.dos2unix

1
yum -y install dos2unix*

3.expect

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//先安装tcl
//下载tcl安装包,https://sourceforge.net/projects/tcl/files/Tcl/8.6.12/tcl8.6.12-src.tar.gz/download
tar -zxf tcl8.6.12-src.tar.gz
cd tcl8.6.12/unix/
./configure --prefix=/usr/tcl --enable-shared
make
make install

# 目录tcl8.6.12/unix/下的tclUnixPort.h复制到generic中
cp tclUnixPort.h ../generic/

# 授权允许普通用户使用
chmod 755 /usr/tcl/lib/expect5.45.4
chmod -R 755 /usr/tcl

//安装expect
//下载安装包:https://jaist.dl.sourceforge.net/project/expect/Expect/5.45.4/expect5.45.4.tar.gz

tar -zxf expect5.45.4.tar.gz
cd expect5.45.4
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.6.12/generic ##配置expect的安装路径,--with-tcl为告诉configure脚本tcl解释器位置,--with-tclinclude为告诉脚本tcl头文件位置
make
make install
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect

chmod -R 755 /usr/expect
chmod 755 /usr/expect/bin

//命令写入环境变量
vi /etc/profile
export PATH=$PATH:/usr/expect/bin/

source /etc/profile

//测试
输入expect命令,看是否进入形如expect1.1>这样的命令行

4.安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//查看是否已经安装 Mysql
rpm -qa | grep mysql
//如果安装过可以执行命令删除
rpm -e 文件名
//下载官方 Mysql 包
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
//安装包
yum -y install mysql57-community-release-el7-10.noarch.rpm
//安装MySQL
yum -y install mysql-community-server
//如果安装失败提示密钥国企可以执行下面命令
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
//启动服务
systemctl start mysqld.service
//查看 Mysql 运行状态
service mysqld status
//查看初始密码
grep ‘password’ /var/log/mysqld.log
//进入数据库
mysql -u root -p
//如果提示数据库无法访问,修改my.cnf
//修改之前先关闭mysql服务
service mysqld stop
//修改 vi /etc/my.cnf
//添加skip-grant-tables,这样mysql可以免密登录。
//重启服务
systemctl restart mysqld.service
//切换mysql数据库
show databases;
use mysql;
//重置密码root为root
update user set authentication_string=password("root") where user="root";
//删除skip-grant-tables
//重启服务

5.安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//1.安装依赖包
//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

//2.下载并解压安装包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz

//3.安装nginx
//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行命令 考虑到后续安装ssl证书 添加两个模块
./configure --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install

//4.配置nginx.conf
vi /usr/local/nginx/conf/nginx.conf

//5.启动服务
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

//6.重启nginx
/usr/local/nginx/sbin/nginx -s reload

6.Hadoop单机安装

1
2
3
4
mkdir input
cp etc/hadoop/*.xml input
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input output 'dfs[a-z.]+'
cat output/*

7.Hive安装

1
2
3
4
5
6
7
# 1.解压压缩包
# 2.配置环境变量
#HIVE
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
# 3.查看hive 版本
hive --version

8.Spark安装

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1.解压压缩包
# 2.配置环境变量
export SPARK_HOME=/home/hadoop/spark
export PATH=$SPARK_HOME/bin:$PATH:$SPARK_HOME:sbin
# 3.在spark/conf目录下
cp spark-env.sh.template spark-env.sh
# 4.在spark-env.sh里添加hadoop的路径
export SPARK_DIST_CLASSPATH=$(/home/hadoop/hadoop/bin/hadoop classpath)
# 5.查看spark是否安装成功
run-example SparkPi 2>&1 | grep "Pi is"
# 6.使用spark shell
spark shell