Linux日常
总阅读次
Linux配置,shell脚本…
ftp命令用法
- ftp登入:
1
FTP 10.8.3.140
vmware下虚拟机网络问题
- 仅主机模式
vm网卡编辑与vm下Linux系统IP保持一致
网卡文件名可以跟配置文件不一致
[root@localhost network-scripts]# vi ifcfg-eno16777736
1 | DEVICE=eth0 |
网卡信息
1 | [root@localhost network-scripts]# ifconfig |
eno16777736更名
将/etc/sysconfig/network-scripts/ifcfg-eno16777736
网卡名字改为ifcfg-eth0,并修改配置文件为:
1 | TYPE=Ethernet |
主要将DEVICE=eth0
该网卡配置文件为vm下桥接网卡信息
- 修改grub文件来禁用内核继续使用该命名规则,步骤:
编辑grub配置文件”/etc/sysconfig/grub“:
在”GRUB_CMDLINE_LINUX“变量中添加一句”net.ifnames=0 biosdevname=0“.
如下:
1 | GRUB_TIMEOUT=5 |
- 重新生成grub配置并更新内核参数:
运行命令:grub2-mkconfig -o /boot/grub2/grub.cfg
- 添加udev的规则(很有必要!)
需要在”/etc/udev/rules.d“目录中创建一个网卡规则”70-persistent-net.rules“,并写入下面的语句:
SUBSYSTEM==”net”,ACTION==”add”,DRIVERS==”?“,ATTR{address}==”您的网卡MAC地址”,ATTR{type}==”1” ,KERNEL==”eth“,NAME=”eth0”
如下
1 | [root@localhost ~]# vi /etc/udev/rules.d/70-persistent-net.rules |
1 | SUBSYSTEM=="net",ACTION=="add",DRIVERS=="?*",ATTR{address}=00:0c:29:44:10:6c",ATTR{type}=="1",KERNEL="eth*",NAME="eth0" |
- reboot重启系统
fedora更新源
#cd /etc/yum.repos.d
把原来的问文件删除 rm -rf
然后
1 | #wget http://mirrors.163.com/.help/fedora-163.repo |
需要注释掉配置文件里面的https://mirrors
一行,不然应该很慢
1 | mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch |
dnf makecache
makecache命令参数是指让DNF重新获取并建立软件源元数据信息缓存
http://mirrors.sohu.com/help/fedora.html
VM下桥接网卡,应该将vm下虚拟机设置为dhcp自动获取ip
1 | HWADDR=00:0c:29:44:a0:6c |
设置开机启动命令、vm下与主机共享目录 //mark
http://blog.csdn.net/wujin8589/article/details/52062413
二、解决安装VMWare tools后/mnt中有hgfs但没共享文件
前提:在虚拟机软件中设置了共享目录
此时在linux中进入 /mnt/hgfs 文件夹,但发现共享的文件没有显示
使用以下办法解决(root权限):
sudo passwd root
输入root的密码就可以正常切换到root权限了
- vmware-hgfsclient 命令查看当前有哪些共享的目录,这里我只使用了shared文件夹
- 使用 mount -t vmhgfs .host:/shared /mnt/hgfs 命令挂载该共享文件夹(注意:带.号的哦),其中.host:/Documents是共享名,只需把Documents换成
使用vmware-hgfsclient 命令得到的目录,/mnt/hgfs是挂载点 - 到此为止是可以使用该共享文件夹了,但每次都得重复mount一次,所以需要设置为随机启动后自动挂载
编辑 /etc/fstab,添加下面一行
.host:/shared /mnt/hgfs vmhgfs defaults 0 0 (按需写)
设置默认进入文本模式
http://www.2cto.com/os/201309/246497.html
1.如果你想让系统默认从文本模式启动的话,则应该依次输入以下两条命令:
sudo rm /etc/systemd/system/default.target //这条命令是删除原来的默认启动模式
sudo ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target //这条命令是添加新的启动模式,将文本模式设置成默认启动模式
2.如果你想让系统默认从图形界面启动的话,则应该依次输入以下两条命令:
sudo rm /etc/systemd/system/default.target //这条命令是删除原来的默认启动模式
sudo ln -s /lib/systemd/system/graphical.target /etc/systemd/system/default.target //这条命令是添加新的启动模式,将图形模式设置成默认启动模式
注意一下:
当你修改系统默认启动模式为文本模式后,重新启动操作系统后,linux就会默认进入tty1(终端1)的文本模式。如果你想要进入图形界面,则可以输入一面这条命令:
startx //这是以普通用户登陆图形界面,如果你想以超级用户(root)进入图形界面的话,则应该输入sudo startx。
fedora设置root用户自动登入
1 | vi /etc/gdm/custom.conf |
ssh登不上
情况一:VM下host能与虚拟机互相Ping通,但是SSH却登不上提示密码错误(实际密码没错错误)
实际解决
VM下Linux与宿主win10系统的以太网卡IP相同,导致SSH登入不上
注意:如果Linux桥接的网卡有设网关,VM下Linux网卡要手动设置网关和IP;如:
1 | TYPE=Ethernet |
- ssh报错:kex_exchange_identification: Connection closed by remote host
[takethat@t470p ~]$ ssh -v -l pi -p 44 192.168.1.63
OpenSSH_8.6p1, OpenSSL 1.1.1k 25 Mar 2021
debug1: Reading configuration data /home/takethat/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.1.63 [192.168.1.63] port 44.
debug1: Connection established.
debug1: identity file /home/takethat/.ssh/id_rsa type 0
debug1: identity file /home/takethat/.ssh/id_rsa-cert type -1
debug1: identity file /home/takethat/.ssh/id_dsa type -1
debug1: identity file /home/takethat/.ssh/id_dsa-cert type -1
debug1: identity file /home/takethat/.ssh/id_ecdsa type -1
debug1: identity file /home/takethat/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/takethat/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/takethat/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/takethat/.ssh/id_ed25519 type -1
debug1: identity file /home/takethat/.ssh/id_ed25519-cert type -1
debug1: identity file /home/takethat/.ssh/id_ed25519_sk type -1
debug1: identity file /home/takethat/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/takethat/.ssh/id_xmss type -1
debug1: identity file /home/takethat/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
kex_exchange_identification: Connection closed by remote host
Connection closed by 192.168.1.63 port 44[root@localhost boost_1_59_0]# ./bootstrap.sh –with-libraries=all –with-toolset=gcc1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20原因server做了端口转发,导致验证无法正确通过端口
[](https://unix.stackexchange.com/questions/128894/ssh-exchange-identification-connection-closed-by-remote-host-not-using-hosts-d)
+ fedora21让sshd开机自动启动
chkconfig sshd on
参照文章:
https://blog.csdn.net/yuxuan_08/article/details/72863720
# fedora21编译boost 1.59.0
[参考文章] [2]
[2]: https://blog.csdn.net/u011641865/article/details/73498533
1. 配置编译选项
Building Boost.Build engine with toolset gcc… tools/build/src/engine/bin.linuxx86/b2
Detecting Python version… 2.7
Detecting Python root… /usr
Unicode/ICU support for Boost.Regex?… not found.
Generating Boost.Build configuration in project-config.jam…
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit ‘project-config.jam’.
Further information:
Command line help:
./b2 –helpGetting started guide:
http://www.boost.org/more/getting_started/unix-variants.htmlBoost.Build documentation:
http://www.boost.org/build/doc/html/index.htm
https://yq.aliyun.com/articles/67001
1 |
|
./b2 toolset=gcc
1 |
|
Building Boost.Build engine with toolset gcc…
Failed to build Boost.Build build engine
Consult ‘bootstrap.log’ for more details.
1 | 解决: |
chmod +x ./tools/build/src/engine/build.sh
1
2
3
4
+ fedora21安装完Qt后报错:
/opt/Qt5.4.1/5.4/gcc/include/QtGui/qopengl.h:122: error: GL/gl.h: No such file or directory
include <GL/gl.h>
^
1 | 或者: |
:-1: error: cannot find -lGL
1 |
|
参考: https://forum.facepunch.com//f/hwsw/beeol/GL-gl-h-No-such-file-or-directory/1/
linux杀死进程指令
用 ps -e
1 | kill -9 `进程ID` |
跟
1 | killall `进程名称` |
可以用
ps -e | grep run
找出带run字符的进程名字
查找相关进程
1 | [root@localhost ~]# ps -ef | grep SLE |
ps -ef | grep SLE
找出带SLE的进程名字
kill -9
+PID
杀死进程
批量解压包脚本
- 批量解压目录下所有.tgz包
1
2解压本目录所有.zxvf文件
for tar in *.tgz; do tar xvf $tar; done
1 | # 解压本目录所有.tar.gz文件 |
mark:脚本有错,只能一条一条的运行,2个语句块放到一起会报错,想想如何解决写到一起??
linux下boost
- 查看boost版本:
1
- 去除.sh脚本里的^M
1
2敲出^M字符的方法,ctrl+v然后ctrl+m就可以了。
#sed -i 's/^M//g' filename
fedora
创建root用户密码:
sudo passwdfedora27安装 synergy-1.10.0-40.stable.275cdc1c.centos.el7.x86_64.rpm
rpm -ivh synergy-1.10.0-40.stable.275cdc1c.centos.el7.x86_64.rpm
报错:
[root@localhost Downloads]# rpm -ivh synergy-1.10.0-40.stable.275cdc1c.centos.el7.x86_64.rpm
error: Failed dependencies:
libdns_sd.so.1()(64bit) is needed by synergy-1.10.0-40.stable.275cdc1c.el7.x86_64
解决:
1 | dnf install avahi-compat-libdns_sd |
能安装成功,但是启动报错
System tray is unavailable,don’t close your window
看linux桌面环境
[root@acer Downloads]# gnome-shell –version
GNOME Shell 3.26.1
rfsdlfjlasfjdlkj
- fedora28开启sshd
确认是否安装ssh包
rpm -qa | grep openssh-server修改配置文件
1
2
3
4
5
6vi /etc/ssh/sshd_config
PermitRootLogin yes //是否允许root直接登录
Port 22 //监听的端口号,默认是22,可以自定义。
1 | chkconfig sshd on |
重启
1 | service sshd restart |
- ubuntu18.04安装shadows
https://blog.csdn.net/bingyu9875/article/details/54600691
https://blog.csdn.net/totorocyx/article/details/80032556
报错:
1 | takethat@t470p:~$ sslocal -c /home/takethat/shadowsocks.json |
解决办法
1 | vi /usr/local/lib/python2.7/dist-packages/shadowsocks/crypto/openssl.py |
在ubuntu18.04使用命令
apt install shadowsocks
安装的是shadowsocks 2.9.0-2
,重启操作系统后没有这个报错
ubuntu删除firefox
dpkg –get-selections |grep firefox
- 少动态库
[root@localhost SOFTWARE_PACKAGE_DEBUG]# ldd AGM_Client
./AGM_Client: ./libc.so.6: versionGLIBC_2.18' not found (required by /lib/libstdc++.so.6) ./AGM_Client: ./libc.so.6: version
GLIBC_2.17’ not found (required by /lib/libstdc++.so.6)
- 加载动态库失败,没有定义函数符号原因:
1
2./test_GC_ZZ14A /home/takethat/AGM__Driver_ZZ14A/GC-AGM_ZZ14A/libGC_ZZ14A.so
Cannot load library: /home/takethat/AGM__Driver_ZZ14A/GC-AGM_ZZ14A/libGC_ZZ14A.so: undefined symbol: sbs_n455_dio_set
sbs_n455_dio_set
这个函数有声明,但是没有定义,可能这个函数是定义在另一个动态库里;
- ssh别的主机失败,但是别的主机SSH过来却可以
scp命令也是相同的情况
报错:
1 | [root@localhost ~]# ssh 192.168.242.132 |
- error: expected ‘while’ before ‘void’解决办法
1
2
3
4
5
6
7
8
9root@vmubuntu:/home# gcc condest1.c -o b.out -lpthread
condest1.c: In function ‘thread1’:
condest1.c:36:1: error: expected ‘while’ before ‘void’
void* thread2(void* arg)
^
condest1.c:70:1: error: expected declaration or statement at end of input
}
^
condest1.c:70:1: error: expected declaration or statement at end of input
pthread_cleanup_push(hander, &mutex);
// pthread_cleanup_push(hander, “handler 1”);//代码中用了2个退出调用函数
- error:expected declaration or statement at end of input
root@vmubuntu:/home# gcc -pthread pthread_cleanup.c -o c.out
pthread_cleanup.c: In function ‘thr_fn2’:
pthread_cleanup.c:40:1: error: expected ‘while’ before ‘int’
int main()
^
pthread_cleanup.c:83:1: error: expected declaration or statement at end of input
}
^
pthread_cleanup.c:83:1: error: expected declaration or statement at end of input
解决1:
1 | pthread_cleanup_pop(0); |
解决2:
pthread_cleanup_push()/pthread_cleanup_pop()必须同时出现,如果有头无尾也会报这个错误;
解决3:
err=pthread_cearte(&tid1,NULL,thread_fun,NULL);// 打错了,应该是:
解决4:
本地写的代码到编译环境的代码不一致,检查下路径;
vi报错
[takelinux ~]# vim
Error detected while processing function plug#end:
line 86:
E484: Can’t open file /usr/share/vim/vim80/syntax/syntax.vim
Press ENTER or type command to continue