linux常用服务搭建
一、pvs
pvcreate /dev/vdb1
vgcreate vg1 /dev/vdb1
vgextend vg1 /dev/vdb2
lvcreate -L 2G -n lv1 vg1
mkfs.ext3 /dev/vg1/lv1 //格式化逻辑卷
lvextend -r(使操作立即生效) -L 756M /dev/vg1/lv1
二、openssh
ssh互信关系实现免密登录原理:
- 在客户端使用ssh-keygen生成一对密钥:公钥+私钥
- 手动将公钥添加到Server端的authorized_key
非对称式加密:公钥由私钥产生,但无法推算出私钥;公钥加密后的密文,只能通过私钥解密
应用场景: 加密:公钥加密私钥解密 数字签名:私钥加密公钥解密
三、ntp
1、yum install ntp ntpdate -y
2、vim /etc/ntp.conf
添加如下两行 server ntp1.aliyun.com
server ntp2.aliyun.com
systemctl start ntpd && systemctl enable ntpd
关闭防火墙略
四、jdk 通过yum安装jdk
1、现在安装JDK1.8
yum search java | grep jdk
yum install java-1.8.0-openjdk //默认安装完只有运行环境,没有开发环境
yum install java-1.8.0-openjdk-devel.x86_64
输入javac有反应说明安装成功
2、配置JAVA_HOME环境变量
// 1、找到JDK安装路径
which java
输出:/usr/bin/java
ls -lr /usr/bin/java
输出:/usr/bin/java -> /etc/alternatives/java
ls -lrt /etc/alternatives/java
输出:/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
最终的位置如下
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
// 2、配置JAVA_HOME
vim /etc/profile
// 在里面添加如下配置
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
// 3、执行一下命令让配置生效
source /etc/profile
// 4、验证路径,能正确输出路径说明配置成功
echo $JAVA_HOME
五、nginx
1、将nginx放到yum repro库中(yum中默认没有nginx)
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安装
yum -y install nginx
3、修改端口号(Apache的默认端口是80,nginx的默认端口也是80,修改默认监听端口避免冲突)
vim /etc/nginx/conf.d/default.conf
server{
listen 8080;
server_name localhost;
}
4、启用服务
systemctl start nginx && systemctl enable nginx
5、验证
curl http://127.0.0.1:8080
六、rabbitmq (消息中间件)
使用场景
- 异步处理
- 应用的解耦
- 流量削峰
yum -y install socat
wget https://github.com/rabbitmq/erlang-rpm/releases/download/v23.3.4.11/erlang-23.3.4.11-1.el7.x86_64.rpm
wget https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.9.16-1.el7.noarch.rpm
rpm -ivh erlang-23.3.4.11-1.el7.x86_64.rpm
rpm -ivh rabbitmq-server-3.9.16-1.el7.noarch.rpm
systemctl enable rabbitmq-server && systemctl start rabbitmq-server
rabbitmq-plugins enable rabbitmq_management //启用web管理界面
http://localhost:15672 //验证(guest guest登录)
rabbitmqctl add_user admin admin //创建账号
rabbitmqctl set_user_tags admin administrator //设置角色
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*" //设置用户权限
rabbitmqctl list_users //查看用户列表
七、zookeeper(集群管理)
1、下载安装包并解压(https://downloads.apache.org/zookeeper/)
wget https://downloads.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz
2、修改配置文件
mv apache-zookeeper-3.6.3-bin apache-zookeeper-3.6.3(改名可省略)
cd apache-zookeeper-3.6.3/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
// 末尾添加
dmin.serverPort=2190 //Zookeeper有个内嵌的管理控制台,通过netty启动,启动默认端口8080。admin.serverPort=xx,是设置netty启动端口。8080端口很常用,所以更换。
3、设置环境变量(不设置的话启动要到安装目录/bin下面)
vim /etc/profile
// 添加如下两行
export ZOOKEEPER_HOME=/root/test/apache-zookeeper-3.6.3
export PATH=$PATH:$ZOOKEEPER_HOME/bin
// 启动
zkServer.sh start
八、mysql(https://dev.mysql.com/downloads/repo/yum/)
1、删除已安装的mysql
// 检查MariaDB
// 删除mariadb
rpm -qa|grep mariadb
rpm -ev --nodeps xxx
// 删除mysql
rpm -qa|grep mysql
rpm -ev --nodeps xxx
// 下载安装
wget https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm
rpm -ivh https://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm
yum repolist all | grep mysql //查看yum仓库的所有MySQL版本
sudo yum-config-manager --enable mysql80-community
sudo yum-config-manager --disable mysql57-community
yum -y install mysql-community-server --nogpgcheck
// 启动mysql
systemctl start mysqld.service && systemctl enable mysqld.service
mysql -uroot -p //root初始密码为空,直接按空进入
上述密码为空的情况,如果密码不为空,按以下处理
grep 'temporary password' /var/log/mysqld.log //MySQL5.7为root用户随机生成了一个密码,如果安装的是RPM包,则默认是/var/log/mysqld.log
// 修改登录密码
ALTER USER root@localhost IDENTIFIED BY 'Admin@139';
// 默认只能本机登录,修改帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入MySQL后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
use mysql;
select host from user where user='root';
update user set host = '%' where user ='root';
// 刷新配置
flush privileges;
九、redis数据库安装(Key-Value内存数据库)https://github.com/redis/redis/archive/7.0.4.tar.gz
wget https://github.com/redis/redis/archive/7.0.4.tar.gz
tar -xzvf 7.0.4.tar.gz
mv redis-7.0.4/ /usr/local/redis
cd /usr/local/redis/
make //编译
cd src/
make install PREFIX=/usr/local/redis //安装,这里加PREFIX作用是编译时可以指定程序存放的路径,方便后续删除
vim /usr/local/redis/redis.conf
1.修改远程访问
bind 0.0.0.0 -::1 (将 127.0.0.1 改为 0.0.0.0)
protected-mode no (将 yes 改为 no)
2.后台启动配置
daemonize yes (将 no 改为 yes)
3.设置密码
requirepass password (添加这行)
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf //启动redis
关闭进程
netstat -lanp | grep redis
kill -9 pid
十、安装MongoDB (https://www.mongodb.com/try/download/community)
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-6.0.0.tgz
tar -xzvf mongodb-linux-x86_64-rhel70-6.0.0.tgz
mv mongodb-linux-x86_64-rhel70-6.0.0 /usr/local/mongodb
vim /etc/profile
cd /usr/local/mongodb/
mkdir data data/db data/log
sudo chmod 666 data/db data/log/
vim mongodb //mongodb 目录下新建配置文件 mongodb.conf
# 数据库数据存放目录
dbpath=/usr/local/mongodb/data/db
# 日志文件存放目录
logpath=/usr/local/mongodb/data/log/mongodb.log
# 日志追加方式
logappend=true
# 端口
port=27017
# 是否认证
auth=true
# 以守护进程方式在后台运行
fork=true
# 远程连接要指定ip,否则无法连接;0.0.0.0代表不限制ip访问
bind_ip=0.0.0.0
vim /etc/profile
末尾加入以下
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:$MONGODB_HOME/bin
mongod -f /usr/local/mongodb/mongodb.conf //启动mongo服务
十一、nacos 服务发现、配置、管理平台(https://github.com/alibaba/nacos/releases)
wget https://github.com/alibaba/nacos/releases/download/1.4.4/nacos-server-1.4.4.tar.gz
tar -xzvf nacos-server-1.4.4.tar.gz
mv nacos /usr/local/nacos
vim /usr/local/nacos/conf/application.properties
sh /usr/local/nacos/bin/startup.sh -m standalone(单机模式运行,集群略)
localhost:8848/nacos //验证 用户名密码都是nacos
+++将nacos添加到守护进程并设置其开机自启+++
# 添加内容如下
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl start nacos && systemctl enable nacos
十二、git
yum -y install git
adduser git && groupadd git
echo git | passwd --stdin git
su - git
git init --bare learning.git
chown git:git learngit.git
十三、gitlab(https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/)
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm
vim /etc/gitlab/gitlab.rb
修改该行 external_url 'http://192.168.0.103:9527'
gitlab-ctl reconfigure
gitlab-ctl start/stop/restart
vim /etc/gitlab/initial_root_password //密码放到临时文件
Password: thAXLJhVoo6V9sRvRH5HrLrD5rg88C7gccEGZDT4Lq0=
Menu->Admin->Password //修改密码
日拱一卒 功不唐捐