scarcoco / projx

5 stars 0 forks source link

Centos 环境搭建 #8

Open scarcoco opened 4 years ago

scarcoco commented 4 years ago

System

$ uname -a

Linux iZuf68um4r4f2fvrvh133aZ 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

MariaDB

$ yum install mariadb mariadb-server

$ systemctl start mariadb

# auto start
$ systemctl enable mariadb 

$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

NodeJS

nvm

$ curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash
$ source ~/.bash_profile
$ nvm list-remote
$ nvm install v13.1.0

Python

$ which python
/usr/bin/python

$ python --version
Python 2.7.5

Golang

Install

Reference: https://golang.org/doc/install?download=go1.13.4.linux-amd64.tar.gz

$ wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz

Add /usr/local/go/bin to the PATH environment variable

$ export PATH=$PATH:/usr/local/go/bin

$ go version
o version go1.13.4 linux/amd64

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build740480601=/tmp/go-build -gno-record-gcc-switches"

test

$ mkdir -p ~/go && cd ~/go
$ mkdir -p src/hello
$ touch main.go

main.go 的代码如下:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}
$ cd ~/go/src/hello
$ go build
$ ./hello
hello, world

$ go run main.go
hello, world

go module

开启 go module之后,项目目录不要求一定要在 $GOPATH 目录下,任意目录下执行 go mod init 即可。

$ export GO111MODULE=auto

# 建议设置,否则后续很多包下载不下来
$ export GOPROXY=https://goproxy.io

$ mkdir ~/gomod & cd ~/gomod

# main 是 go.mod 中 module 名字,建议和目录一致
$ go mod init main

$ cat go.mod
module main

go 1.13

main.go 的代码如下:

package main

import (
    "net/http"

    "github.com/labstack/echo"
)

func main() {
    e := echo.New()
    e.GET("/", func(c echo.Context) error {
        return c.String(http.StatusOK, "Hello, World!")
    })
    e.Logger.Fatal(e.Start(":1323"))
}
$ go run main.go

Nginx

参考:http://nginx.org/en/docs/install.html

which nginx
nginx -v
nginx -V
kaelli commented 4 years ago

新建数据库账户没有远程访问权限

kaelli commented 4 years ago

新建数据库账户没有远程访问权限

scarcoco commented 4 years ago

MariaDB 远程无法访问解决方案

查看 MariaDB 绑定的地址和端口

$ netstat -apn | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      32702/mysqld
unix  2      [ ACC ]     STREAM     LISTENING     822460   32702/mysqld         /var/lib/mysql/mysql.sock

MariaDB 配置文件路径 /etc/my.cnf/etc/my.conf.d/ 目录下,如果有 bind-address = 127.0.0.1 配置,那么上面的地址则为 127.0.0.1:3306

MariaDB 状态

# 开机启动
systemctl enable mariadb
# 状态
systemctl status mariadb

mysql 数据库账号设置

$ mysql -uroot -p

> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

> FLUSH PRIVILEGES;

> SELECT host, user FROM user

防火墙状态

$ firewall-cmd --query-port=3306/tcp
$ firewall-cmd --permanent --add-port=3306/tcp
$ firewall-cmd --reload

阿里云服务器

看一下后台配置端口是否开放端口,具体参考:https://help.aliyun.com/document_detail/25471.html

参考:

  1. https://zhuanlan.zhihu.com/p/49046496
  2. https://zoco.me/post/centos7-mariadb-remote-access
kaelli commented 4 years ago

阿里云安全组配置端口

scarcoco commented 4 years ago

Nginx 安装

之前通过 yum 安装,现在想新增 nginx-rtmp-module 模块,需要源码安装。

yum -y remove nginx
./configure \
    --with-pcre=/root/download/pcre-8.44 \
    --with-openssl=/root/download/openssl-1.1.1d \
    --with-zlib=/root/download/zlib-1.2.11 \
    --with-http_ssl_module \
    --with-http_v2_module \
    --add-module=/root/download/nginx-rtmp-module

adding module in /root/download/nginx-rtmp-module
 + ngx_rtmp_module was configured
creating objs/Makefile

Configuration summary
  + using PCRE library: /root/download/pcre-8.44
  + using OpenSSL library: /root/download/openssl-1.1.1d
  + using zlib library: /root/download/zlib-1.2.11

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
make

出现错误:

configure: error: Invalid C++ compiler or C++ compiler flags
make[1]: *** [/root/download/pcre-8.44/Makefile] 错误 1

解决方法:

yum install -y gcc gcc-c++

防火墙打开

$ firewall-cmd --query-port=80/tcp
$ firewall-cmd --permanent --add-port=80/tcp
$ firewall-cmd --reload
scarcoco commented 4 years ago

ffmpeg

su -c 'yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm'

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

yum -y install ffmpeg ffmpeg-devel
ffmpeg -version