我是靠谱客的博主 超级镜子,这篇文章主要介绍CentOS8 服务器环境配置安装前的准备Python 安装Nginx 安装Node 安装MySQL 安装搭建 gitlab,现在分享给大家,希望可以做个参考。

CentOS8 服务器环境配置

  • 安装前的准备
    • 使用 yum 安装必备依赖
    • 准备好需要的安装包
  • Python 安装
    • 解压 Python-3.9.0.tgz
    • 编译安装
    • 建立软连接
    • 测试
  • Nginx 安装
    • 创建 nginx 用户
    • 解压 nginx-1.18.0.tar.gz
    • 编译安装
    • 创建 nginx.service
    • 开启端口
    • 启动 nginx 并设置开机启动
  • Node 安装
    • 解压 node-v12.19.0.tar.gz
    • 编译安装
    • 测试
    • 安装 Angular
  • MySQL 安装
    • 安装 rpcsvc
      • 解压 rpcsvc-proto-1.4.2.tar.xz
      • 编译安装
    • 解压 boost_1_73_0.tar.gz
    • 创建 mysql 用户及相关目录
    • 安装 MySQL
      • 解压 mysql-boost-8.0.22.tar.gz
      • cmake
      • 编译安装
    • 初始化 MySQL
    • 创建配置文件
    • 其他操作
  • 搭建 gitlab
    • 安装依赖
    • 开启 SSH 并设置开机启动
    • 开放系统防火墙的 HTTP 和 HTTPS 访问
    • 配置 Postfix 邮件服务并设置开机启动
    • 添加 GitLab 软件包存储库
    • 安装 GitLab 软件包
    • 自定义访问端口
    • 安装 GitLab CI

安装前的准备

使用 yum 安装必备依赖

复制代码
1
2
3
yum -y groupinstall "Development Tools" yum -y install wget gcc gcc-c++ make cmake automake python2 bzip2-devel expat-devel gdbm-devel ncurses ncurses-devel openssl openssl-devel readline-devel sqlite-devel tk-devel xz-devel zlib-devel libffi-devel pcre pcre-devel libaio-devel libtirpc-devel

准备好需要的安装包

软件名称官方网站下载地址文件名称
Python 3.9.0Python 官网下载链接Python-3.9.0.tgz
Nginx 1.18.0Nginx 官网下载链接nginx-1.18.0.tar.gz
Node 12.19.0Node 官网下载链接node-v12.19.0.tar.gz
MySQL 8.0.22MySQL 官网下载链接mysql-boost-8.0.22.tar.gz
boost 1.73.0boost 官网下载页面boost_1_73_0.tar.gz
rpcsvc 1.4.2网址下载链接rpcsvc-proto-1.4.2.tar.xz

Python 安装

解压 Python-3.9.0.tgz

复制代码
1
2
3
tar -zxf Python-3.9.0.tgz cd Python-3.9.0

编译安装

复制代码
1
2
3
4
./configure --enable-optimizations make make install

建立软连接

安装完成后,/usr/local/bin 中自带 python3 -> python3.9 的软连接,也可以建立自己的软连接

复制代码
1
2
3
ln -s /usr/local/bin/python3.9 /usr/local/bin/python39 ln -s /usr/local/bin/pip3.9 /usr/local/bin/pip39

测试

复制代码
1
2
3
4
5
6
7
8
[root@localhost ~]# python3 Python 3.9.0 (default, Oct 20 2020, 14:28:34) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello World") Hello World >>> exit()

Nginx 安装

创建 nginx 用户

  • -g: 指定所属的 group
  • -s: 指定 shell,因为它不需要登录,所以用 /sbin/nologin
  • -M: 不创建 home 目录,因为它不需要登录
复制代码
1
2
3
groupadd nginx useradd -g nginx -s /sbin/nologin -M nginx

解压 nginx-1.18.0.tar.gz

复制代码
1
2
3
tar -zxf nginx-1.18.0.tar.gz cd nginx-1.18.0

编译安装

  • –prefix 指定安装路径
  • –user 指定运行 nginx 的用户
  • –group 指定运行 nginx 的组
  • –with-http_stub_status_module 允许查看 nginx 状态的模块
  • –with-http_ssl_module 支持 https 的模块
复制代码
1
2
3
4
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module make make install

创建 nginx.service

复制代码
1
2
vi /usr/lib/systemd/system/nginx.service

文件内容

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit] Description=nginx-The High-performance HTTP Server After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target

重新加载服务文件

复制代码
1
2
systemctl daemon-reload

开启端口

复制代码
1
2
3
4
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload

启动 nginx 并设置开机启动

复制代码
1
2
3
systemctl enable nginx systemctl start nginx

在 nginx.conf 中 http 里添加 include ./sites-enabled/*; (如果存在则不需要添加)

创建文件夹 sites-enabled

复制代码
1
2
3
vi /usr/local/nginx/conf/nginx.conf mkdir -p /usr/local/nginx/conf/sites-enabled

nginx 站点配置,每个站点在目录 /usr/local/nginx/conf/sites-enabled 创建文件,内容如下

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server { listen 80; server_name www.xxx.com; location / { root /xxx/xxx/xxx/; index index.html index.htm; # try_files $uri $uri/ /index.html; } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
# listen 监听的端口 # server_name 域名 # root 站点根目录 # index 默认访问的文件 # try_files 用于替代 rewrite, Angular 中子路由的使用需要该项

Node 安装

解压 node-v12.19.0.tar.gz

复制代码
1
2
3
tar -zxf node-v12.19.0.tar.gz cd node-v12.19.0

编译安装

复制代码
1
2
3
4
./configure make make install

测试

复制代码
1
2
3
[root@localhost ~]# node -v v12.19.0

安装 Angular

复制代码
1
2
3
4
5
6
7
8
9
10
11
npm install -g @angular/cli ## 编译 Angular npm install npm prune ng build ## 编译后的文件在 dist 文件夹 ## Angular 运行 ng serve ## 安装 cnpm npm install -g cnpm --registry=https://registry.npm.taobao.org

MySQL 安装

MySQL 安装需要准备三个安装包

  • mysql-boost-8.0.22.tar.gz
  • boost_1_73_0.tar.gz
  • rpcsvc-proto-1.4.2.tar.xz

安装 rpcsvc

解压 rpcsvc-proto-1.4.2.tar.xz

复制代码
1
2
3
tar -xf rpcsvc-proto-1.4.2.tar.xz cd rpcsvc-proto-1.4.2

编译安装

复制代码
1
2
3
4
./configure make make install

解压 boost_1_73_0.tar.gz

只需要把 boost_1_73_0.tar.gz 解压到 /usr/local/boost 即可

复制代码
1
2
3
mkdir -p /usr/local/boost tar -xf boost_1_73_0.tar.gz -C /usr/local/boost

创建 mysql 用户及相关目录

复制代码
1
2
3
4
5
6
7
8
9
groupadd mysql useradd -g mysql -s /sbin/nologin -M mysql mkdir -p /usr/local/mysql mkdir -p /data/mysql chown -R mysql:mysql /usr/local/mysql/ chown -R mysql:mysql /data/mysql/ chmod -R 755 /data/mysql/ chmod -R 755 /usr/local/mysql/

安装 MySQL

解压 mysql-boost-8.0.22.tar.gz

复制代码
1
2
3
tar -zxf mysql-boost-8.0.22.tar.gz cd mysql-8.0.22

cmake

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=1 -DFORCE_INSOURCE_BUILD=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DWITH_BOOST=/usr/local/boost

编译安装

复制代码
1
2
3
4
# make -j4 make make install

初始化 MySQL

复制代码
1
2
3
cd /usr/local/mysql/bin ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --character-set-server=utf8

创建配置文件

复制代码
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
vi /usr/local/mysql/my.cnf ### 文件内容如下 ### [client] port=3306 socket=/tmp/mysql.sock default-character-set=utf8 #user=root #password=onlyCHINA123 [mysqld] server-id=1 #skip-grant-tables # 取消注释改行可以无密码登录 port=3306 user=mysql max_connections=200 socket=/tmp/mysql.sock basedir=/usr/local/mysql datadir=/data/mysql pid-file=/data/mysql/mysql.pid init-connect='SET NAMES utf8' character-set-server=utf8 default-storage-engine=INNODB log_error=/data/mysql/mysql-error.log slow_query_log_file=/data/mysql/mysql-slow.log [mysqldump] quick max_allowed_packet=16M

其他操作

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 创建 mysql 软连接 ln -s /usr/local/mysql/bin/mysql /usr/bin # 添加到 /etc 目录的软连接 ln -s /usr/local/mysql/my.cnf /etc/my.cnf # 把 Mysql 加入系统启动 cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld # 增加执行权限 chmod 755 /etc/init.d/mysqld # 修改 mysqld basedir=/usr/local/mysql datadir=/data/mysql # 加入开机启动 systemctl enable mysqld # 启动 mysql service mysqld start # 登录 mysql -u root -p # 修改root密码 flush privileges; alter user 'root'@'localhost' identified by "123456";

搭建 gitlab

安装依赖

复制代码
1
2
3
yum -y groupinstall "Development Tools" yum -y install policycoreutils openssh-server postfix

开启 SSH 并设置开机启动

复制代码
1
2
3
systemctl enable sshd systemctl start sshd

开放系统防火墙的 HTTP 和 HTTPS 访问

复制代码
1
2
3
4
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https systemctl reload firewalld

配置 Postfix 邮件服务并设置开机启动

复制代码
1
2
3
systemctl enable postfix systemctl start postfix

添加 GitLab 软件包存储库

复制代码
1
2
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash

安装 GitLab 软件包

复制代码
1
2
3
4
# 配置访问地址并安装 # EXTERNAL_URL="http://gitlab.example.com" yum -y install gitlab-ce yum -y install gitlab-ce

自定义访问端口

复制代码
1
2
3
4
5
6
7
8
9
vi /etc/gitlab/gitlab.rb ### 需要修改内容如下 ### external_url 'http://0.0.0.0:8008' ### 修改 gitlab.rb 文件后都需要重新配置服务 ### gitlab-ctl reconfigure # 开放响应端口端口 firewall-cmd --zone=public --add-port=8008/tcp --permanent firewall-cmd --reload
复制代码
1
2
3
# 查看默认 root 密码(该文件会在24小时内删除,请修改密码) cat /etc/gitlab/initial_root_password

安装 GitLab CI

管理中心 - 概览 - Runner 页面,点击 安装GitLab Runner,会进入安装文档页面,安装方法和安装 GitLab 大同小异

复制代码
1
2
3
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash yum -y install gitlab-runner

安装完成后注册

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
gitlab-runner register # url 和 token 在之前的管理中心 Runner 页面 [root@localhost src]# gitlab-runner register Runtime platform arch=amd64 os=linux pid=138622 revision=ece86343 version=13.5.0 Running in system-mode. Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://gitlab.hyperv.com:8008/ Please enter the gitlab-ci token for this runner: oLoCX4NFv2W92L_BxEAe Please enter the gitlab-ci description for this runner: [localhost]: Please enter the gitlab-ci tags for this runner (comma separated): Registering runner... succeeded runner=oLoCX4NF Please enter the executor: custom, docker-ssh, parallels, shell, ssh, kubernetes, docker, virtualbox, docker+machine, docker-ssh+machine: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

最后

以上就是超级镜子最近收集整理的关于CentOS8 服务器环境配置安装前的准备Python 安装Nginx 安装Node 安装MySQL 安装搭建 gitlab的全部内容,更多相关CentOS8内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部