Linux开发环境搭建
一、NFS客户端安装(REHL)
1)安装nfs客户端工具
yum install -y nfs-utils
2)使用showmount
命令查看nfs服务器的共享目录,例如:
showmount -e 192.168.1.123
3)挂载到本地路径,如下将vol1挂载到本地/mnt/share
目录
mount -t nfs 192.168.1.123:/vol1 /mnt/share
4)在/etc/fstab
配置下增加如下行,开机启动后即可自动挂载
192.168.1.123:/vol1 /mnt/share nfs defaults 0 0
二、防火墙管理
2.1 firewalld防火墙管理
1)端口管理
firewall-cmd --list-ports # 列出开通的端口号
firewall-cmd --permanent --add-port=22/tcp # 添加端口号
firewall-cmd --permanent --remove-port=22/tcp # 移除端口号
firewall-cmd --reload # 重载,添加或删除后需要reload才能生效
2)关闭防火墙,并禁用开机自启动
systemctl stop firewalld
systemctl disable firewalld
2.2 iptables防火墙管理
添加规则
iptables -A INPUT -s 192.168.1.3/24 -p tcp --dport 8008 -j ACCEPT
删除规则
iptables -D INPUT -s 192.168.1.3/24 -j ACCEPT
查询已有规则
iptables -nvL
执行永久生效,否则重启将失效
service iptables save
三、Python3安装
3.1、编译安装
指定安装的python版本
export python_version='3.9.13'
安装系统依赖
yum install -y \
patch \
gcc \
make \
bzip2-devel \
ncurses-devel \
sqlite-devel \
xz-devel \
tk-devel \
readline-devel \
openssl \
openssl-devel \
gcc-c++ \
libffi-devel \
gdbm-devel \
hdf5-devel \
libyaml-devel
或
sudo apt install -y \
build-essential \
libsqlite3-dev \
sqlite3 \
bzip2 \
libbz2-dev \
libffi-dev \
libssl-dev \
openssl \
liblzma-dev \
libncurses5 \
libncurses5-dev \
libncursesw5 \
libreadline-dev
curl -O https://mirrors.huaweicloud.com/python/$python_version/Python-$python_version.tar.xz
tar -xvf Python-$python_version.tar.xz;cd Python-$python_version
./configure --prefix=/usr/bin/openssl --prefix=/usr/local/python$python_version
make;make install
ln -s /usr/local/python$python_version/bin/python3 /usr/local/bin/python3
问题:pip requires Python '>=3.7' but the running Python is 3.6.14
解决方法:执行get-pip.py进行安装(https://files.cnblogs.com/files/greene/get-pip.zip)
3.2、配置pypi源
mkdir $HOME/.pip
touch $HOME/.pip/pip.conf
tee -a $HOME/.pip/pip.conf <<'EOF'
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
安装poetry
curl -sSL https://install.python-poetry.org | python3 -
安装pyenv
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
pyenv install 3.10
四、protoc安装和使用
下载protoc工具https://github.com/protocolbuffers/protobuf/releases
使用方法参考https://developers.google.com/protocol-buffers/docs/gotutorial
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative helloworld/helloworld.proto
windows下编译proto协议文件
.\protoc.exe --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal\proto\internal.proto
proto文件中package为定义的go包名,go_package为实际包路径
option go_package = "internal/proto";
package proto;
五、SSH免密登录配置
获取客户端公钥.ssh/id_rsa.pub
检查并确保服务端文件和目录权限如下
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
将从客户端获取的公钥追加到authorized_keys
文件中即可。
六、Cargo代理配置
编辑或创建文件$HOME/.cargo/config
即可
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'tuna' # tuna、sjtu、ustc、rustcc
# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
# rustcc社区
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
七、PG库管理
创建用户和数据库
create user db_user with password 'passwd';
create database db_name owner db_user;
grant all privileges on database db_name to db_user;
八、安装数据库客户端
pg_dump
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt install postgresql-client-14
mysqldump
sudo apt install mysql-client
mongodump
sudo apt install mongo-tools
mongosh
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
九、Centos7安装Dcoker-ce
sudo yum update -y
sudo yum -y remove docker docker-common docker-selinux docker-engine
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce -y
sudo yum install docker-compose-plugin -y
sudo systemctl start docker
sudo systemctl enable docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://******.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo usermod -aG docker $USER
十、安装Go
curl -O https://dl.google.com/go/go1.19.5.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz
在~/.bashrc中设置环境变量
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOPROXY=https://goproxy.io,direct
十一、解压安装mysql8
groupadd mysql
useradd -r -g mysql mysql
tar -xvf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
mv mysql-8.0.28-linux-glibc2.17-x86_64-minimal /usr/local/mysql8
chown -R root:root /usr/local/mysql8
chown -R mysql:mysql /data/mysql
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
[mysqld]
port=3306
basedir=/usr/local/mysql8
datadir=/data/mysql/8.0.28
socket=/data/mysql/8.0.28/mysql.sock
innodb_log_group_home_dir=/data/mysql/8.0.28
chkconfig --list mysql
/usr/local/mysql8/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/data/mysql/8.0.28
service mysql start
修改root密码
mysql -uroot -p --socket=/data/mysql/8.0.28/mysql.sock
ALTER user 'root'@'localhost' IDENTIFIED BY '******';
创建用户(admin)和数据库(admin)
use mysql;
create user admin IDENTIFIED BY '******';
create database admin;
grant all privileges on *.* to 'admin'@'%';
安装xtrabackup
wget https://downloads.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0.28-21/binary/tarball/percona-xtrabackup-8.0.28-21-Linux-x86_64.glibc2.17.tar.gz
usermod -a -G mysql admin
chown -R admin:admin /data/backup
mysql_config_editor set --login-path=admin --user=admin --socket=/data/mysql/8.0.28/mysql.sock -p
mysql --login-path=admin
备份
xtrabackup --backup --throttle=400 --login-path=admin --datadir=/data/mysql/8.0.28 --target-dir=/data/backup/f1
xtrabackup --backup --throttle=400 --login-path=admin --datadir=/data/mysql/8.0.28 --target-dir=/data/backup/incr1 --incremental-basedir=/data/backup/f1
xtrabackup --backup --throttle=400 --login-path=admin --datadir=/data/mysql/8.0.28 --target-dir=/data/backup/incr2 --incremental-basedir=/data/backup/incr1
恢复
cp -r /data/backup/f1/* /data/restore
xtrabackup --prepare --apply-log-only --target-dir=/data/restore
xtrabackup --prepare --apply-log-only --target-dir=/data/restore --incremental-dir=/data/backup/incr1
xtrabackup --prepare --apply-log-only --target-dir=/data/restore --incremental-dir=/data/backup/incr2
十二、升级git
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc -y
yum install gcc perl-ExtUtils-MakeMaker -y
yum remove git
curl -O https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.29.3.tar.xz
tar -xvf git-2.29.3.tar.xz
cd git-2.29.3
make prefix=/usr/local/git all
make prefix=/usr/local/git install
ln -s /usr/local/git/bin/git /usr/local/bin/git
十二、mysql8.0安装
mkdir -p /usr/local/mysql
tar -xvf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
$ cat << EOF > /usr/local/mysql/8.0.28/my.cnf
[mysqld]
basedir=/usr/local/mysql/8.0.28
datadir=/data/mysql/8.0.28
socket=/usr/local/mysql/8.0.28/mysql.sock
port=3306
user=mysql
EOF
/usr/local/mysql/8.0.28/bin/mysqld --defaults-file=/usr/local/mysql/8.0.28/my.cnf --initialize-insecure --user=mysql
$ cat << EOF > /etc/systemd/system/mysql.service
[Unit]
Description=MySQL Server
After=network.target
[Service]
ExecStart=/usr/local/mysql/8.0.28/bin/mysqld_safe --defaults-file=/usr/local/mysql/8.0.28/my.cnf
ExecStop=/usr/local/mysql/8.0.28/bin/mysqladmin -uroot shutdown
User=mysql
Group=mysql
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
安装kuboard-spray
sudo docker run -d \
--privileged \
--restart=unless-stopped \
--name=kuboard-spray \
-p 80:80/tcp \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /data/kuboard-spray-data:/data \
swr.cn-east-2.myhuaweicloud.com/kuboard/kuboard-spray:v1.1.0-amd64
本文来自博客园,作者:GreeneGe,转载请注明原文链接:https://www.cnblogs.com/greene/p/16413957.html