我从2017年开始,完全使用linux系统作为主力系统。一开始使用Ubuntu linux,后面转到Manjaro linux。
下面是我遇到的一部分问题,主要有系统运维、软件安装和其它日常使用中的问题。
# 开放端口 firewall-cmd --zone=public --add-port=80/tcp --permanent;firewall-cmd --reload # 向指定ip开放指定端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.17.6.52" port protocol="tcp" port="1521" accept" #更新规则 firewall-cmd --reload #重启服务 systemctl restart firewalld.service #删除端口 firewall-cmd --zone=public --remove-port=1521/tcp --permanent
解决办法
Your NRPE iptables chain does not appear to a have a default accept rule.
Unless you just want your own iptables chain for NRPE, you could use:
iptables -I INPUT -s 0/0 -p tcp --dport 5666 -j ACCEPT
This will add an accept rule to the default INPUT chain.
Otherwise, you need to add an accept rule to your NRPE chain.
iptables -I NRPE -s 0/0 -p tcp --dport 5666 -j ACCEPT
有多种更新方式
#将a文件添加到jar文件的指定路径下 jar -uf abc.jar /META-INFO/a
编辑 ~/.vimrc
文件,增加以下内容
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8
root用户可以用runuser命令,以其它用户执行命令
runuser -l elva -c 'whoami'
#切换数据库,若不存在会自动创建 use test # 创建用户 db.createUser({user: "root", pwd: "123456", roles: [{ role: "dbOwner", db: "test" }]})
要完全隐藏此信息,您必须丢弃所有ICMP请求,这是以前iptables防火墙一贯使用的DROP大法。
将external的target设定为DROP,此时无法ping
firewall-cmd --zone=external --set-target=DROP --permanent firewall-cmd --reload
参考地址
vim /src/http/ngx_http_header_filter_module.c # 要修改的配置 static u_char ngx_http_server_string[] = "Server: nginx" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF; # 修改为 static u_char ngx_http_server_string[] = "Server: unknow" CRLF; static u_char ngx_http_server_full_string[] = "Server: unknow" CRLF; static u_char ngx_http_server_build_string[] = "Server: unknow" CRLF; #如果提示缺少PCRE库 yum -y install pcre-devel # 编译 ./configure --prefix=/usr/local/nginx && make && make install
在10.0.134.105上,由于存在多余的网卡 执行命令ifconfig,除了docker0,还可以看到多个桥接网卡 #执行命令:docker network ls 正常情况显示: NETWORK ID NAME DRIVER SCOPE b27a1db91825 bridge bridge local c1d9192be39b host host local 0e3a57c7d22e none null local #执行 docker network rm 网卡名,删除多余的网卡 #修改/etc/docker/daemon.json,写入 {"bip":"172.168.0.1/16"} #如果不能用ip访问docker的资源,检查路由表是否完整 route add -net 172.168.0.0 netmask 255.255.0.0 dev docker0
参考地址
We have solved the issue by adding the following to NGINX:
proxy_http_version 1.1
I guess NGINX proxies traffic by default with http version 1.0, but chunked transfer encoding is a http 1.1 feature.
nginx官网推荐:
For HTTP, the proxy_http_version directive should be set to “1.1
” and the “Connection” header field should be cleared:
server { ... location /http/ { proxy_pass http://http_backend; proxy_http_version 1.1; proxy_set_header Connection ""; ... } }
编辑nginx.conf文件,修改如下:
worker_processes 1; user username;
其中username为实际用户的名称。为了保证安全性,可以使用www-data用户。 nginx-403-forbidden-for-all-files
参见Low write performance on SLES 11 servers with large RAM和Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio。 对于大内存来说,需要考虑调整磁盘写缓存。在/etc/sysctl.conf
中加入
#磁盘写缓存上限(占总内存的百分比) vm.dirty_ratio = 3 #内核flusher线程开始清理磁盘写缓存的上限 vm.dirty_background_ratio = 2
笔记本上如果安装了laptop_mod之类的软件,可能在开机时重新设置了vm.dirty_ratio参数,解决办法:使用cron定时任务,执行命令sleep 5 && sudo sysctl --system
,其中sleep5秒是必要的。
2013-09-17 - Gaetan Bisson
From version 207 on, systemd will not apply the settings from /etc/sysctl.conf
anymore: it will only apply those from /etc/sysctl.d/*
. Since the settings of our /etc/sysctl.conf
shipped by procps-ng have become kernel defaults anyway, we have decided to deprecate this file.
Upon upgrading to procps-ng-3.3.8-3, you will be prompted to move any changes you made to /etc/sysctl.conf
under /etc/sysctl.d
. The easiest way to do this is to run:
pacman -Syu mv /etc/sysctl.conf.pacsave /etc/sysctl.d/99-sysctl.conf
If you never customized /etc/sysctl.conf
, you have nothing to do.
按上节调整磁盘与缓存参数,能够解决长时间开机后gnome-shell进程占用内存过大不能释放的问题。
安装preload,自动缓存常用的数据: yay -S preload
卸载多余的软件:
yay -Rs empathy sudo pacman -Rs gnome-calendar gnome-todo
禁止tracker-store
cp /usr/lib/systemd/user/tracker-store.service ~/.config/autostart cp /usr/lib/systemd/user/tracker-miner-fs.service ~/.config/autostart #编辑以上两个文件,写入内容: X-GNOME-Autostart-enabled=false Hidden=true # 禁止tracker扫描磁盘 gsettings set org.freedesktop.Tracker.Miner.Files enable-monitors false gsettings set org.freedesktop.Tracker.Miner.Files crawling-interval -2 gsettings set org.freedesktop.Tracker.Miner.Files ignored-files ['*'] 删除tracker的数据目录 rm -rf ~/.local/share/tracker rm -rf ~/.cache/tracker
cpwd=`pwd` ps -ef |grep "$cpwd"|grep -v grep|awk '{print $2}'|xargs kill -s 9 rm -rf logs/* rm -rf work/* nohup sh bin/startup.sh & echo "tomcat stated"
Archlinux MySQL安装
mariadb.server文件的位置:/usr/lib/systemd/system
安装后,执行命令:mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
然后重启守护进程
Installing MariaDB/MySQL system tables in '/run/media/elva/data/database/mysql' ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
设置root密码
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password' '/usr/bin/mysqladmin' -u root -h bruce password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/run/media/elva/data/database/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl
Access denied for user 'root'@'localhost'
编辑/etc/mysql/my.cnf,在[mysql]
下增加skip-grant-tables
;
重启mysql,登录mysql -u root -p
;
运行以下命令:
mysql> flush privileges; mysql> alter user 'root'@'localhost' IDENTIFIED BY 'password'
去掉第一步在/etc/mysql/my.cnf中增加的语句,重启mysql。
升级MySQL后
升级和启动后,执行mysql_upgrade -u root -p
允许远程连接
下面的命令将密码设置为password
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES;
重启数据库
更改数据目录
数据目录的默认位置是/var/lib/mysql
,带权限复制到目标位置
sudo cp -R -p /var/lib/mysql /path
编辑/etc/mysql/my.conf
,增加或修改如下内容:
[client] port = 3306 socket = /path/mysql.sock [mysqld] port = 3306 socket = /path/mysql.sock datadir= /path/mysql
安装后执行命令:sudo su - postgres -c "initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'"
启动PostgreSQL
更改数据目录
Create the new directory and assign it to user postgres
(you eventually have to become root):
mkdir -p /pathto/pgroot/data chown -R postgres:postgres /pathto/pgroot
Become the postgres user(change to root, then postgres user), and initialize the new cluster:
initdb -D /pathto/pgroot/data
If not using systemd, edit /etc/conf.d/postgresql
and change the PGROOT variable(optionally PGLOG) to point to your new pgroot directory:
#PGROOT="/var/lib/postgres/" PGROOT="/pathto/pgroot/"
If using systemd, edit /etc/systemd/system/multi-user.target.wants/postgresql.service
, which links to /usr/lib/systemd/system/postgresql.service
, and change the default PGROOT path.
#Environment=PGROOT=/var/lib/postgres/ Environment=PGROOT=/pathto/pgroot/
You will also need to change the default PIDFile path.
PIDFile=/pathto/pgroot/data/postmaster.pid
更改systemd的配置文件后,要重新加载:sudo systemctl daemon-reload
启用postgis功能,需要执行:
CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;
由于zip格式中并没有指定编码格式,windows下生成的zip文件中的编码是GBK/GB2312等,因此这些zip文件在linux下解压缩时出现乱码问题,linux下的默认编码是utf8。
办法一:安装软件unarchiver,它会自动检测文件的编码,解压缩命令:unar $fileName
办法二:unzip -O cp936,默认的unzip没有-O这个选项,需要安装unzip-iconv。
方法一、 for file in $(find . -name "*.txt" -type f);do mv "$file" "${file%.*}";done 方法二、 使用find 将文件名输出到文件中,使用cut和xargs生成 mv命令 find . -name "*.png" >> name.txt cut -d '.' -f 1 name.txt|xargs -i echo mv {}.png {} >>cmd.sh ./cmd.sh
一般的linux上,ctrl + alt + F1 to F6是 getty/agetty程序提供的虚拟控制台,F7是X server运行的console。
在ubuntu 17.10 和更高版本中, X server转移到TTY1和TTY2中,需要使用ctrl + alt + F1 或 F2.
当处理某个命令行的TTY时,还可以使用 Alt + left 或 Alt + right切换TTY
有下面的办法:
1、sudo killall -1 gnome-shell
2、Alt
+ F2
, type "r" then Enter
3、Ctrl + Alt + Backspace kills the X11 interface and restarts it
sudo dd if=manjaro.iso of=/dev/sdd bs=4M status=progress
使用快捷键 ctl + shift + F,可以切换简体和繁体
常见问题:
My unqualified host name (aspire) unknown; sleeping for retry
解决办法:
修改/etc/mail/local-host-names, 增加 127.0.0.1 localhost localhost.localhost
修改 /etc/hosts 增加 127.0.0.1 hostname hostname.hostname
sendmail会把计算机名作为域名加到主机名后,组成完整的长名 name.name来访问
邮件内容在 /var/spool/mail
解决办法:nohup wine "/home/elva/.wine/drive_c/Program Files/QQ/Bin/QQ.exe" & > /dev/null 2>&1
,这样就没有错误日志了
/opt/MindMaster-6/libexec/QtWebEngineProcess: /opt/MindMaster-6/libexec/../lib/libz.so.1: version 'ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16
解决办法:下载zlib1.2.9版本,将编译出来的文件,替换到mindmaster安装目录
报错信息:
Exception in thread "main" java.awt.AWTError: Assistive Technology not found: org.GNOME.Accessibility.AtkWrapper at java.awt.Toolkit.loadAssistiveTechnologies(Toolkit.java:807)
解决办法:
卸载 openjdk-11-jre-headless, 使用 openjdk-8-jre-headless
修改openjdk的配置文件 /etc/java-8-openjdk/accessibility.properties
#assistive_technologies=org.GNOME.Accessibility.AtkWrapper
修改qemu.conf文件
cd /etc/libvirt sudo vi qemu.conf # 修改内容如下,以实际用户名为准 user = 'elva' group = 'elva'
sudo groupadd wireshark sudo chgrp wireshark /usr/bin/dumpcap sudo chmod 4755 /usr/bin/dumpcap sudo gpasswd -a xhz wireshark
sudo apt install chrome-gnome-shell
Solution
启动模拟器时报错:
08:24 Emulator: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) 08:25 Emulator: libGL error: unable to load driver: i965_dri.so 08:25 Emulator: libGL error: driver pointer missing 08:25 Emulator: libGL error: failed to load driver: i965 08:25 Emulator: libGL error: unable to load driver: swrast_dri.so 08:25 Emulator: libGL error: failed to load driver: swrast
解决方法:
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /media/elva/data/Android /Sdk/emulator/lib ANDROID_EMULATOR_USE_SYSTEM_LIBS=1 ./studio.sh 这个环境变量写到/etc/profile中也不生效,变通的办法是在一个shell中写如下内容: #!/bin/sh export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1 exec /opt/android-studio-ide-171.4408382-linux/android-studio/bin/studio_origin.sh
pacman -S manjaro-gnome-assets manjaro-base-skel
hdparm -I /dev/sda
本机显示的信息如下,也就是支持SATA3.0,但不支持PCI-E
Transport: Serial, ATA8-AST, SATA II Extensions, SATA Rev 2.6, SATA Rev 3.0
DaoCloud推出了加速器,编辑 /etc/docker/daemon.json
,写入以下内容:
{ "registry-mirrors":["http://f1361db2.m.daocloud.io/","https://hub-mirror.c.163.com/"] }
curl -o /dev/null -s -w '%{time_total}' https://hub-mirror.c.163.com/
/etc/xdg/autostart
和~/.config/autostart
目录下的都是开机自启,以及利用 systemd。
教程
主要步骤:
yay -S vmware-workstation linux419-headers
kernel 4.9+ 都支持bbr
执行的命令如下:
sudo modprobe tcp_bbr #编辑/etc/sysctl.d/sys-99.conf,写入以下内容 net.core.default_qdisc=fq net.ipv4.tcp_congestion_control=bbr #启用 sudo sysctl --system #check lsmod | grep bbr
solution: use "keyboard.dispatch": "keyCode" in your settings and restart VS. reference
Enter your password to unlock your login keyring
编辑chromium.desktop文件
Exec=chromium --password-store=basic %U
--password-store Specifies which encryption storage backend to use.
Possible values are kwallet, kwallet5, gnome, gnome-keyring,
gnome-libsecret, basic. Any other value will lead to Chrome detecting
the best backend automatically. TODO(crbug.com/571003): Once
PasswordStore no longer uses the Keyring or KWallet for storing
passwords, rename this flag to stop referencing passwords. Do not rename
it sooner, though; developers and testers might rely on it keeping
large amounts of testing passwords out of their Keyrings or KWallets.
安装lightdm-webkit2-greeter
yay -S lightdm-webkit2-greeter 编辑 /etc/lightdm/lightdm.conf 改为 greeter-session=lightdm-webkit2-greeter
此时生效的是默认的antergos主题
下载pantheon主题
git clone git@github.com:miko007/LightDM-Webkit-pantheon-theme.git sudo mv LightDM-Webkit-pantheon-theme /usr/share/lightdm-webkit/themes 编辑/etc/lightdm/lightdm-webkit2-greeter.conf [greeter] webkit-theme = pantheon
sudo systemctl restart lightdm
vim ~/.config/gtk-3.0/gtk.css
#pulseaudio-button * { -gtk-icon-transform: scale(.6); }
重启 xfce4-panel -r
官方地址
安装create_ap,以及两个依赖软件hostapd和dnsmasq
开启热点命令:
sudo create_ap wlp2s0 enp3s0 bruce elva2016
报错ERROR: Failed to initialize lock
,解决办法:
rm /tmp/create_ap*.lock
提示 Operation not possible due to RF-kill
,解决办法:
rfkill list
的结果如果包含soft blocked:yes hard blocked:no
,执行命令:
sudo rfkill unblock wifi
此时这两项都变成no。
can not perform a '--user' install
办法:修改 ~/.pip
目录下的配置文件 pip.conf
, 增加一行 user=false
jenkins默认会关闭shell脚本的所有子进程,需要设置BUILD_ID变量才能防止进程被kill
需要安装tcl和expect
spawn 启动新的交互进程, 后面跟命令或者指定程序
expect 从进程中接收信息, 如果匹配成功, 就执行expect后的动作
send 向进程发送字符串
send exp_send 用于发送指定的字符串信息
exp_continue 在expect中多次匹配就需要用到
send_user 用来打印输出 相当于shell中的echo
interact 允许用户交互
exit 退出expect脚本
eofexpect 执行结束, 退出
set 定义变量
puts 输出变量
set timeout 设置超时时间
示例
#!/usr/bin/expect set timeout 30 spawn ssh root@47.102.153.109 expect "password*" send "Kingdom.2019\r" interact
编辑 /usr/lib/systemd/system/redis.service,注释掉 Type=notify
nohup java -jar jenkins.war *--httpPort=8080 --prefix=/jenkins &*
参考
Reset/remove current shortcut:
xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/<Super>d" --reset
setup new
xfconf-query --channel xfce4-keyboard-shortcuts --property "/xfwm4/custom/<Super>d" --create --type string --set "show_desktop_key" xfconf-query --channel xfce4-keyboard-shortcuts --list -v | grep -i super
这时可以使用 '"'"'
替代单引号。解释一下:
' 使用单引号结束第一段;
" 开启第二段,这里使用双引号;
' 单引号本身;
" 结束第二段,使用双引号;
' 开启第三段,使用单引号。
将新增的文件添加到svn纪录中
sub='svn st | awk '\''{if($1 == "?"){print $2}}'\''|xargs svn add'