各种常用服务快速安装

服务器初始化

# 主机名
hostname='master.server'

# 初始化
hostnamectl set-hostname $hostname
systemctl stop firewalld.service && systemctl disable firewalld.service
systemctl stop NetworkManager && systemctl disable NetworkManager
setenforce 0 && sed -i 's/enforcing/disabled/g' /etc/selinux/config

# YUM 源
mv /etc/yum.repos.d/CentOS-* /tmp/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache

# 安装基本工具
yum install -y vim wget lsof net-tools ntp bash-completion
source /usr/share/bash-completion/bash_completion

# 配置时间同步
cat > /etc/ntp.conf << EOF
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOF
systemctl stop chronyd && systemctl disable chronyd
systemctl start ntpd && systemctl enable ntpd
ntpdate -u 0.cn.pool.ntp.org
hwclock --systohc
echo '0 * * * * /usr/sbin/ntpdate -u 0.cn.pool.ntp.org >> /tmp/autontpdate 2>&1'  >> /var/spool/cron/root


# 打开文件数
cat >> /etc/security/limits.conf <<EOF
* soft nofile 102400
* hard nofile 204800
EOF

# 最大进程数
cat > /etc/security/limits.d/20-nproc.conf <<EOF
* soft nproc 102400
* hard nproc 204800
EOF

# 内核优化
cat >> /etc/sysctl.conf << EOF
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_tw_recycle = 1
vm.max_map_count = 655360
EOF
sysctl -p

# 历史命令显示操作时间、命令行历史数
if ! grep "HISTTIMEFORMAT" /etc/profile &>/dev/null; then
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
echo "export HISTSIZE=500" >>/etc/profile
echo "export HISTFILESIZE=500" >> /etc/profile
fi
source  /etc/profile

快速安装docker

yum install -y yum-utils device-mapper-persistent-data lvm2 vim \
&& yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo \
&& yum makecache fast \
&& yum -y install docker-ce \
&& mkdir -p  /etc/docker/ \
&& echo -e '{\n  "data-root":"/home/docker",\n  "registry-mirrors": ["https://1e7waog4.mirror.aliyuncs.com"]\n}' > /etc/docker/daemon.json \
&& systemctl daemon-reload && systemctl start docker && systemctl enable docker \
&& yum install -y bash-completion \
&& source /usr/share/bash-completion/bash_completion \
&& source /usr/share/bash-completion/completions/docker

docker compose

curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose \
&& ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose \
&& docker-compose --version

1、配置阿里yum源

mv /etc/yum.repos.d/CentOS-* /tmp/ \
&& curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \
&& curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum makecache && yum clean all 

2、设置中文字符

安装中文字符

yum install -y kde-l10n-Chinese glibc-common 

设置环境变量

(
cat <<EOF
export LC_ALL=zh_CN.utf8
export LANG=zh_CN.utf8
export LANGUAGE=zh_CN.utf8
EOF
) >> ~/.bashrc \
&& localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 \
&& source ~/.bashrc \
&& echo $LANG

3、安装MySQL

获取安装包

yum install -y wget \
&& wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar 

安装MySQL

tar -xvf mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar \
&& yum install -y numactl libaio net-tools perl \
&& rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm \
&& yum clean all && rm -rf mysql* \
&& rpm -qa|grep mysql 

配置文件

vi /etc/my.cnf
[mysqld]
# 默认连接端口
port = 3306
# 用于本地连接的socket套接字
socket = /var/lib/mysql/mysql.sock
# pid文件所在目录
pid-file = /var/run/mysqld/mysqld.pid
# 数据文件存放的目录
datadir = /var/lib/mysql
# MySQL存放临时文件的目录
tmpdir = /tmp
# 错误日志配置文件
log-error = /var/log/mysqld.log
# 服务端默认编码(数据库级别)
character_set_server = utf8
# 服务端默认的比对规则,排序规则
collation_server = utf8_general_ci
# 性能优化的引擎,默认关闭
performance_schema = 0
# 是否支持符号链接,即数据库或表可以存储在my.cnf中指定datadir之外的分区或目录,为0不开启
symbolic-links = 0
# 禁用DNS主机名查找,启用以后用内网地址向mysqlslap请求响应快了一半
skip_name_resolve = 1
# 最大可连接数
max_connections = 800
# 某台host连接错误次数,超过该次数则被屏蔽
max_connect_errors = 1000
# 数据库事务隔离级别
transaction_isolation = READ-COMMITTED
# join优化内存
join_buffer_size = 128M
# 内部内存临时表的最大值
tmp_table_size = 64M
# 最大接受的数据包大小
max_allowed_packet = 64M
# 服务器关闭交互式连接前等待活动的秒数
interactive_timeout = 1200
# 服务器关闭非交互连接之前等待活动的秒数
wait_timeout = 600
# 读入缓冲区的大小
read_buffer_size = 16M
# 随机读缓冲区大小
read_rnd_buffer_size = 8M
# 在每个connection第一次需要使用这个buffer的时候,一次性分配设置的内存
sort_buffer_size = 8M
# 定义了你MySQL应该支持的sql语法,对数据的校验等等,限制一些所谓的‘不合法’的操作
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 值定义了日志文件的大小
innodb_log_file_size=256M

启动,获取密码

systemctl start mysqld \
&& systemctl enable mysqld \
&& grep password /var/log/mysqld.log | sed 's/.*\(............\)$/\1/'

授权

set password for root@localhost = password('123456Aa.');
grant all privileges on *.* to 'root'@'%' identified by '123456Aa.';
flush privileges;

4、安装LAMP环境

安装apache

yum install -y httpd httpd-devel \
&& systemctl start httpd \
&& systemctl enable httpd \
&& systemctl status httpd 

安装mariadb

yum install -y mariadb mariadb-server mariadb-libs mariadb-devel \
&& systemctl start mariadb \
&& systemctl enable mariadb \
&& systemctl status mariadb

初始化mariadb

mysql_secure_installation

安装php

yum install -y php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath \
&& systemctl restart httpd

测试文件

echo -e '<?php \n phpinfo(); \n?>' > /var/www/html/info.php

5、安装Node.js环境

yum install -y wget \
&& wget https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz \
&& tar -xvf node-v10.16.3-linux-x64.tar.xz \
&& mv node-v10.16.3-linux-x64 node 
&& mv node /opt
# 配置环境变量
vim ~/.bashrc
export NODE_HOME=/opt/node
export PATH=$NODE_HOME/bin:$PATH
# 刷新生效
source ~/.bashrc

6、nginx

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm \
&& yum install -y nginx \
&& systemctl start nginx.service \
&& systemctl enable nginx.service

6.5 nginx配置文件语法高亮

wget http://www.vim.org/scripts/download_script.php?src_id=14376 -O nginx.vim
cp nginx.vim /usr/share/vim/vim74/syntax
echo 'au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif ' >> /usr/share/vim/vim74/filetypr.vim

7、redis

yum install -y epel-release \
&& yum install -y redis \
&& systemctl start redis \
&& systemctl enable redis

编译安装

yum install -y wget gcc \
&& wget https://download.redis.io/releases/redis-5.0.14.tar.gz \
&& tar -zxvf redis-5.0.14.tar.gz \
&& cd redis-5.0.14 \
&& make PREFIX=/opt/redis install \
&& cp redis.conf /opt/redis \
&& echo 'PATH=$PATH:/opt/redis/bin' >> ~/.bashrc \
&& source ~/.bashrc 

修改 /etc/redis.conf (非必须)

将bind 127.0.0.1 改成 bind 0.0.0.0
protected-mode yes 改成 no

system脚本

vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
PIDFile=/opt/redis/redis.pid
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
LimitNOFILE=655360
PrivateTmp=true
Type=notify
User=root
Group=root

[Install]
WantedBy=multi-user.target

8、编译安装 php5.6

参考链接:https://www.cnblogs.com/mike666/p/13958284.html

安装目录:/data/php_9000

安装基本工具

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel -y

下载安装包

wget https://www.php.net/distributions/php-5.6.40.tar.gz

编译安装

./configure --prefix=/data/php_9000 --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-fpm-group=www --with-fpm-user=www --enable-pcntl --with-mysql
make && make install

php.ini 配置文件

cp php.ini-production /etc/php.ini
# 修改配置项
post_max_size = 64M
upload_max_filesize = 64M
date.timezone = PRC
cgi.fix_pathinfo=1
max_execution_time = 300

php-fpm 配置文件

cd /data/php_9000/etc/
cp php-fpm.conf.default php-fpm.conf
# 修改配置项
user=www
group=www
# 追加以下内容,PHP进程数的设置
pm.max_children = 100
pm.start_servers = 30
pm.min_spare_servers = 20
pm.max_spare_servers = 100
pm.max_requests = 500

启动文件

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

9、JDK环境配置

export JAVA_HOME=/root/jdk1.8		#jdk文件目录
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值