+-
centos7上tar包安装nginx,nodejs,git,mongodb,redis,mysql,postgresql
首页 专栏 mysql 文章详情
0
头图

centos7上tar包安装nginx,nodejs,git,mongodb,redis,mysql,postgresql

wkArtist 发布于 4 月 27 日

总结以下常用的需要安装的运行依赖,目前用到的包括nginx,nodejs,git,mongodb,redis,mysql,postgresql。

安装nginx

安装所需插件 # 安装gcc yum -y install gcc # pcre、pcre-devel安装 yum install -y pcre pcre-devel # zlib安装 yum install -y zlib zlib-devel # 安装openssl yum install -y openssl openssl-devel 安装nginx # 下载nginx安装包 wget http://nginx.org/download/nginx-1.20.0.tar.gz # 解压压缩包 tar -zxvf nginx-1.20.0.tar.gz # 切换到/usr/local/nginx-1.20.0下编译安装 ./configure make make install 启动停止nginx(推荐使用systemd进行管理) #查找安装路径 whereis nginx cd /usr/local/nginx/sbin # 启动nginx ./nginx # 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程 ./nginx -s stop # 此方式停止步骤是待nginx进程处理任务完毕进行停止 ./nginx -s quit # 重启nginx ./nginx -s reload 使用systemd管理 # 创建nginx.service文件 vim /lib/systemd/system/nginx.service # 写入内容如下 [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target 管理nginx服务 # 启动nginx systemctl start nginx.service # 停止nginx systemctl stop nginx.service # 重启nginx systemctl reload nginx.service # 将nginx加入开机启动 systemctl enable nginx.service # 将nginx从开机启动中移除 systemctl disable nginx.service

参考链接:

https://blog.csdn.net/qq_3734...
https://www.cnblogs.com/boony...
https://blog.csdn.net/yunweim...

安装nodejs

下载nodejs压缩包

官方地址:http://nodejs.cn/download/

wget https://npm.taobao.org/mirrors/node/v14.16.1/node-v14.16.1-linux-x64.tar.xz 解压缩 tar -xvf node-v14.16.1-linux-x64.tar.xz mv node-v14.16.1-linux-x64 nodejs 创建软链接 # 建立node软链接 ln -s /usr/local/nodejs/bin/node /usr/local/bin # 建立npm 软链接 ln -s /usr/local/nodejs/bin/npm /usr/local/bin 更换镜像源 # 设置国内淘宝镜像源 npm config set registry https://registry.npm.taobao.org # 查看设置信息 npm config list 验证是否成功 node -v npm -v

参考链接:
https://blog.csdn.net/qq_3795...

安装git

安装依赖包 sudo yum install -y gcc-c++ sudo yum install -y zlib-devel perl-ExtUtils-MakeMaker 去官网下载最新的git源码包 wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.1.tar.gz 解压,配置,安装 # 解压 tar -zxvf git-2.31.1.tar.gz # 创建一个文件夹作为git安装路径 mkdir git cd git-2.30.1 # 指定安装路径 ./configure --prefix=/usr/local/git # 编译 make # 安装 make install 设置环境变量 vim /etc/profile # 在文件末尾追加git执行文件目录 PATH=$PATH:/usr/local/git/bin # 使文件生效 source /etc/profile 查看git版本 git --version

安装mongodb

下载MongoDB安装包 解压安装包 tar -xzvf mongodb-linux-x86_64-rhel70-4.2.13.tgz # 重命名 mv mongodb-linux-x86_64-rhel70-4.2.13 mongodb-4.2 安装MongoDB cd mongodb-4.2 # 创建log和data用于存放日志和数据 mkdir log data # 添加配置文件mongodb.conf vim mongodb.conf # 添加以下配置 # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /usr/local/mongodb-4.2/log/mongodb.log # Where and how to store data. storage: dbPath: /usr/local/mongodb-4.2/data journal: enabled: true # engine: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /usr/local/mongodb-4.2/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. 设置环境变量 vim /etc/profile # 在文件末尾追加git执行文件目录 PATH=$PATH:/usr/local/mongodb-4.2/bin # 使文件生效 source /etc/profile 使用systemd管理mongodb # 创建mongodb.service文件 vim /lib/systemd/system/mongodb.service # 写入内容如下 [Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/mongodb-4.2/bin/mongod --config /usr/local/mongodb-4.2/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb-4.2/bin/mongod --shutdown --config /usr/local/mongodb-4.2/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target 管理mongodb状态 # 启动mongodb systemctl start mongodb.service # 停止mongodb systemctl stop mongodb.service # 重启mongodb systemctl reload mongodb.service # 将mongodb加入开机启动 systemctl enable mongodb.service # 将mongodb从开机启动中移除 systemctl disable mongodb.service

参考文章:

https://www.cnblogs.com/lijia...
https://www.cnblogs.com/shiky...

安装Redis

下载并解压安装包 wget http://download.redis.io/releases/redis-6.2.2.tar.gz tar -zxvf redis-6.2.2.tar.gz 编译并安装 # 创建安装目录 mkdir redis # 编译 cd redis-6.2.2 make # 安装到指定目录 make install PREFIX=/usr/local/redis 创建配置文件 # 从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录 cp /usr/local/redis-6.2.2/redis.conf /usr/local/redis/bin/ # 修改 redis.conf 文件 daemonize yes #守护进程 默认值为:no #bind 127.0.0.1 #绑定地址 将其注释 protected-mode no #关闭保护模式,此时外部网络可以直接访问 默认值为:yes 使用systemd管理 # 创建redis.service文件 vim /lib/systemd/system/redis.service # 添加以下内容 [Unit] Description=redis-server After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf PrivateTmp=true [Install] WantedBy=multi-user.target redis管理命令 systemctl start redis.service #启动redis服务 systemctl stop redis.service #停止redis服务 sysemctl restart redis.service #重新启动服务 systemctl status redis.service #查看服务当前状态 systemctl enable redis.service #设置开机自启动 systemctl disable redis.service #停止开机自启动 创建redis命令软链接 ln -s /usr/local/redis/bin/redis-cli /usr/bin/ 使用redis-cli测试 redis-cli

参考链接:https://www.cnblogs.com/heqiu...

安装mysql

检查系统是否安装过mysql # 查询所有mysql 对应的文件夹,全部删除 whereis mysql find / -name mysql 卸载CentOS7系统自带的mariadb # 查看系统自带的Mariadb [root@VM-12-9-centos ~]# rpm -qa|grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64 # 卸载系统自带的Mariadb [root@VM-12-9-centos ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 # 删除etc目录下的my.cnf ,一定要删掉,等下再重新建 [root@VM-12-9-centos ~]# rm -rf /etc/my.cnf 检查有无安装过mysql 用户组,没有的话创建 # 检查mysql 用户组是否存在 cat /etc/group | grep mysql cat /etc/passwd | grep mysql # 创建mysql 用户组和用户 groupadd mysql useradd -r -g mysql mysql 下载安装包,从官网安装下载,我下载的位置在/usr/local/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz 解压安装 # 解压 tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz # 重命名为mysql mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql # 更改mysql 目录下所有文件夹所属的用户组和用户,以及权限 chown -R mysql:mysql /usr/local/mysql chmod -R 755 /usr/local/mysql 初始化mysql # 创建data目录 mkdir /usr/local/mysql/data # 初始化,控制台中会打印临时密码 /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql # 保存结尾处的临时密码,后续使用客户端时需用此密码登录 [root@VM-12-9-centos bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 2021-04-27T06:23:19.882305Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-04-27T06:23:20.192179Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-04-27T06:23:20.273220Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-04-27T06:23:20.343826Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0fa9325e-a721-11eb-a87c-5254009d3ad8. 2021-04-27T06:23:20.348927Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-04-27T06:23:21.462427Z 0 [Warning] CA certificate ca.pem is self signed. 2021-04-27T06:23:21.570135Z 1 [Note] A temporary password is generated for root@localhost: qitk>aF<%5yO 编写配置文件my.cnf,并添加配置 vim /etc/my.cnf # 插入以下配置 [mysqld] datadir=/usr/local/mysql/data port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES symbolic-links=0 max_connections=400 innodb_file_per_table=1 lower_case_table_names=1 启动mysqld /usr/local/mysql/support-files/mysql.server start 使用systemd进行管理 vim /lib/systemd/system/mysql.service # 添加以下配置 [Unit] Description=MySQL Server Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Service] User=mysql Group=mysql # mysql pid文件记录的是当前mysqld进程的pid # 通过Mysqld_safe启动mysql时,mysqld_safe会检查pid文件,未指定PID文件时,pid文件默认名为$DATADIR/`hostname`.pid PIDFile=/usr/local/mysql/data/VM-12-9-centos.pid ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf Restart=on-failure RestartPreventExitStatus=1 TimeoutSec=0 PrivateTmp=false [Install] WantedBy=multi-user.target 使用systemd管理mysql命令 systemctl start mysql.service #启动mysql服务 systemctl stop mysql.service #停止mysql服务 sysemctl restart mysql.service #重新启动服务 systemctl status mysql.service #查看服务当前状态 systemctl enable mysql.service #设置开机自启动 systemctl disable mysql.service #停止开机自启动 添加客户端软链接 ln -s /usr/local/mysql/bin/mysql /usr/bin/ 客户端登录并修改密码 # 密码为之前初始化mysql时保存的临时密码 mysql -u root -p # 修改密码 set password for root@localhost = password('新密码');

参考文章:

https://www.cnblogs.com/wpnr/...
https://blog.csdn.net/supaher...
https://www.cnblogs.com/justf...

安装postgresql

因为不能使用CentOs的 root账号 启动PostgreSql。所以在这里,我先创建一个专门的用于用以操作PostgreSql useradd postgresql 安装依赖。如果你的服务器已安装过gcc相关内容,这步可忽略 yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake gcc* readline-devel 解压安装 # 解压postgreSql tar -vxf postgresql-13.2.tar.gz # 创建PostgreSql的安装目录以及数据目录 mkdir -p /usr/local/postgresql/data chown -R postgresql:postgresql /usr/local/postgresql # 进入解压目录 cd postgresql-13.2/ # 执行configure ./configure --prefix=/usr/local/postgresql --with-python --with-libxml --with-libxslt # make并安装 make & make install 初始化数据库 # 切换到之前创建的用户 su postgresql # 初始化数据库 /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data -E UTF8 # 修改配置文件 vim /usr/local/postgresql/data/postgresql.conf # 修改允许访问的ip地址 listen_addresses='*' # 修改网桥配置信息 vim /usr/local/postgresql/data/pg_hba.conf # 修改IPV4 local connections # 其中192.168.0.0/16 代表192.168.1.1到192.168.255.255都可以访问 host all all 192.168.0.0/16 md5 配置环境变量 # 先切回root用户 su root # 添加环境变量 vim /etc/profile # 追加 # postgresql export PATH=$PATH:/usr/local/postgresql/bin export PGHOME=/usr/local/postgresql export PGDATA=/usr/local/postgresql/data/ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/ # 重新加载配置文件 source /etc/profile 启动,停止postgresql # 切回postgresql用户 su postgresql # 启动服务 pg_ctl start -D $PGDATA -l /usr/local/postgresql/server.log # 进入默认数据库 psql postgres # 创建有密码的用户 CREATE USER postgres WITH PASSWORD '123456'; # 停止服务 pg_ctl stop -D $PGDATA # 查看服务状态 pg_ctl status -D $PGDATA # 重启服务 pg_ctl reload -D $PGDATA 使用systemd管理postgresql # 切到root用户 su root # 添加配置文件 vim /lib/systemd/system/postgresql.service [Unit] Description=PostgreSQL database server After=network.target After=syslog.target [Service] Type=forking User=postgresql Environment=PGDATA=/usr/local/postgresql/data ExecStart=/usr/local/postgresql/bin/pg_ctl start -D ${PGDATA} -s -w ExecStop=/usr/local/postgresql/bin/pg_ctl stop -D ${PGDATA} -s -m fast ExecReload=/usr/local/postgresql/bin/pg_ctl reload -D ${PGDATA} -s TimeoutSec=300 [Install] WantedBy=multi-user.target 在postgresql用户使用systemd命令 systemctl start postgresql.service #启动postgresql服务 systemctl stop postgresql.service #停止postgresql服务 sysemctl restart postgresql.service #重新启动服务 systemctl status postgresql.service #查看服务当前状态 systemctl enable postgresql.service #设置开机自启动 systemctl disable postgresql.service #停止开机自启动

参考文章:

https://blog.csdn.net/qq_2663...
https://blog.csdn.net/darkdra...
https://www.postgresql.org/do...

centos mongodb mysql redis postgresql
阅读 108 更新于 5 月 17 日
举报
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
avatar
wkArtist
6 声望
1 粉丝
关注作者
0 条评论
得票数 最新
提交评论
avatar
wkArtist
6 声望
1 粉丝
关注作者
宣传栏
目录

总结以下常用的需要安装的运行依赖,目前用到的包括nginx,nodejs,git,mongodb,redis,mysql,postgresql。

安装nginx

安装所需插件 # 安装gcc yum -y install gcc # pcre、pcre-devel安装 yum install -y pcre pcre-devel # zlib安装 yum install -y zlib zlib-devel # 安装openssl yum install -y openssl openssl-devel 安装nginx # 下载nginx安装包 wget http://nginx.org/download/nginx-1.20.0.tar.gz # 解压压缩包 tar -zxvf nginx-1.20.0.tar.gz # 切换到/usr/local/nginx-1.20.0下编译安装 ./configure make make install 启动停止nginx(推荐使用systemd进行管理) #查找安装路径 whereis nginx cd /usr/local/nginx/sbin # 启动nginx ./nginx # 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程 ./nginx -s stop # 此方式停止步骤是待nginx进程处理任务完毕进行停止 ./nginx -s quit # 重启nginx ./nginx -s reload 使用systemd管理 # 创建nginx.service文件 vim /lib/systemd/system/nginx.service # 写入内容如下 [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target 管理nginx服务 # 启动nginx systemctl start nginx.service # 停止nginx systemctl stop nginx.service # 重启nginx systemctl reload nginx.service # 将nginx加入开机启动 systemctl enable nginx.service # 将nginx从开机启动中移除 systemctl disable nginx.service

参考链接:

https://blog.csdn.net/qq_3734...
https://www.cnblogs.com/boony...
https://blog.csdn.net/yunweim...

安装nodejs

下载nodejs压缩包

官方地址:http://nodejs.cn/download/

wget https://npm.taobao.org/mirrors/node/v14.16.1/node-v14.16.1-linux-x64.tar.xz 解压缩 tar -xvf node-v14.16.1-linux-x64.tar.xz mv node-v14.16.1-linux-x64 nodejs 创建软链接 # 建立node软链接 ln -s /usr/local/nodejs/bin/node /usr/local/bin # 建立npm 软链接 ln -s /usr/local/nodejs/bin/npm /usr/local/bin 更换镜像源 # 设置国内淘宝镜像源 npm config set registry https://registry.npm.taobao.org # 查看设置信息 npm config list 验证是否成功 node -v npm -v

参考链接:
https://blog.csdn.net/qq_3795...

安装git

安装依赖包 sudo yum install -y gcc-c++ sudo yum install -y zlib-devel perl-ExtUtils-MakeMaker 去官网下载最新的git源码包 wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.1.tar.gz 解压,配置,安装 # 解压 tar -zxvf git-2.31.1.tar.gz # 创建一个文件夹作为git安装路径 mkdir git cd git-2.30.1 # 指定安装路径 ./configure --prefix=/usr/local/git # 编译 make # 安装 make install 设置环境变量 vim /etc/profile # 在文件末尾追加git执行文件目录 PATH=$PATH:/usr/local/git/bin # 使文件生效 source /etc/profile 查看git版本 git --version

安装mongodb

下载MongoDB安装包 解压安装包 tar -xzvf mongodb-linux-x86_64-rhel70-4.2.13.tgz # 重命名 mv mongodb-linux-x86_64-rhel70-4.2.13 mongodb-4.2 安装MongoDB cd mongodb-4.2 # 创建log和data用于存放日志和数据 mkdir log data # 添加配置文件mongodb.conf vim mongodb.conf # 添加以下配置 # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /usr/local/mongodb-4.2/log/mongodb.log # Where and how to store data. storage: dbPath: /usr/local/mongodb-4.2/data journal: enabled: true # engine: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /usr/local/mongodb-4.2/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. 设置环境变量 vim /etc/profile # 在文件末尾追加git执行文件目录 PATH=$PATH:/usr/local/mongodb-4.2/bin # 使文件生效 source /etc/profile 使用systemd管理mongodb # 创建mongodb.service文件 vim /lib/systemd/system/mongodb.service # 写入内容如下 [Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/mongodb-4.2/bin/mongod --config /usr/local/mongodb-4.2/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb-4.2/bin/mongod --shutdown --config /usr/local/mongodb-4.2/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target 管理mongodb状态 # 启动mongodb systemctl start mongodb.service # 停止mongodb systemctl stop mongodb.service # 重启mongodb systemctl reload mongodb.service # 将mongodb加入开机启动 systemctl enable mongodb.service # 将mongodb从开机启动中移除 systemctl disable mongodb.service

参考文章:

https://www.cnblogs.com/lijia...
https://www.cnblogs.com/shiky...

安装Redis

下载并解压安装包 wget http://download.redis.io/releases/redis-6.2.2.tar.gz tar -zxvf redis-6.2.2.tar.gz 编译并安装 # 创建安装目录 mkdir redis # 编译 cd redis-6.2.2 make # 安装到指定目录 make install PREFIX=/usr/local/redis 创建配置文件 # 从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录 cp /usr/local/redis-6.2.2/redis.conf /usr/local/redis/bin/ # 修改 redis.conf 文件 daemonize yes #守护进程 默认值为:no #bind 127.0.0.1 #绑定地址 将其注释 protected-mode no #关闭保护模式,此时外部网络可以直接访问 默认值为:yes 使用systemd管理 # 创建redis.service文件 vim /lib/systemd/system/redis.service # 添加以下内容 [Unit] Description=redis-server After=network.target [Service] Type=forking ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf PrivateTmp=true [Install] WantedBy=multi-user.target redis管理命令 systemctl start redis.service #启动redis服务 systemctl stop redis.service #停止redis服务 sysemctl restart redis.service #重新启动服务 systemctl status redis.service #查看服务当前状态 systemctl enable redis.service #设置开机自启动 systemctl disable redis.service #停止开机自启动 创建redis命令软链接 ln -s /usr/local/redis/bin/redis-cli /usr/bin/ 使用redis-cli测试 redis-cli

参考链接:https://www.cnblogs.com/heqiu...

安装mysql

检查系统是否安装过mysql # 查询所有mysql 对应的文件夹,全部删除 whereis mysql find / -name mysql 卸载CentOS7系统自带的mariadb # 查看系统自带的Mariadb [root@VM-12-9-centos ~]# rpm -qa|grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64 # 卸载系统自带的Mariadb [root@VM-12-9-centos ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 # 删除etc目录下的my.cnf ,一定要删掉,等下再重新建 [root@VM-12-9-centos ~]# rm -rf /etc/my.cnf 检查有无安装过mysql 用户组,没有的话创建 # 检查mysql 用户组是否存在 cat /etc/group | grep mysql cat /etc/passwd | grep mysql # 创建mysql 用户组和用户 groupadd mysql useradd -r -g mysql mysql 下载安装包,从官网安装下载,我下载的位置在/usr/local/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz 解压安装 # 解压 tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz # 重命名为mysql mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql # 更改mysql 目录下所有文件夹所属的用户组和用户,以及权限 chown -R mysql:mysql /usr/local/mysql chmod -R 755 /usr/local/mysql 初始化mysql # 创建data目录 mkdir /usr/local/mysql/data # 初始化,控制台中会打印临时密码 /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql # 保存结尾处的临时密码,后续使用客户端时需用此密码登录 [root@VM-12-9-centos bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 2021-04-27T06:23:19.882305Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-04-27T06:23:20.192179Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-04-27T06:23:20.273220Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-04-27T06:23:20.343826Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0fa9325e-a721-11eb-a87c-5254009d3ad8. 2021-04-27T06:23:20.348927Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-04-27T06:23:21.462427Z 0 [Warning] CA certificate ca.pem is self signed. 2021-04-27T06:23:21.570135Z 1 [Note] A temporary password is generated for root@localhost: qitk>aF<%5yO 编写配置文件my.cnf,并添加配置 vim /etc/my.cnf # 插入以下配置 [mysqld] datadir=/usr/local/mysql/data port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES symbolic-links=0 max_connections=400 innodb_file_per_table=1 lower_case_table_names=1 启动mysqld /usr/local/mysql/support-files/mysql.server start 使用systemd进行管理 vim /lib/systemd/system/mysql.service # 添加以下配置 [Unit] Description=MySQL Server Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Service] User=mysql Group=mysql # mysql pid文件记录的是当前mysqld进程的pid # 通过Mysqld_safe启动mysql时,mysqld_safe会检查pid文件,未指定PID文件时,pid文件默认名为$DATADIR/`hostname`.pid PIDFile=/usr/local/mysql/data/VM-12-9-centos.pid ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf Restart=on-failure RestartPreventExitStatus=1 TimeoutSec=0 PrivateTmp=false [Install] WantedBy=multi-user.target 使用systemd管理mysql命令 systemctl start mysql.service #启动mysql服务 systemctl stop mysql.service #停止mysql服务 sysemctl restart mysql.service #重新启动服务 systemctl status mysql.service #查看服务当前状态 systemctl enable mysql.service #设置开机自启动 systemctl disable mysql.service #停止开机自启动 添加客户端软链接 ln -s /usr/local/mysql/bin/mysql /usr/bin/ 客户端登录并修改密码 # 密码为之前初始化mysql时保存的临时密码 mysql -u root -p # 修改密码 set password for root@localhost = password('新密码');

参考文章:

https://www.cnblogs.com/wpnr/...
https://blog.csdn.net/supaher...
https://www.cnblogs.com/justf...

安装postgresql

因为不能使用CentOs的 root账号 启动PostgreSql。所以在这里,我先创建一个专门的用于用以操作PostgreSql useradd postgresql 安装依赖。如果你的服务器已安装过gcc相关内容,这步可忽略 yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake gcc* readline-devel 解压安装 # 解压postgreSql tar -vxf postgresql-13.2.tar.gz # 创建PostgreSql的安装目录以及数据目录 mkdir -p /usr/local/postgresql/data chown -R postgresql:postgresql /usr/local/postgresql # 进入解压目录 cd postgresql-13.2/ # 执行configure ./configure --prefix=/usr/local/postgresql --with-python --with-libxml --with-libxslt # make并安装 make & make install 初始化数据库 # 切换到之前创建的用户 su postgresql # 初始化数据库 /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data -E UTF8 # 修改配置文件 vim /usr/local/postgresql/data/postgresql.conf # 修改允许访问的ip地址 listen_addresses='*' # 修改网桥配置信息 vim /usr/local/postgresql/data/pg_hba.conf # 修改IPV4 local connections # 其中192.168.0.0/16 代表192.168.1.1到192.168.255.255都可以访问 host all all 192.168.0.0/16 md5 配置环境变量 # 先切回root用户 su root # 添加环境变量 vim /etc/profile # 追加 # postgresql export PATH=$PATH:/usr/local/postgresql/bin export PGHOME=/usr/local/postgresql export PGDATA=/usr/local/postgresql/data/ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/ # 重新加载配置文件 source /etc/profile 启动,停止postgresql # 切回postgresql用户 su postgresql # 启动服务 pg_ctl start -D $PGDATA -l /usr/local/postgresql/server.log # 进入默认数据库 psql postgres # 创建有密码的用户 CREATE USER postgres WITH PASSWORD '123456'; # 停止服务 pg_ctl stop -D $PGDATA # 查看服务状态 pg_ctl status -D $PGDATA # 重启服务 pg_ctl reload -D $PGDATA 使用systemd管理postgresql # 切到root用户 su root # 添加配置文件 vim /lib/systemd/system/postgresql.service [Unit] Description=PostgreSQL database server After=network.target After=syslog.target [Service] Type=forking User=postgresql Environment=PGDATA=/usr/local/postgresql/data ExecStart=/usr/local/postgresql/bin/pg_ctl start -D ${PGDATA} -s -w ExecStop=/usr/local/postgresql/bin/pg_ctl stop -D ${PGDATA} -s -m fast ExecReload=/usr/local/postgresql/bin/pg_ctl reload -D ${PGDATA} -s TimeoutSec=300 [Install] WantedBy=multi-user.target 在postgresql用户使用systemd命令 systemctl start postgresql.service #启动postgresql服务 systemctl stop postgresql.service #停止postgresql服务 sysemctl restart postgresql.service #重新启动服务 systemctl status postgresql.service #查看服务当前状态 systemctl enable postgresql.service #设置开机自启动 systemctl disable postgresql.service #停止开机自启动

参考文章:

https://blog.csdn.net/qq_2663...
https://blog.csdn.net/darkdra...
https://www.postgresql.org/do...