xiedeacc
发布于 2023-12-24 / 35 阅读
0
0

ubuntu 22.04系统初始化

1. sudo免密码

打开terminal

sudo passwd root
sudo su
vi /etc/sudoers

在最后添加内容

tiger ALL=(ALL) NOPASSWD:ALL

2. 卸载系统自带软件

sudo apt autoremove --purge -y libreoffice-common thunderbird totem rhythmbox simple-scan gnome-mahjongg aisleriot gnome-mines cheese transmission-common gnome-sudoku firefox firefox-locale-en firefox-locale-zh-hans
sudo apt autoremove --purge -y

3. 更新系统源

sudo sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

4. apt安装软件

sudo apt update
sudo apt install -y language-pack-zh-hans dialog iputils-ping iftop openssh-server tcl
sudo apt install -y lua5.1 libluajit-5.1-dev libperl-dev libncurses5-dev python3-dev ruby-dev libtcl tcl-dev libxml2-dev libxslt-dev libgeoip-dev libgd-dev
sudo apt install -y vim ack python3-pip vim zsh git subversion exuberant-ctags cscope clang-format lcov graphviz 
sudo apt install -y build-essential gcc g++ gdb clang cmake autoconf libtool
sudo chsh -s /bin/zsh

5. 开启ssh登录

5.1 生成ssh密钥

ssh-keygen -t ed25519 -a 100 -C "tiger@xiedeacc.com"
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys

5.2 配置sshd

vim /etc/ssh/sshd_config

内容

Include /etc/ssh/sshd\_config.d/\*.conf
Port 10022
ClientAliveInterval 360
ClientAliveCountMax 0

SyslogFacility AUTH

AllowUsers tiger
StrictModes yes
MaxAuthTries 3

AuthenticationMethods publickey
PubkeyAuthentication yes
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no

UsePAM yes
X11Forwarding yes
PrintMotd no

AcceptEnv LANG LC\_\*
Subsystem sftp /usr/lib/openssh/sftp-server

5.3 重启sshd

sudo systemctl restart ssh

6. 桌面版配置

6.1 root登录桌面

vim /etc/pam.d/gdm-autologin
vim /etc/pam.d/gdm-password
vim /etc/gdm3/custom.conf

6.2 图像模式和命令行模式切换

systemctl set-default multi-user.target
systemctl set-default graphical.target

7. 系统配置

7.1 安装字体

sudo su
locale-gen en_US.UTF-8
update-locale 

wget https://github.com/fangwentong/dotfiles/raw/master/ubuntu-gui/fonts/Monaco.ttf
mkdir -p /usr/share/fonts/custom
mv Monaco.ttf /usr/share/fonts/custom
chmod 744 /usr/share/fonts/custom/Monaco.ttf
cd /usr/share/fonts/custom
mkfontscale
mkfontdir
fc-cache -fv

7.2 虚拟机开启时间同步和USB兼容性

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
vi  /etc/default/locale
shutdown -P now
编辑虚拟机 -> 硬件 -> USB控制器兼容性3.0
编辑虚拟机 -> 选项 -> VMware Tools开启时间同步

详细可以参考

https://askubuntu.com/questions/1238397/ubuntu-server-20-04-time-format-24-hours-on-shell-with-date-command

8. 安装开发常用软件

8.1 oh-my-zsh

sh -c "\$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

修改提示

vi .oh-my-zsh/themes/robbyrussell.zsh-theme

内容

PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}$PWD%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}%1{✗%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

8.2 rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

8.3 nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm node_mirror: https://npm.taobao.org/mirrors/node/
nvm npm_mirror: https://npm.taobao.org/mirrors/npm/
npm config set registry https://registry.npmmirror.com
npm install -g npm typescript js-beautify typescript-formatter eslint prettier instant-markdown-d

8.4 go

sudo su
cd /usr/local
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
tar zxvf go1.21.5.linux-amd64.tar.gz
rm go1.21.5.linux-amd64.tar.gz
exit

8.5 java

sudo su
cd /usr/local
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
tar zxvf jdk-17_linux-x64_bin.tar.gz
rm jdk-17_linux-x64_bin.tar.gz
exit

8.6 设置python

mkdir ~/.pip
vi ~/.pip/pip.conf

内容

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

安装python库

pip3 install -U numpy six wheel setuptools keras_applications keras_preprocessing pydot yapf autopep8 pylint cpplint vtk scipy matplotlib scikit-image scikit-learn ipython dlib wheel gevent mock pyyaml flake8 testresources pillow cpplint

8.7 安装各种格式化工具

sudo su
wget https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildifier-linux-amd64 -O /usr/local/bin/buildifier
chmod +x /usr/local/bin/buildifier
cd /usr/local
mkdir java_lib
cd java_lib
wget https://github.com/google/google-java-format/releases/download/v1.19.1/google-java-format-1.19.1-all-deps.jar

8.8 安装bazel-compilation-database

sudo su
cd /usr/local
git clone https://github.com/grailbio/bazel-compilation-database.git
cd bazel-compilation-database
ln -sf generate.py bazel-compdb

9. 编译安装vim

9.1 编译安装

sudo apt autoremove --purge -y vim vim-runtime vim-tiny vim-common vim-scripts vim-doc
cd
mkdir -p src/software
git clone https://github.com/vim/vim.git
cd vim
./configure --enable-fail-if-missing --enable-luainterp=yes --enable-perlinterp=yes --enable-python3interp=yes --enable-tclinterp=yes --enable-rubyinterp=yes --enable-cscope --enable-terminal --enable-autoservername --enable-multibyte --enable-fontset --with-features=huge --with-luajit --with-tclsh=/usr/bin/tclsh --with-ruby-command=ruby --with-motif-lib=dynamic -with-tlib=ncurses
make -j20
sudo make install
sudo ln -s /usr/local/bin/vim /usr/local/bin/vi

如果luajit找不到,则

sudo su
cp /usr/include/luajit-2.1/*.h /usr/include
ln -sf /usr/lib/x86_64-linux-gnu/libluajit-5.1.so /usr/lib/x86_64-linux-gnu/libluajit.so
exit

9.2 设置.vimrc

配置见附件 https://blog.xiedeacc.com/upload/.vimrc

9.3 安装插件

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vi
:PluginInstall

git clone https://github.com/powerline/fonts ~/.vim/bundle/vim-airline-fonts
cd ~/.vim/bundle/vim-airline-fonts && ./install.sh

cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
./install.py --all

10. 编译安装nginx

10.1 添加用户

groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M

10.2 编译安装

git clone  https://github.com/nginx/nginx.git
cd nginx && mkdir third_party && cd third_party
wget http://zlib.net/zlib-1.2.12.tar.gz
wget https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.39/pcre2-10.39.tar.gz
wget https://github.com/openssl/openssl/archive/refs/tags/openssl-3.0.2.tar.gz
cd ..

./auto/configure \
--user=nginx \
--group=nginx \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_image_filter_module \
--with-http_geoip_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-perl=/usr/bin/perl \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module \
--with-stream_ssl_preread_module \
--with-cpp_test_module \
--with-compat   \
--with-pcre=./third_party/pcre2-10.39 \
--with-pcre-jit \
--with-zlib=./third_party/zlib-1.2.12 \
--with-openssl=./third_party/openssl-openssl-3.0.2 \
--with-libatomic \
--with-debug \
--pid-path=/usr/local/nginx/run/nginx.pid \
--lock-path=/usr/local/nginx/run/nginx.lock \
--error-log-path=/usr/local/nginx/log/error-log \
--http-log-path=/usr/local/nginx/log/access.log

make -j12
sudo make install

10.3 配置ssl

mkdir /usr/local/nginx/conf/ssl
chown -R ubuntu:ubuntu /usr/local/nginx/conf/ssl /usr/local/nginx/log

10.4 配置systemd

sudo vi /lib/systemd/system/nginx.service

内容

[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -q -g 'daemon on; master\_process on;'
ExecStart=/usr/local/nginx/sbin/nginx -g 'daemon on; master\_process on;'
ExecReload=/usr/local/nginx/sbin/nginx -g 'daemon on; master\_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/ningx/run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target

启动nginx

systemctl enable nginx.service
systemctl start nginx.service
systemctl stop nginx.service

11. 设置环境变量

vi ~/.zshrc

添加如下内容:

ulimit -c unlimited

source $HOME/.cargo/env
export PATH=$HOME/.cargo/bin:$PATH

export GOROOT=/usr/local/go
export GOPATH=$HOME/src/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOSRC=$GOPATH/src
export GOBIN=$GOPATH/bin
export GOPKG=$GOPATH/pkg
export GO111MODULE=on

export PATH=/usr/local/nginx/sbin:$PATH

export JAVA_HOME=/usr/local/jdk-17.0.9
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/bin

export PATH=/usr/local/bazel-compilation-database:$PATH

12. 其他配置

vi /etc/default/grub
update-grub

apt update
apt install ntpdate
ntpdate ntp.ubuntu.com
hwclock --localtime --systohc

评论