Linux脚本备忘录

安装系统后的环境准备

添加新用户

1
2
3
4
5
6
adduser #封装命令,处理完添加用户的全部过程 su到新用户显示username@hostname~$:
useradd #底层命令,什么都没有加,su到新用户显示$:

# 生成 8 位强密码
PASSWORD=$(openssl rand -base64 6 | cut -c1-8)
echo "Password: $PASSWORD"

用户添加sudo组

1
2
3
4
5
6
7
usermod -aG sudo new_user
#加完以后记得:
newgrp sudo
#作用有3:
#1.切换到指定的组上下文
#2.即时生效组更改
#3.启动一个子 shell

配置sshd

1
2
3
4
5
6
7
8
#服务端安装
apt install ssh-server

#配置
sudo vim /etc/ssh/sshd_config

#重启服务
sudo service restart sshd

Vim

Vim配置推荐 - ma6174

1
2
wget 47.93.11.51:88/install_vim.sh
bash install_vim.sh

zsh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#安装zsh
sudo apt install zsh

#修改默认shell为zsh
chsh -s /bin/zsh

#安装oh-my-zsh
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
##如果不成功,请执行下面两条命令,成功了就不需要做下面两条
wget 47.93.11.51:88/install_zsh.sh
bash install_zsh.sh

#安装zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

历史记录推荐命令插件

1
2
##命令自动推荐,根据历史记录
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

命令自动补全

1
2
3
4
5
##命令自动补全插件
mkdir ~/.oh-my-zsh/plugins/incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh
##目录自动跳转插件
sudo apt install autojump

.zshrc配置文件配置

1
2
#插件添加zsh-syntax-highlighting
plugins=(git zsh-syntax-highlighting)
1
2
3
4
5
6
7
8
9
#设置终端颜色,提示符,及上一条指令返回码提示
autoload -U colors && colors
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%1~ %{$reset_color%}%# "
RPROMPT="[%{$fg[yellow]%}%?%{$reset_color%}]"
# Useful support for interacting with Terminal.app or other terminal programs
[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"
source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
source /usr/share/autojump/autojump.sh
source ~/.oh-my-zsh/plugins/incr/incr*.zsh

ctags

1
2
3
4
5
#安装
sudo apt install ctags

#建立索引
ctags -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/systags /usr/include/* /usr/include/x86_64-linux-gnu/sys/* /usr/include/x86_64-linux-gnu/bits/* /usr/include/arpa/*

.vimrc添加索引

1
set tags+=~/systags

安装glibc-doc

  1. 使用以下命令安装
1
sudo apt install glibc-doc

常见路径

hostname :/etc/hostname

host: /ect/hosts

tomcat

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
37
38
39
40
41
42
43
44
45
46
47
#安装JDK8
sudo apt install default-jre -y
sudo apt install openjdk-11-jre-headless -y
sudo apt install openjdk-8-jre-headless -y

#sudo wget https://downloads.apache.org/tomcat/tomcat-8/v8.5.65/bin/apache-tomcat-8.5.65.tar.gz
sudo wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-8/v8.5.73/bin/apache-tomcat-8.5.73.tar.gz
tar zxf apache-tomcat-8.5.73.tar.gz
sudo mv apache-tomcat-8.5.73 /usr/local/tomcat

#建立软连接
sudo ln -s /usr/local/tomcat/bin/* /usr/local/sbin/

#启动
startup.sh start

#端口检查
netstat -anput | grep 8080

#启动命令
startup.sh start #//启动
shutdown.sh #//关闭

catalina.sh stop #//启动
catalina.sh start #//关闭

#关闭防火墙
sudo ufw disable

#tomcat 参数配置
vim /usr/local/tomcat/conf/server.xml
#.......

<Connector port="8081" protocol="HTTP/1.1" #将之前8080端口改成8081端口

connectionTimeout="20000"

# redirectPort="8443" />

#目录修

# <Host name="localhost" appBase="/opt/www" #将网站根目录改到/opt/www

# unpackWARs="true" autoDeploy="true">

#更改网站家目录,这里的ROOT必须大写,更改完成后需要重启
sudo mkdir /opt/www/ROOT -p

mysql

mysql 8.0下载

1
wget https://repo.mysql.com//mysql-apt-config_0.8.20-1_all.deb
1
2
3
4
5
6
7
8
#MySQL 设置
#密码
sudo mysql -uroot
use mysql;
update user set authentication_string=PASSWORD("自定义密码") where User="root";
update user set plugin="mysql_native_password" where User ="root";
flush privileges;
quit;

对于Linux和windows下字符集不兼容的情况,需要替换

• 把文件中的所有的utf8mb4_0900_ai_ci替换为utf8_general_ci
• 以及utf8mb4替换为utf8
• 如上图所示的位置,上图只是一部分,注意全部替换。

数据库导出

1
mysqldump -uroot -p >c:ShareYunAlbum。sql

数据库导入

1
2
use ShareYunAlbum 
source ~/ShqreYunAlbum.sql

卸载mysql

1
2
3
4
5
6
sudo apt purge mysql-* -y
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt autoreclean
sudo apt-get remove mysql-common
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

本站由 Zane Jiang 使用 Stellar 1.33.1 主题创建,一款很棒的 Hexo 主题!

总访问 次 || 本页访问
总访客 人 || 本页访客